MATLAB神经网络模式识别

myd*_*dew 3 matlab neural-network

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

W1=net.IW{1,1};
W2=net.LW{2,1};
b1=net.b{1,1};
b2=net.b{2,1};
Run Code Online (Sandbox Code Playgroud)

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

[edit]下面是生成的代码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)
Run Code Online (Sandbox Code Playgroud)

Ita*_*atz 5

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

您可以在此处了解更多信息:http : //www.mathworks.com/help/toolbox/nnet/rn/f0-81221.html#f0-81692