views:

701

answers:

1

I have this code:

in = [5 columns of data-points];
out = [1 column of data-points];
net = newfit(in,out,5);
net = train(net,in,out);

now I want to

  • access the error variable that is generated (so that I can calculate the mean error etc.)
  • run this in a loop, so I want to re-initialize weights between loops.
  • access the variable that stores the time it took to run

How can these three things be done from command line?

[I know how these things can be done with nntool GUI]

+2  A: 
% data
in = rand(100,5)';
out = rand(100,1)';

net = newfit(in,out,5);                 % create ANN
net.trainParam.showWindow = 0;          % dont show window

rmse = [];
t = [];
for i=1:10
    net = init(net);                     % initialize network weights

    tic
    net = train(net,in,out);             % train
    predicted = sim(net, in);            % test
    t(i) = toc;

    r = (out-predicted);                 % residuals
    rmse(i) = sqrt(sum(r.^2)/length(r)); % root mean square error
end
bar([t; rmse]', 'grouped'), xlabel('Runs')
legend({'Elapsed Time' 'RMSE'}, 'orientation','horizontal')

screenshot

Amro
thanks a lot @Amro. This really helped, a lot. Thanks again.
Lazer