【问题标题】:Matlab neural network toolbox save regression plot to fileMatlab 神经网络工具箱将回归图保存到文件
【发布时间】:2015-01-10 04:06:22
【问题描述】:

我正在尝试通过我学校的多核计算服务器上的 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

我猜我会将它添加到文件的末尾,但我很确定这是不对的。如果有人可以帮助我,将不胜感激!

【问题讨论】:

    标签: matlab neural-network


    【解决方案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 的更多信息,请参阅here

    【讨论】:

    • 谢谢!像魅力一样工作
    猜你喜欢
    • 2011-07-08
    • 1970-01-01
    • 2015-06-03
    • 2013-04-10
    • 2013-01-13
    • 2013-09-07
    • 2014-01-02
    • 2021-09-13
    • 2014-04-20
    相关资源
    最近更新 更多