我试图通过我学校的多核计算服务器上的ssh连接运行一个matlab脚本(由nftool生成,因为我的matlab知识最好)和一个相当大的数据集。由于我无法直接查看培训网络时产生的图形界面,我想将图表保存到文件中(我认为我最想要的是回归因此我可以在工作结束后查看它。我只编辑了代码以自动导入数据文件
% Solve an Input-Output Fitting problem with a Neural Network
% Script generated by NFTOOL
% Created Tue Nov 11 21:20:40 CST 2014
%
% This script assumes these variables are defined:
%
% NNinput - input data.
% NNoutput - target data.
% sets the same seed every time, so the rand() sequence is always identical
RandStream.setGlobalStream(RandStream('mt19937ar','seed',1));
close all % closes all of the figures that you have generated in your program
clear all % deletes all stored variables in your workspace
clc % removes all lines in your command window
NNinput = load('NNinput');
NNoutput = load('NNoutput');
inputs = NNinput;
targets = NNoutput;
inputs = inputs.';
targets = targets.';
% Create a Fitting Network
hiddenLayerSize = 10;
net = fitnet(hiddenLayerSize);
% Choose Input and Output Pre/Post-Processing Functions
% For a list of all processing functions type: help nnprocess
net.inputs{1}.processFcns = {'removeconstantrows','mapminmax'};
net.outputs{2}.processFcns = {'removeconstantrows','mapminmax'};
% Setup Division of Data for Training, Validation, Testing
% For a list of all data division functions type: help nndivide
net.divideFcn = 'dividerand'; % Divide data randomly
net.divideMode = 'sample'; % Divide up every sample
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
% For help on training function 'trainlm' type: help trainlm
% For a list of all training functions type: help nntrain
net.trainFcn = 'trainlm'; % Levenberg-Marquardt
% Choose a Performance Function
% For a list of all performance functions type: help nnperformance
net.performFcn = 'mse'; % Mean squared error
% Choose Plot Functions
% For a list of all plot functions type: help nnplot
net.plotFcns = {'plotperform','plottrainstate','ploterrhist', ...
'plotregression', 'plotfit'};
% Train the Network
[net,tr] = train(net,inputs,targets);
% Test the Network
outputs = net(inputs);
errors = gsubtract(targets,outputs);
performance = perform(net,targets,outputs)
% Recalculate Training, Validation and Test Performance
trainTargets = targets .* tr.trainMask{1};
valTargets = targets .* tr.valMask{1};
testTargets = targets .* tr.testMask{1};
trainPerformance = perform(net,trainTargets,outputs)
valPerformance = perform(net,valTargets,outputs)
testPerformance = perform(net,testTargets,outputs)
到目前为止,我能够想到的只有......
h = findobj('Type', plotregression(targets, outputs), TRAINING_PLOTREGRESSION, 'regressionPlot');
for k = 1:numel(h)
print(h(k), sprintf('Pic%d.ps',k));
end;
来自这篇文章how to save matlab neural networks toolbox generated figures
而且我猜我会将其添加到文件的末尾,但我非常确定这是不对的。如果有人可以帮助我,我将不胜感激!
答案 0 :(得分:1)
这可能是保存培训情节的最强<基本方式。您已在代码的这一部分中选择了绘图函数:
% Choose Plot Functions
% For a list of all plot functions type: help nnplot
net.plotFcns = {'plotperform','plottrainstate','ploterrhist', ...
'plotregression', 'plotfit'};
现在您可以在代码末尾(或者在训练网络后的任何地方)调用每个绘图函数,并使用print
保存绘图:
plotperform(tr);
print('-dpsc', 'perform')
plottrainstate(tr);
print('-dpsc', 'trainstate')
ploterrhist(tr);
print('-dpsc', 'errhist')
plotregression(tr);
print('-dpsc', 'regression')
plotfit(tr);
print('-dpsc', 'fit')
print
的第一个参数选择打印机驱动程序,在本例中为PostScript Level 3颜色,第二个是图的名称。有关print
。