Reputation: 15
I'm trying to run a matlab script (generated by nftool, as my matlab knowledge is poor at best) with a rather large data set through my ssh connection on my school's multi-core compute server. Since I can't directly look at the graphical interface that's produce while training an the network, I'd like to save the plots to a file (the one I think I want the most is the regression plot) so I can look at it after the job runs. I've only edited the code to automatically import the data files
% 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)
So far, all I've been able to come up with is...
h = findobj('Type', plotregression(targets, outputs), TRAINING_PLOTREGRESSION, 'regressionPlot');
for k = 1:numel(h)
print(h(k), sprintf('Pic%d.ps',k));
end;
from this post how to save matlab neural networks toolbox generated figures
and I'm guessing that I would add this to the end of the file, but I'm pretty sure that that isn't right. If anybody can help me out it would be much appreciated!
Upvotes: 0
Views: 1874
Reputation: 6679
This is likely the most basic way to save the plots about your training. You have chosen your plot functions in this part of your code:
% Choose Plot Functions
% For a list of all plot functions type: help nnplot
net.plotFcns = {'plotperform','plottrainstate','ploterrhist', ...
'plotregression', 'plotfit'};
So now you can simply call each plot function at the end of your code (or anywhere after training the network) and save the plot with 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')
The first argument of print
selects the printer driver, in this case PostScript Level 3 color, and the second is the name of the figure. See here for more information about print
.
Upvotes: 1