马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
%CMAC Identification for nonlinear model
function CMAC=CMAC_indentification()
clear all;
close all;
%%%%%%%%%%%%%%%%%%%%initial vallue and set the parameter of system %%%%%%%%
xite=0.8; %输出层权值的学习效率,也可以大于1;
alfa=0.05; %输出层的惯性常数
M=100; N=7; C=7; %M为概念映射量化后的最大值,C为泛化参数,检测单元的感受野大小
%N为实际映射中除以一个质数,中得质数
w=zeros(N,1); %输出层权值的初始值
%w=rands(N,1);
%!!这里C等于w
ts=0.01; tmax=1; %仿真时间和步长
%%%%%%%%%%%%%%%%%%%%%%loop needed value%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
w_1=w; w_2=w; u_1=0;y_1=0;
for k=1:1:tmax/ts
%%%%%%%%%%%%%%%%%%%%%be controled model%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
y=u_1^3+y_1/(1+y_1^2);
u=sin(4*2*pi*k*ts/2)+1;
%%%%%%%%%%%%%%%%%%%%%%%CMAC神经网络输出计算%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
xmin=0; xmax=2; %跟u有直接的关系,是u的最大值和最小值
s=round((u-xmin)*M/(xmax-xmin)); %Quantity,按线性函数量化
sum=0;
for i=1:1:C
ad(i)=mod(s+i,N)+1; %Table mapping and Hash transfer:Start address
sum=sum+w(ad(i));
end
ym=sum; %CMAC神经网络的输出
%%%%%%%%%%%%%%%%%%%%%%%%%CMAC神经网络的输出权值的调整%%%%%%%%%%%%%%%%%%%%%%%%%%
error=y-ym; %性能指标
d_w=xite*error/C; %采用梯度下降法获得
for i=1:1:C
ad(i)=mod(s+i,N)+1; %实际地址,相当于坐标。选中其中的权值进行调整
w(ad(i))=w_1(ad(i))+ d_w+alfa*(w_1(ad(i))-w_2(ad(i)));
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%parameter update%%%%%%%%%%%%%%%%%%%%%%%%%
w_2=w_1;w_1=w;u_1=u;y_1=y;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%output save%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
time(k)=ts*k; %record the time
YY(k)=y; YYm(k)=ym;
end
plot(time,YY,'b',time,YYm,'r');grid on
end
|