Why is predicting the output of a trained neural network by using "net/sim" different than manually calculating the output using the network weights, biases and transfer functions?
Show older comments
Why is predicting the output of a trained neural network by using "net/sim" different than manually calculating the output using the network weights, biases and transfer functions?
Refer to the following example:
%% create random data
rng(1);
xdata = rand(5,100);
ydata = rand(1,100);
%% fit a forward network
nlayersize = 10;
net = feedforwardnet(nlayersize);
net.trainParam.showWindow = false;
net = train(net,xdata,ydata);
net.layers{1}.transferFcn
%% calculate the model output at a new point
xNew = rand(5,1);
y1 = net(xNew); % can use sim as well
%% manually calculate model output
IW = net.IW{1};
LW = net.LW{2,1};
b = net.b;
y2 = IW*xNew+b{1};
y2 = tansig(y2);
y2 = LW*y2+b{2};
dy = y1-y2
"dy" is not zero but it should be.
Accepted Answer
More Answers (0)
Categories
Find more on Deep Learning Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!