简体   繁体   English

MATLAB神经网络模式识别

[英]MATLAB Neural Network pattern recognition

I've made simple neural network for mouse gestures recognition (inputs are angles)and I've used nprtool (function patternnet for creating). 我已经为鼠标手势识别(输入是角度)制作了简单的神经网络,并且我使用了nprtool(用于创建的函数patternnet)。 I saved the weights and biases of the network: 我保存了网络的权重和偏见:

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

and for calculating result I used tansig(W2*(tansig(W1*in+b1))+b2); 为了计算结果,我使用了tansig(W2*(tansig(W1*in+b1))+b2); where in is an input. 其中in是输入。 But the result is awful (each number is approximately equal to 0.99). 但结果很糟糕(每个数字大约等于0.99)。 Output from commend net(in) is good. 来自推荐net(in)输出是好的。 What am I doing wrong ? 我究竟做错了什么 ? It's very important for me why first method is bad (the same I do in my C++ program). 对我来说非常重要的是为什么第一种方法是坏的(和我在C ++程序中做的一样)。 I'm asking for help:) 我在寻求帮助:)

[edit] Below there's generated code from nprtool GUI . [编辑]下面是从nprtool GUI生成的代码。 Maybe for someone it would be helpful but I don't see any solution to my problem from this code. 也许对某人来说这会有所帮助,但我没有从这段代码中看到我的问题的任何解决方案。 For hidden and output layers neurons is used tansig activation function (is there any parameter in MATLAB network ?). 对于隐藏和输出层,神经元使用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)

As can be seen in your code, the network applies automated preprocessing of the input and postprocessing of the targets - look for the lines which define processFcns . 从代码中可以看出,网络对目标的输入和后处理应用自动预处理 - 查找定义processFcns的行。 It means that the trained parameters are valid for input which is preprocessed, and that the output of the network is postprocessed (with the same paramaters as the targets were). 这意味着训练的参数对于预处理的输入有效,并且网络的输出被后处理(具有与目标相同的参数)。 So in your line tansig(W2*(tansig(W1*in+b1))+b2); 所以在你的行tansig(W2*(tansig(W1*in+b1))+b2); you can't use your original inputs. 你不能使用原始输入。 You have to preprocess the input, use the result as the network's input, and postprocess the output using the same parameters that were used to postprocess the targets. 您必须预处理输入,将结果用作网络的输入,并使用用于后处理目标的相同参数对输出进行后处理。 Only then will you get the same result as calling net(in) . 只有这样你才能得到与调用net(in)相同的结果。

You can read more here: http://www.mathworks.com/help/toolbox/nnet/rn/f0-81221.html#f0-81692 您可以在这里阅读更多内容: http//www.mathworks.com/help/toolbox/nnet/rn/f0-81221.html#f0-81692

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM