智能控制神经网络作业.docx
《智能控制神经网络作业.docx》由会员分享,可在线阅读,更多相关《智能控制神经网络作业.docx(15页珍藏版)》请在冰豆网上搜索。
智能控制神经网络作业
智能控制作业
学生姓名:
学号:
专业班级:
7-2采用BP网路、RBF网路、DRNN网路逼近线性对象
,分别进行matlab仿真。
(一)采用BP网络仿真
网络结构为2-6-1。
采样时间1ms,输入信号
,权值
的初值随机取值,
。
仿真m文件程序为:
%BPsimulation
clearall;
clearall;
xite=0.5;
alfa=0.5;
w1=rands(2,6);%valueofw1,initiallybyrandom
w1_1=w1;w1_2=w1;
w2=rands(6,1);%valueofw2,initiallybyrandom
w2_1=w2;w2_2=w2_1;
dw1=0*w1;
x=[0,0]';
u_1=0;
y_1=0;
I=[0,0,0,0,0,0]';%inputofyinhancengcell
Iout=[0,0,0,0,0,0]';%outputofyinhancengcell
FI=[0,0,0,0,0,0]';
ts=0.001;
fork=1:
1:
1000
time(k)=k*ts;
u(k)=0.5*sin(3*2*pi*k*ts);
y(k)=(u_1-0.9*y_1)/(1+y_1^2);
forj=1:
1:
6
I(j)=x'*w1(:
j);
Iout(j)=1/(1+exp(-I(j)));
end
yn(k)=w2'*Iout;%outputofnetwork
e(k)=y(k)-yn(k);%errorcalculation
w2=w2_1+(xite*e(k))*Iout+alfa*(w2_1-w2_2);%rectifyofw2
forj=1:
1:
6
FI(j)=exp(-I(j))/(1+exp(-I(j))^2);
end
fori=1:
1:
2
forj=1:
1:
6
dw1(i,j)=e(k)*xite*FI(j)*w2(j)*x(i);%dw1calculation
end
end
w1=w1_1+dw1+alfa*(w1_1-w1_2);%rectifyofw1
%jacobianinformation
yu=0;
forj=1:
1:
6
yu=yu+w2(j)*w1(1,j)*FI(j);
end
dyu(k)=yu;
x
(1)=u(k);
x
(2)=y(k);
w1_2=w1_1;w1_1=w1;
w2_2=w2_1;w2_1=w2;
u_1=u(k);
y_1=y(k);
end
figure
(1);
plot(time,y,'r',time,yn,'b');
xlabel('times');ylabel('yandyn');
figure
(2);
plot(time,y-yn,'r');
xlabel('times');ylabel('error');
figure(3);
plot(time,dyu);
xlabel('times');ylabel('dyu');
运行结果为:
(二)采用RBF网络仿真
网路结构为2-4-1,采样时间1ms,输入信号
,权值的初值随机取值,
,高斯基函数初值
,
。
仿真m文件程序如下:
%RBFsimulation
clearall
clearall
alfa=0.05;
xite=0.5;
x=[0,0]';
b=1.5*ones(4,1);
c=0.5*ones(2,4);
w=rands(4,1);
w_1=w;w_2=w_1;
c_1=c;c_2=c_1;
b_1=b;b_2=b_1
d_w=0*w;
d_b=0*b;
y_1=0;
ts=0.001;
fork=1:
1:
2000;
time(k)=k*ts;
u(k)=0.5*sin(1*2*pi*k*ts);
y(k)=(u(k)-0.9*y_1)/(1+y_1^2);
x
(1)=u(k);
x
(2)=y_1;
forj=1:
1:
4
h(j)=exp(-norm(x-c(:
j))^2/(2*b(j)*b(j)));
end
ym(k)=w'*h';
em(k)=y(k)-ym(k);
forj=1:
1:
4
d_w(j)=xite*em(k)*h(j);
d_b(j)=xite*em(k)*w(j)*h(j)*(b(j)^-3)*norm(x-c(:
j))^2;
fori=1:
1:
2
d_c(i,j)=xite*em(k)*w(j)*h(j)*(x(i)-c(i,j))*(b(j)^-2);
end
end
w=w_1+d_w+alfa*(w_1-w_1);
b=b_1+d_b+alfa*(b_1-b_2);
c=c_1+d_c+alfa*(c_1-c_2);
%Jacobianinformation
yu=0;
forj=1:
1:
4
yu=yu+w(j)*h(j)*(c(1,j)-x
(1))/b(j)^2;
end
dyu(k)=yu;
y_1=y(k);
w_2=w_1;
w_1=w;
c_2=c_1;
c_1=c;
b_2=b_1;
b_1=b;
end
figure
(1);
plot(time,y,'r',time,ym,'b');
xlabel('time(s)');ylabel('yandym');
figure
(2);
plot(time,y-ym,'r');
xlabel('time(s)');ylabel('error');
figure(3);
plot(time,dyu,'b');
xlabel('time(s)');ylabel('dyu');
仿真结果为:
(三)DRNN网路仿真
采样时间1ms,输入信号
,权值
的初值随机取值,取
。
仿真m文件程序为:
%DRNNsimulation
clearall;
clearall;
wd=rands(7,1);
wo=rands(7,1);
wi=rands(3,7);
xj=zeros(7,1);
xj_1=xj;
u_1=0;y_1=0;
xitei=0.35;
xited=0.35;
xiteo=0.35;
ts=0.001;
fork=1:
1:
1000
time(k)=k*ts;
u(k)=0.5*sin(4*pi*k*ts);
y(k)=(u_1-0.9*y_1)/(1+y_1^2);
Ini=[u_1,y_1,1]';
forj=1:
1:
7
sj(j)=Ini'*wi(:
j)+wd(j)*xj(j);
end
forj=1:
1:
7
xj(j)=(1-exp(-sj(j)))/(1+exp(-sj(j)));
end
Pj=0*xj;
forj=1:
1:
7
Pj=wo(j)*(1+xj(j))*(1-xj(j))*xj_1(j);
end
Qij=0*wi;
forj=1:
1:
7
fori=1:
1:
3
Qij(i,j)=wo(j)*(1+xj(j))*(1-xj(j))*Ini(i);
end
end
ymk=0;
forj=1:
1:
7
ymk=ymk+xj(j)*wo(j);
end
ym(k)=ymk;
e(k)=y(k)-ym(k);
wo=wo+xiteo*e(k)*xj;
wd=wd+xited*e(k)*Pj;
wi=wi+xitei*e(k)*Qij;
xj_1=xj;
u_1=u(k);
y_1=y(k);
end
figure
(1);
plot(time,y,'r',time,ym,'b');
xlabel('time/s');ylabel('yandym');
figure
(2);
plot(time,y-ym,'r');
xlabel('time/s');ylabel('error');
仿真结果为: