2009-11-04 62 views
3

我有這樣的代碼:使用nntool [MATLAB]從命令行

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

現在我想

  • 訪問時產生(這樣我可以計算平均的誤差變量錯誤等)
  • 運行此循環,所以我想重新初始化循環之間的權重
  • 訪問存儲時間花了運行

怎麼能這三樣東西從命令行完成的變量?

[我知道這些東西可以用nntool GUI來完成]

回答

3

例子:

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

screenshot


注:在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 
+0

非常感謝@Amro。這非常有幫助,很多。再次感謝。 – Lazer 2009-11-04 17:27:13