|
lr=0.01; max_epoch=1000; %lr为学习速率,max_epoch为循环的最大次数
sl=0.99;
err_goal=0.001; %err_goal为期望误差最小数
W0=[0 0 0 0 0;0 0 0 0.9999 0.9999;0.3670 0.1511 0 0.9999 0;0.4968 0.9999 0 0 0.9999;0.4359 0.3496 0 0.9999 0]
A0=[0.0547 -0.0570 0.0433 0.0678 -0.0536]
N=5; %N为概念的个数
Wk=W0;
Ak=A0;
for epoch=1:max_epoch
Al=Ak+Ak*Wk';
for i=1:N %计算节点Ci的值
%Al(i,1)=1/(1+exp(-Al(i,1)));
Al(1,i)=tanh(Al(1,i));
end
for i=1:N %更新W
for j=1:N
if Wk(i,j)~=0
Wk(i,j)=sl*Wk(i,j)+lr*Ak(1,i)*(Ak(1,i)-sign(Wk(i,j))*Wk(i,j)*Ak(1,i));
else
Wk(i,j)=0;
end
end
end
C1(epoch)=Ak(1,1);
C2(epoch)=Ak(1,2);
C3(epoch)=Ak(1,3);
C4(epoch)=Ak(1,4);
C5(epoch)=Ak(1,5);
f1=abs(Al(1,1)-Ak(1,1));
f2=abs(Al(1,5)-Ak(1,5));
if (f1<err_goal)&(f2<err_goal)break;end;
Ak=Al;
end
disp('按任意健继续')
pause
plot(C1,'r')
hold on
plot(C2,'c')
hold on
plot(C3,'m')
hold on
plot(C4,'y')
hold on
plot(C5,'b') |
评分
-
1
查看全部评分
-
|