编辑: qksr | 2015-08-31 |
002;
c2=0.0002;
c3=0.002;
b=input('输入一个数,输入1可以设定部分参数,输入其他数自动运行: ');
if b==1;
s1=input('输入学习的最大步长: ');
s2=input('输入学习的最小步长,0到1: ');
s=s1;
N=input('输入采样点数,建议为20: ');
Mmax=input('请输入隐层节点的最大数目,必须大于2: ');
a=input('输入学习率,建议输0.8: ');
else s1=2;
s2=0.8;
N=20;
Mmax=10;
a=0.8;
end NUMmax=10000;
X=zeros(1,N);
Y=zeros(1,N);
y=zeros(1,N);
for i=0:N-1;
X(i+1)=2*pi*i/N;
Y(i+1)=0.5+0.4*sin(X(i+1));
end for m=4:Mmax;
W=random('exp',0.5,2,m);
V=random('exp',0.5,1,m+1);
P=zeros(1,m);
Q=zeros(1,m+1);
Q(m+1)=1;
for NUM=1:NUMmax;
E=0;
Emax=0;
for k=1:N;
Z=0;
for j=1:m;
P(j)=W(1,j)*X(k)+W(2,j);
Q(j)=1/(1+exp(-P(j)));
end for j=1:m+1;
Z=Z+V(j)*Q(j);
end y(k)=1/(1+exp(-Z));
e=0.5*(Y(k)-y(k))*(Y(k)-y(k));
if ec2 for j=1:m;
ww1=s*Q(j)*(1-Q(j))*X(k)*(Y(k)-y(k))*y(k)*(1-y(k))*V(j);
ww2=s*Q(j)*(1-Q(j))*(Y(k)-y(k))*y(k)*(1-y(k))*V(j);
W(1,j)=W(1,j)+a*ww1;
W(2,j)=W(2,j)+a*ww2;
end %j for j=1:m+1;
vv=s*(Y(k)-y(k))*y(k)*(1-y(k))*Q(j);
V(j)=V(j)+a*vv;
end %j end if Emax