【问题标题】:Using nntool [MATLAB] from command line从命令行使用 nntool [MATLAB]
【发布时间】:2010-12-13 00:13:22
【问题描述】:

我有这个代码:

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

现在我想

  • 访问生成的误差变量(这样我就可以计算平均误差等)
  • 在循环中运行它,所以我想在循环之间重新初始化权重
  • 访问存储运行时间的变量

如何从命令行完成这三件事?

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

【问题讨论】:

    标签: matlab command-line neural-network nntool


    【解决方案1】:

    例子:

    % 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,请改用以下代码来创建网络:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-07
      • 1970-01-01
      • 2011-10-03
      • 2010-12-12
      • 1970-01-01
      相关资源
      最近更新 更多