2016-07-20 1 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 

0.98로 예상했던 것과 결코 같지 않습니다.

그래서, 내 질문은 :

  1. 올바른 초기 가중치를 설정하는 내 코드인가? 그렇지 않다면 설정하는 방법은 무엇입니까?
  2. 맞으면 결과가 여전히 다른 이유는 무엇입니까?
+1

아마이'net.divideFcn = 'dividerand'(mydividerand 등)에서 고유해야한다 '이'net.divideMode = '샘플은'; '다른 각 네트워크를 훈련되고 데이터의 부분 집합. –

답변

2

정확하게 @Neil Slater가 말했듯이 : deviderand 어딘가에있는 함수는 임의의 부분이며 임의성을 수정하지 않으면 결과가 달라질 수 있습니다. 시도 :

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

여러 번 결과가 변경됩니다. 당신은 할 수 닐 제안 또는 고정 임의 씨와 자신의 dividerand 기능을 만들 수 있습니다처럼 다른 'net.divideMode'에 대한 오 중 (내가 사실을 반영 건너 뛰 정말 무작위로 고정 dividerand의 isin't 이상) :

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'를 변경하는 것이 현명하지 않으므로 아무 것도 터치하기 전에 '다른 이름으로 저장'을 선택하십시오. 또한, 새로운 기능의 이름이 다르고

[a,b,c]=mydividerand(10,0.7,0.15,0.15)%always the same result