3

マウス ジェスチャ認識用の単純なニューラル ネットワーク (入力は角度) を作成し、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 に等しい)。commend からの出力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)
4

1 に答える 1

5

コードに見られるように、ネットワークは入力の自動化された前処理とターゲットの後処理を適用します - を定義する行を探しますprocessFcns。これは、トレーニングされたパラメーターが前処理された入力に対して有効であり、ネットワークの出力が後処理されることを意味します (ターゲットと同じパラメーターを使用)。したがって、あなたの行でtansig(W2*(tansig(W1*in+b1))+b2);は元の入力を使用できません。入力を前処理し、結果をネットワークの入力として使用し、ターゲットの後処理に使用したのと同じパラメーターを使用して出力を後処理する必要があります。そうして初めて、 を呼び出したのと同じ結果が得られますnet(in)

ここで詳細を読むことができます: http://www.mathworks.com/help/toolbox/nnet/rn/f0-81221.html#f0-81692

于 2012-05-23T20:40:14.947 に答える