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');
당신이 실제로 신경망을 훈련 하시겠습니까? 각 트레이닝 사이클에 동일한 가중치를 사용하면 (예 : 가중치가 변경되지 않음) 신경망을 학습 할 수있는 방법이 없습니다 ... 목표가 무엇입니까? – Kiril
네, NN을 훈련시키고 싶습니다. 내 .m 파일에서 NN을 만들고 기차하고 시뮬레이션합니다. 그러나 세 번째로 실행할 때 얻는 네트워크 교육의 최상의 성능.그래서, 제 아이디어는 두 번째 달리기에서 가중치를 저장하고 다음 번에 가중치로 사용합니다 (그래서 3 번 연속으로 실행할 필요가 없습니다). – user999507