Reputation: 119
I am trying to make multiple designs of neural network and from these trials i want the best performing neural network and then retrain my final network with the best performing design. I get the best performance in trial 4. But when i try to retrain the network with these values, iget different outputs. Please help me. My code is:
load inputdata
load targetdata
x=input;
t=target;
hiddenLayerSize = 30;
net = patternnet(hiddenLayerSize);
net.trainFcn='trainbr';
net.trainParam.epochs=100;
rng(0);
Ntrials=20;
for i = 1:Ntrials
s{i} = rng;
net = configure(net,x,t);
[ net tr y e] = train(net,x,t);
% Best mseval over all epochs of ith run
netIW0{i} = net.IW
netb0{i} = net.b
netLW0{i} = net.LW
tstind = tr.testInd;
ytst = y(:,tstind);
ttst = t(:,tstind);
%mseval(i) = mse(net,ttst,ytst)
mseval(i)=tr.best_tperf;
plt=plt+1,figure(plt)
plotconfusion(ttst,ytst)
title([ ' TEST SET CONFUSION MATRIX. TRIAL = ', num2str(i)] )
hold off
end
[ minmseval ibest ] = min(mseval);
rng=s{ibest}; % For repeating the best design
bestnet = configure(net,x,t);
[ bestnet tr y e] = train(net,x,t);
bestIW0 = bestnet.IW
bestb0 = bestnet.b
bestLW0 = bestnet.LW
msetst=tr.best_tperf;
tstind = tr.testInd;
ytst = y(:,tstind);
ttst = t(:,tstind);
fWb=getwb(bestnet);
%msetst= mse(bestnet,ttst,ytst)
plt=plt+1,figure(plt)
plotconfusion(ttst,ytst)
title([ ' OVERALL TEST SET CONFUSION MATRIX= '] )
hold off
save bestnet
view(bestnet)
Upvotes: 0
Views: 740
Reputation: 81
I do not know why You can not reproduce Your best network. But You can work around the problem by saving every of this 20 nets as separate objects and than just recall the best one and delete others. And this will be a faster way because You do not need to train again Your network.
Upvotes: 1