2011-10-17 5 views
5

newff (...)를 사용하여 MATLAB에서 신경망을 만들었습니다. 동일한 입력 및 출력으로 교육 할 때 교육 결과는 실행마다 다릅니다. 나는 그것이 실행될 때마다 가중치가 다르기 때문에 그것이 일어나고 있음을 이해합니다. 내 질문은 동일한 결과를 얻을 수 있도록 내 NN을 훈련 할 때마다 초기 가중치를 동일하게 만드는 방법입니다. 또한, No1 교육에서 일부 가중치를 저장하는 것이 가능하고 후자는 No2 교육에 사용할 수 있습니까? generate reproducible results으로MATLAB의 신경망, 초기 가중치

TNX

+1

당신이 실제로 신경망을 훈련 하시겠습니까? 각 트레이닝 사이클에 동일한 가중치를 사용하면 (예 : 가중치가 변경되지 않음) 신경망을 학습 할 수있는 방법이 없습니다 ... 목표가 무엇입니까? – Kiril

+0

네, NN을 훈련시키고 싶습니다. 내 .m 파일에서 NN을 만들고 기차하고 시뮬레이션합니다. 그러나 세 번째로 실행할 때 얻는 네트워크 교육의 최상의 성능.그래서, 제 아이디어는 두 번째 달리기에서 가중치를 저장하고 다음 번에 가중치로 사용합니다 (그래서 3 번 연속으로 실행할 필요가 없습니다). – user999507

답변

6

, 당신은 수동으로 코드의 시작 부분에 같은 씨앗/상태로 난수 발생기를 설정해야합니다. 이것은 (당신은 MATLAB의 버전에 따라 다름) number of ways으로 수행 할 수 있습니다

오래된 스타일 :

rand('twister',1234) 

업데이트 된 스타일 :

RandStream.setGlobalStream(RandStream('mt19937ar','Seed',1234)); 

new function이 R2011a에서 소개되었다 마지막 호출을 단순화합니다.

rng(1234,'twister') 

atter 구문을 사용하는 것이 좋습니다.

2

직접적인 대답이 아니라 보조 메모로 Nguyen Widrow initialization and it's already implemented in Matlab's Neural Net toolbox이라고하는 것이 있습니다.

내 경험상 꽤 잘 작동하고 신경망이 더 빠르게 수렴하는 데 도움이됩니다. 나는 또한 결과가 더욱 일관성이 있다는 것을 발견했다. Amro's post에 따라 고정 랜덤 시드를 사용하는 것이 좋습니다. "대신 다른 데이터 분할 문제 이용 함수 「divideblock"또는 "divideint"에로틱 랜덤 데이터 분할 2 랜덤 중량 초기화

:

+0

Chris는 맞습니다. 어떤 종류의 가중치 초기화가 기본값으로 사용되는지주의 깊게 확인하십시오. MATLAB의 마지막 버전에서는 기본값이 임의의 초기화가 아니고 Nguyen Widrow 초기화 알고리즘이기 때문입니다. –

-1
If you really want to have the weights before and after the training of NN you can use these codes : 

for n1=4:8 
    wb1=rand(n1,n_input); 
    wb2=rand(n_output,n1); 
    bb1=rand(n1,1); 
    bb2=rand(n_output,1); 

    wb=[wb1(:);wb2(:);bb1;bb2]'; 

    xlswrite(['weight' num2str(n1) '.xlsx'],wb,'Sheet1',num2str(n1)); 

end 


if n1==4 
     wb = xlsread(['weight' num2str(n1) '.xlsx']); 
     i1 = n1*n_input; 
     i2 = n_output*n1; 
     i3 = n1; 
     i4 = n_output; 

     f1=wb(1:i1); 
     f2=wb(i1+1:i1+i2); 
     f3=wb(i1+i2+1:i1+i2+i3); 
     f4=wb(i1+i2+i3+1:i1+i2+i3+i4); 

     wb1=reshape(f1,n1,n_input); 
     wb2=reshape(f2,n_output,n1); 
     bb1=reshape(f3,n1,1); 
     bb2=reshape(f4,n_output,1); 

    elseif n1==5 
     wb=xlsread(['weight' num2str(n1) '.xlsx']); 
     i1=n1*n_input; 
     i2=n_output*n1; 
     i3=n1; 
     i4=n_output; 

     f1=wb(1:i1); 
     f2=wb(i1+1:i1+i2); 
     f3=wb(i1+i2+1:i1+i2+i3); 
     f4=wb(i1+i2+i3+1:i1+i2+i3+i4); 

     wb1=reshape(f1,n1,n_input); 
     wb2=reshape(f2,n_output,n1); 
     bb1=reshape(f3,n1,1); 
     bb2=reshape(f4,n_output,1); 

    elseif n1==6 
     wb=xlsread(['weight' num2str(n1) '.xlsx']); 
     i1=n1*n_input; 
     i2=n_output*n1; 
     i3=n1; 
     i4=n_output; 

     f1=wb(1:i1); 
     f2=wb(i1+1:i1+i2); 
     f3=wb(i1+i2+1:i1+i2+i3); 
     f4=wb(i1+i2+i3+1:i1+i2+i3+i4); 

     wb1=reshape(f1,n1,n_input); 
     wb2=reshape(f2,n_output,n1); 
     bb1=reshape(f3,n1,1); 
     bb2=reshape(f4,n_output,1); 

    elseif n1==7 
     wb=xlsread(['weight' num2str(n1) '.xlsx']); 
     i1=n1*n_input; 
     i2=n_output*n1; 
     i3=n1; 
     i4=n_output; 

     f1=wb(1:i1); 
     f2=wb(i1+1:i1+i2); 
     f3=wb(i1+i2+1:i1+i2+i3); 
     f4=wb(i1+i2+i3+1:i1+i2+i3+i4); 

     wb1=reshape(f1,n1,n_input); 
     wb2=reshape(f2,n_output,n1); 
     bb1=reshape(f3,n1,1); 
     bb2=reshape(f4,n_output,1); 

    elseif n1==8 
     wb=xlsread(['weight' num2str(n1) '.xlsx']); 
     i1=n1*n_input; 
     i2=n_output*n1; 
     i3=n1; 
     i4=n_output; 

     f1=wb(1:i1); 
     f2=wb(i1+1:i1+i2); 
     f3=wb(i1+i2+1:i1+i2+i3); 
     f4=wb(i1+i2+i3+1:i1+i2+i3+i4); 

     wb1=reshape(f1,n1,n_input); 
     wb2=reshape(f2,n_output,n1); 
     bb1=reshape(f3,n1,1); 
     bb2=reshape(f4,n_output,1); 
    end 

    net = newff(inputs,targets,4,{'tansig','purelin'},'trainlm'); 
    n.IW{1,1}=wb1; 
    n.LW{2,1}=wb2; 
    n.b{1}=bb1; 
    n.b{2}=bb2; 


And after training for saving the network you want : 

[net tr] = train(net,inputs,targets); 

wb11=n.IW{1,1}; 
    wb22=n.LW{2,1}; 
    bb11=n.b{1}; 
    bb22=n.b{2}; 

    wbzz=[wb11(:);wb22(:);bb11;bb22]'; 

    xlswrite('weight.xlsx',wbzz,'Sheet1'); 
2

다른 matlab에 신경망 툴박스 결과는 두 가지 이유로 인 dividerand "이 같은 :

net.dividefcn='divideblock; net.divideparam.trainratio=.7; net.divideparam.valratio=.15; net.divideparam.testratio=.15;

랜덤 웨이트 초기화 문제의 경우 Matlab 초기화 함수 ("initzero", "initlay", "initwb", "initnw")가 거의 무작위 인 것으로 보입니다. 따라서이 함수가 호출 당 비슷한 결과를 얻도록 강요해야합니다.

RandStream.setGlobalStream (RandStream ('mrg32k3a','Seed', 1234));

그리고 그들 중 하나를 사용

net.initFcn='initlay'; net.layers{i}.initFcn='initnw';

+0

코드를 형식화하기 시작하여 인내심을 잃었습니다 .-- 직접 백 메틱을 편집하고 제거하십시오. – kleopatra

+0

Backticks가 무엇입니까? –