Using nntool [MATLAB] from command line

末鹿安然 提交于 2019-12-23 21:26:48

问题


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]


回答1:


Example:

% some random data
in = rand(100,5)';
out = rand(100,1)';

% create a feed-forward back-propagation neural network
% (1 hidden layer with 5 neurons)
net = newfit(in,out,5);
net.trainParam.showWindow = 0;     % dont show GUI

% repeat 10 times
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(mean(r.^2));    % root mean square error
end

% plot errors and elapsed times
bar([t; rmse]', 'grouped'), xlabel('Runs')
legend({'Elapsed Time' 'RMSE'}, 'orientation','horizontal')


NOTE: In R2010b, newfit function was deprecated in favor of fitnet, use the following code instead to create the network:

% old
%net = newfit(in,out,5);

% new
net = fitnet(5);                   % create ANN
net = configure(net, in, out);     % set input/output sizes according to data


来源:https://stackoverflow.com/questions/1673489/using-nntool-matlab-from-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!