2012-05-23 165 views
3

我做了簡單的鼠標手勢識別神經網絡(輸入是角度),我用nprtool(函數模式網創建)。我節省了網絡的權重和偏見:MATLAB神經網絡模式識別

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) 
+1

請包括創建'net',我們不能猜測參數沒有你使用的代碼。不用猜測它創建了什麼函數也是很好的('network'?) –

+0

我在一分鐘前完成了它。我會很感激的幫助:) – mydew

回答

4

如可以在你的代碼中可以看出,網絡應用的自動化目標的輸入和後處理的預處理 - 尋找它定義processFcns線。這意味着訓練過的參數對預處理的輸入有效,並且網絡的輸出被後處理(與目標相同的參數)。所以在你的線tansig(W2*(tansig(W1*in+b1))+b2);你不能使用你的原始輸入。您必須對輸入進行預處理,將結果用作網絡輸入,並使用與用於後處理目標相同的參數後處理輸出。只有這樣你才能得到與調用net(in)相同的結果。

你可以在這裏閱讀更多:http://www.mathworks.com/help/toolbox/nnet/rn/f0-81221.html#f0-81692

+0

哦,我現在看到。非常感謝! :) – mydew