[英]MATLAB Neural Network pattern recognition
我已經為鼠標手勢識別(輸入是角度)制作了簡單的神經網絡,並且我使用了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)
從代碼中可以看出,網絡對目標的輸入和后處理應用自動預處理 - 查找定義processFcns
的行。 這意味着訓練的參數對於預處理的輸入有效,並且網絡的輸出被后處理(具有與目標相同的參數)。 所以在你的行tansig(W2*(tansig(W1*in+b1))+b2);
你不能使用原始輸入。 您必須預處理輸入,將結果用作網絡的輸入,並使用用於后處理目標的相同參數對輸出進行后處理。 只有這樣你才能得到與調用net(in)
相同的結果。
您可以在這里閱讀更多內容: http : //www.mathworks.com/help/toolbox/nnet/rn/f0-81221.html#f0-81692
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.