bp神经网络设计源程序
clear
c=load('d:\c.txt');
a=load('d:\a.txt');
c=c';
a=a';
n=0;
dsum=1;
v=abs(randn(3,6)); %输入层至隐含层连接权
z1=randn(3,1);%输入层阈值
z=zeros(3,5);
z(:,1)=z1;
z(:,2)=z1;
z(:,3)=z1;
z(:,4)=z1;
z(:,5)=z1;
s=zeros(3,5);
b=zeros(3,5);
%隐含层至输出层
w=abs(randn(2,3)); %隐含层至输出层连接权
zy1=randn(2,1);%隐含层阈值
zy(:,1)=zy1;
zy(:,2)=zy1;
zy(:,3)=zy1;
zy(:,4)=zy1;
zy(:,5)=zy1;
l=zeros(2,5);
cc=zeros(2,5);
con=[1 1 1 1 1; 1 1 1 1 1];
d=zeros(2,5);
con2=[1 1 1 1 1;1 1 1 1 1;1 1 1 1 1];
SL1=randn(1,1);
SL2=randn(1,1);
while dsum>0.00001
s=v*a+z;
b=1./(1+exp(-s) );
%隐含层至输出层
l=w*b+zy;
cc=1./(1+exp(-l));
%计算误差
j=c-cc;
d=j.*c.*(con-c);
e=w'*d.*b.*(con2-b);
SL1=abs(randn(1,1));
SL2=abs(randn(1,1));
w=w+SL1*d*b';
zy=zy+SL1*d;
v=v+SL2*e*a';
z=z+SL2*e;
dsum=0;
for i=1:2
for j=1:5
dsum=dsum+abs(d(i,j));
end
end
n=n+1;
error(n)=dsum;
end
n1=1:n;
plot(n1,error)