从命令行使用 nntool [MATLAB] [英] Using nntool [MATLAB] from command line

查看:25
本文介绍了从命令行使用 nntool [MATLAB]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码:

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

现在我想

  • 访问生成的误差变量(以便我可以计算平均误差等)
  • 在循环中运行它,所以我想在循环之间重新初始化权重.
  • 访问存储时间运行所需的变量
  • 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?

[我知道如何使用 nntool GUI 完成这些事情]

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

推荐答案

示例:

% 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')

注意:在 R2010b 中,newfit 函数被弃用,取而代之的是 fitnet,使用以下代码创建网络:

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

这篇关于从命令行使用 nntool [MATLAB]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆