【问题标题】:MATLAB Neural Network pattern recognitionMATLAB 神经网络模式识别
【发布时间】:2012-05-29 16:52:52
【问题描述】:

我已经为鼠标手势识别制作了简单的神经网络(输入是角度),并且我使用了 nprtool(用于创建的函数 patternnet)。我保存了网络的权重和偏差:

W1=net.IW{1,1};
W2=net.LW{2,1};
b1=net.b{1,1};
b2=net.b{2,1};

为了计算结果,我使用了tansig(W2*(tansig(W1*in+b1))+b2); 其中in 是一个输入。但结果很糟糕(每个数字大约等于 0.99)。推荐 net(in) 的输出很好。我究竟做错了什么 ?为什么第一种方法不好(在我的 C++ 程序中也是如此)对我来说非常重要。我正在寻求帮助:)

[编辑] 下面是nprtool GUI 生成的代码。也许对某人来说这会有所帮助,但我没有从这段代码中看到我的问题的任何解决方案。隐藏层和输出层神经元使用tansig激活函数(MATLAB网络中有参数吗?)。

% Solve a Pattern Recognition Problem with a Neural Network
% Script generated by NPRTOOL
% Created Tue May 22 22:05:57 CEST 2012
%
% This script assumes these variables are defined:
%
%   input - input data.
%   target - target data.    
inputs = input;
targets = target;

% Create a Pattern Recognition Network
hiddenLayerSize = 10;
net = patternnet(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)

% View the Network
view(net)

% Plots
% Uncomment these lines to enable various plots.
%figure, plotperform(tr)
%figure, plottrainstate(tr)
%figure, plotconfusion(targets,outputs)
%figure, ploterrhist(errors)

【问题讨论】:

  • 请包含创建net的代码,我们无法猜测您使用了哪些参数。不必猜测是什么函数创建了它也很好(network?)
  • 我在一分钟前完成了这个。我将非常感谢您的帮助:)

标签: matlab neural-network


【解决方案1】:

从您的代码中可以看出,网络对输入应用自动预处理和对目标进行后处理 - 查找定义 processFcns 的行。这意味着训练后的参数对于预处理的输入是有效的,并且网络的输出是后处理的(具有与目标相同的参数)。因此,在您的tansig(W2*(tansig(W1*in+b1))+b2); 行中,您不能使用原始输入。您必须预处理输入,将结果用作网络的输入,并使用用于后处理目标的相同参数对输出进行后处理。只有这样,您才能得到与调用net(in) 相同的结果。

您可以在此处阅读更多内容:http://www.mathworks.com/help/toolbox/nnet/rn/f0-81221.html#f0-81692

【讨论】:

  • 哦,我现在明白了。非常感谢! :)
猜你喜欢
  • 2012-02-29
  • 2013-11-30
  • 2011-06-02
  • 2012-02-20
  • 1970-01-01
  • 2011-12-12
  • 2018-11-22
  • 2013-07-10
相关资源
最近更新 更多