[NEURAL NETWORK] How can I make MSE be the same in different trying times ?

8 views (last 30 days)
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 ?

Accepted Answer

Greg Heath
Greg Heath on 2 Dec 2014
Edited: Greg Heath on 2 Dec 2014
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
  3 Comments
Greg Heath
Greg Heath on 2 Dec 2014
Obviously, you did not follow my advice to see what goodies tumble out of
tr = tr
Son Nguyen
Son Nguyen on 3 Dec 2014
I apologize that I missed it, I got it already.
I still has one more question. Is there anyway to take out the initial weights of training ? I'm going to compare my algorithm with LM and BFGS. In order to do that, I have to make they have the same initial weights.
If you feel not comfortable to answer my question here, please let me know, I will make a new question for it.
Appreciate very much for your help.

Sign in to comment.

More Answers (1)

Greg Heath
Greg Heath on 2 Dec 2014
Remove the underscores at the beginning and end.
Use net.divideFcn = 'dividetrain' to automatically get the (1/0/0) data division
I hope you don't use 10 epochs for serious work
net2 in never defined
MSE depends on net, not net2
sumsq yields SSE, not MSE
For repeatability you have to set the initial state of the random number generator before data divisions and weight initializations.
MSE is scale dependent. Better to normalize by the average target variance
Hope this helps.
Thank you for formerly accepting my answer
Greg

Categories

Find more on Sequence and Numeric Feature Data Workflows 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!