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;

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐