Manually reproduce results from a neural network generated from Matlab
3 views (last 30 days)
Show older comments
I've tried to reproduce the results I got from a trained network but was unable. Here's my script:
load 'C:\Users\ZA\Documents\cosjacorr.mat'
inputs = cosjacorr(:, 1:9)';
targets = cosjacorr(:, 10:13)';
numHiddenNeurons = 2; % Adjust as desired
net = newpr(inputs,targets,numHiddenNeurons);
net.divideParam.trainRatio = 75/100; % Adjust as desired
net.divideParam.valRatio = 15/100; % Adjust as desired
net.divideParam.testRatio = 10/100; % Adjust as desired
net.inputs{1}.processFcns = {};
net.outputs{2}.processFcns = {};
% Train and Apply Network
[net,tr] = train(net,inputs,targets);
outputs = sim(net,inputs);
% Plot
plotconfusion(targets,outputs)
I removed all pre and post processing hoping that I would be able to reproduce the results but was unsuccessful.
Here's what I did in terms of replicating the network's output:
y1 = tansig(net.IW{1} * input + net.b{1});
Results = tansig(net.LW{2} * y1 + net.b{2});
Can someone please help me out? thanks.
PS. I can even send the entire data file to you if it will help.
0 Comments
Accepted Answer
Greg Heath
on 21 Feb 2016
Type "whos" to see the dimensionality of all variables and parameters.
% help newpr
% doc newpr
% Obsoleted in R2010b NNET 7.0. Last used in R2010a
close all, clear all, clc
[x t ] = simpleclass_dataset;
[ I N ] = size(x) % [ 2 1000 ]
[O N ] = size(t) % [ 4 1000]
H = 2
net = newpr(x,t,H);
net = train(net,x,t);
y = net(x);
IW = net.IW{1,1};
b1 = net.b{1};
b2 = net.b{2};
LW = net.LW{2,1};
whos
% IW 2x2 32 double
% LW 4x2 64 double
% b1 2x1 16 double
% b2 4x1 32 double
% t 4x1000 32000 double
% x 2x1000 16000 double
% y 4x1000 32000 double
B1 = repmat( b1, 1, N );
B2 = repmat( b2, 1, N );
[ xn,xsettings] = mapminmax(x);
[ tn,tsettings] = mapminmax(t);
yn = tanh( B2 + LW*tanh( B1 + IW*xn ) );
y1 = mapminmax.reverse( yn,tsettings);
dy = max(max(abs(y1-y)))
Hope this helps
Thank you for formally accepting my answer
Greg
0 Comments
More Answers (0)
See Also
Categories
Find more on Deep Learning Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!