2016-07-20 29 views
0

私は初期の重みとバイアスがランダムであれば結果が異なることを知っていますので、私はBPニューラルネットワークの構造を最適化し、トレーニング前にGAによって与えられた初期の重みとバイアスを設定するために遺伝的アルゴリズムを使用しました。 私はMatlabのR2014aで仕事をし、私のコードは次の通りである:私は結果毎回が同じであるかどうかを確認するために「のエンド」ループを書いたが、回帰coeffcientが0.8から変化し 初期ウェイトが同じでも毎回異なるニューラルネットワークトレーニング結果が得られるのはなぜですか?

clc 
clear all; 

LoopTime = 100; 
NetAll = cell(1,LoopTime); 
MatFileToSave = sprintf('BPTraining_%4d.mat',LoopTime); 
input_train = xlsread('test.xls','D1:F40')'; 
output_train = xlsread('test.xls','H1:H40')'; 

[inputn,inputps] = mapminmax(input_train); 
[outputn,outputps] = mapminmax(output_train); 

A=[]; 

if ~exist(MatFileToSave,'file') 
for ii = 1:LoopTime 
    net.divideFcn = 'dividerand'; 
    net.divideMode = 'sample'; 
    net=newff(inputn,outputn,7,{'tansig'},'trainlm'); 
    net.divideParam.trainRatio = 70/100; 
    net.divideParam.valRatio = 30/100; 
    net.divideParam.testRatio = 0/100; 
    net.trainParam.epochs=2000; 
    net.trainParam.lr=0.1; 
    net.trainParam.goal=0.00001; 

    net.iw{1,1} = [0.56642385,-0.044929342,2.806006491; 
    -0.129892602,2.969433103,-0.056528269; 
    0.200067228,-1.074037985,-0.90233406; 
    -0.794299829,-2.202876191,0.346403187; 
    0.083438759,1.246476813,1.788348379; 
    0.889662621,1.024847111,2.428373515; 
    -1.24788069,1.383238864,-1.313847905]; 
    net.b{1} = [-1.363912639;-1.978352461;-0.036013077;0.135126212;1.995020537;-0.223083372;-1.013341625]; 
    net.lw{2,1} = [-0.412881802 -0.146069773 1.711325447 -1.091444059 -2.069737603 0.765038862 -2.825474689];  
    net.b{2} = [-2.182832342];  

    [net,tr]=train(net,inputn,outputn); 

    yyn = sim(net,inputn); 
    yy = mapminmax('reverse',yyn,outputps); 
    regre = min(corrcoef(yy,output_train)); 
    error = (yy-output_train)/output_train ; 
    rmse = std(yy); 

    A = [A;ii,regre,error,rmse]; 

    NetAll{ii} = net; 

    clear net; 

    figure 
    plotregression(output_train,yy,'Regression'); 

    forder = 'regre_tr'; 
    if ~exist(forder,'dir'); 
    mkdir(forder); 
    end 
    picstr = [ forder '\regre_' num2str(ii)]; 
    print('-dpng','-r100',picstr); 
    close 

end 

save(MatFileToSave,'NetAll'); 

xlswrite('BPTraining_100.xls',A); 
end 

期待どおりになることは決してありません。

だから、私の質問は:

  1. は正しい初期重みを設定するための私のコードですか?そうでなければ、セットアップ方法は?
  2. 正しい場合、なぜ結果がまだ異なるのですか?
+1

おそらくこの 'net.divideFcn =「dividerand」;'この 'net.divideMode =「サンプル」;'異なる上の各ネットワークを訓練していますデータのサブセット –

答えて

2

これは@Neil Slaterとまったく同じです:deviderandのどこかにランダムな部分があり、ランダム性を修正しないと結果が異なる場合があります。試してください:

[a,b,c]=dividerand(10,0.7,0.15,0.15) 

複数回結果が変わります。

open dividerand %opens the matlab function 
%change the of the function in line 1 
function [out1,out2,out3,out4,out5,out6] = mydividerand(in1,varargin) 
%go to line 105 and add 
rng(1); fixing the random seed 
allInd = randperm(Q); %previous line 105 that is the random part of the function 
%use 'save as' and save it to your workfolder 
:ニールが提案または固定ランダムシード(私はもうその固定dividerandのisin'tが本当にランダムな事実を反映してスキップ)を使用して独自のdividerand関数を作成することができますようにあなたのいずれかを行うことができ異なる「net.divideMode」のO

元の 'dividerand'を変更することは賢明ではないので、何かに触れる前に「別名で保存」を行ってください。また、新しい関数名は(mydividerandのように)異なる、ユニークである必要があり

[a,b,c]=mydividerand(10,0.7,0.15,0.15)%always the same result 
関連する問題