MATLAB: [NEURAL NETWORK] How to make MSE be the same in different trying times

mseneural network

The Mean Square Error (MSE) turns out to be different each time I train the network.
_net = feedforwardnet(10,'trainlm');
net.divideParam.trainRatio=1;
net.divideParam.valRatio=0;
net.divideParam.testRatio=0;
net.trainParam.epochs=10;
[net,tr]=train(net2,x,t);
MSE=sumsqr(net2(x)-t)_
I guess it come from net2.initFcn caused this problem. How do I change it to make MSE becomes the same ?

Best Answer

Initialize the state of the random number generator ONCE AND ONLY ONCE before the random data division and random weight initialization.
In the following example, The design is not repeatable if either or both the first two commands in the loop are commented out.
clear all, clc
[ x, t ] = simplefit_dataset;
MSE00 = mean(var(t',1)) % 8.3378 Reference MSE
net = feedforwardnet; % Defaults used
for i = 1:2
rng('default') % Reset RNG state
net = configure(net,x,t); % Weight initialization
[net tr y e] = train(net,x,t); % y = net(x), e=t-y
NMSE = mse(e)/MSE00 % 1.7558e-05
ttrn = t(tr.trainInd);
MSEtrn00 = mean(var(ttrn',1)) % 8.8219
NMSEtrn = tr.best_perf/MSEtrn00 % 1.386e-05
NMSEval = tr.best_vperf/MSEtrn00 % 1.0019e-05
NMSEtst = tr.best_tperf/MSEtrn00 % 3.6061e-05
end
% P.S. Look at the results of the following command
tr = tr % No semicolon
Hope this helps.
Thank you for formally accepting my answer
Greg