??? Index exceeds matrix dimensions.
运行时出现这个错误提示,不知道怎么修改,麻烦大家帮我看、改一下%第一步:
lr=0.01; max_epoch=1000;%lr为学习速率,max_epoch为循环的最大次数
sl=0.99;
err_goal=0.001; %err_goal为期望误差最小数
W0=
A0=
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(i,1)=tanh(Al(i,1));
end
for i=1:N %更新W
for j=1:N
if Wk(i,j)~=0
Wk(i,j)=sl*Wk(i,j)+lr*Ak(j,1)*(Ak(i,1)-sign(Wk(i,j))*Wk(i,j)*Ak(j,1));
else
Wk(i,j)=0;
end
end
end
C1(epoch)=Ak(1,1);
C2(epoch)=Ak(2,1);
C3(epoch)=Ak(3,1);
C4(epoch)=Ak(4,1);
C5(epoch)=Ak(5,1);
f1=abs(Al(1,1)-Ak(1,1));
f2=abs(Al(5,1)-Ak(5,1));
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') 保存成m文件,按照错误提示一步步改就行了 lr=0.01; max_epoch=1000;%lr为学习速率,max_epoch为循环的最大次数
sl=0.99;
err_goal=0.001; %err_goal为期望误差最小数
W0=
A0=
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]