bp神经网络实验报告郑航_BP神经网络实验报告
DeltaVold=DeltaV;
% adjust thresholds Pi and Tau
DeltaPi=Beta*e+Gamma*DeltaPiOld;
Pi=Pi+DeltaPi;
DeltaPiold=DeltaPi;
DeltaTau=Alpha*d+Gamma*DeltaTauOld;
Tau=Tau+DeltaTau;
DeltaTauold=DeltaTau;
% the error is the max of d(1),d(2),d(3)
Err(Epoch)=Err(Epoch)+0.5*(d(1)*d(1)+d(2)*d(2)+d(3)*d(3)); end %for k=1:Ntrain
Err(Epoch)=Err(Epoch)/Ntrain;
Error=Err(Epoch);
% the training stops when iterate is too much
if Epoch > Maxepoch
break;
end
Epoch = Epoch +1; % update the iterate number
end
% test data
for k=1:Ntest % k = the index of test set
a=datanorm(Ntrain+k,:); % get the input of test sets
% calculate the hidden nodes activation
for ki=1:i
b(ki)=logsig(a*V(:,ki)+Pi(ki));
end;
% calculate the output of test sets
for kj=1:j
c(kj)=logsig(b*W(:,kj)+Tau(kj));
end;
% transfer the output to one field format
if (c(1)> 0.9)
Otest(k)=0;
elseif (c(2)> 0.9)
Otest(k)=1;
elseif (c(3)> 0.9)
Otest(k)=2;
else
Otest(k)=3;
end;
% calculate the accuracy of test sets
if Otest(k)==Odesired(Ntrain+k)
Accuracy=Accuracy+1;
更多推荐
所有评论(0)