% 使用TS模型实现 非线性映射:f(x1,x2)=sin(pi*x1)*cos(pi*x2);
%首先计算隶属度函数,分成了5个等级
clear all;
x1=-1:0.1:1;
x2=-1:0.1:1;
C=[-1 -0.5 0 0.5 1;-1 -0.5 0 0.5 1]; %初始的Cij中心,每一行对应一个分量
Variance=zeros(2,5);
lrate=input('请输入学习率,回车为缺省值 0.6: ');
if isempty(lrate)
lrate=0.6; %学习率alfa
end
count=input('请输入迭代步数,回车为缺省值 300步: ');
if isempty(count)
count=300; % 学习迭代次数
end
disp '隶属度函数的方差为0.15'
Variance=Variance+0.15; %初始的隶属度函数的方差
%Rule=zeros(25,441); %规则的使用度,网络的第三层
%Rule1=zeros(25,441); %归一化后的适用度
W=rand(25,3); %TS模型后件网络的系数p
%Y=zeros(1,25); %使用TS模型每一条规则的后件
%初始计算隶属度函数的值
for i=1:5
for j=1:21
b1(i,j)=exp(-(x1(j)-C(1,i))*(x1(j)-C(1,i))/Variance(1,i));
end
end
figure('color','white');
for i=1:5
plot(x1,b1(i,:));hold on;
end
title('输入分量x1和x2的隶属度函数');
disp '计算中,请等待......'
%载入样本数据,采样率0.1
load sample;
load dt;
[P T]=size(sample);
dt=t;
Temp=ones(P,1);
sample1=[Temp sample]; %在后件网络中使用的样本,有一列为1
%首先计算初始的计算值
for k=1:count
for p=1:P
%计算输出
%分层计算 ,第二层中的隶属度函数的值
for i=1:5
belong1(i,p)=exp(-(sample(p,1)-C(1,i))*(sample(p,1)-C(1,i))/Variance(1,i));
belong2(i,p)=exp(-(sample(p,2)-C(2,i))*(sample(p,2)-C(2,i))/Variance(2,i));
end
%开始计算第三层
for i=1:5
for j=1:5
TempA=[belong1(i,p) belong2(j,p)];
[Value Index]=min(TempA);
Rule((i-1)*5+j,p)=Value;
if (Rule((i-1)*5+j,p))< 0.05
Rule((i-1)*5+j,p)=0;
end %end if
end % end of j
end %end of i
%第四层
Rule1(:,p)=Rule(:,p)/sum(Rule(:,p));
%前件计算结束
%计算后件网络
for i=1:25
Y(i,p)=sample1(p,:)*W(i,:)';
end
YF(p)=Y(:,p)'*Rule1(:,p);
es=dt(p)-YF(p);
for j1=1:25
for i1=1:3
TempW(j1,i1)=W(j1,i1)+lrate*es*Rule1(j1,p)*sample1(p,i1);
end %end of i
end %end of j
W=TempW;
end
E(k)=sqrt((dt-YF)*(dt-YF)')/P; %RMS
k
end %end of k
%误差显示和结果输出
k=1:count;
figure('color','white');
plot(k,E(k));
t=strcat('Fuzzy Netual Network 学习算法学习曲线,最终误差=',num2str(E(count)));
title(t);
xlabel('迭代步数');
ylabel('学习误差');
disp 'finished!!!!'
E(count)
%测试网络,使用不同的采样率数据测试,输出结果
load sample1
load dt1
[P T]=size(sample);
temp=ones(P,1);
sample1=[temp sample];
dt=t;
%计算网络输出得到误差
for p=1:P
%分层计算 ,第二层中的隶属度函数的值
for i=1:5
belong1(i,p)=exp(-(sample(p,1)-C(1,i))*(sample(p,1)-C(1,i))/Variance(1,i));
belong2(i,p)=exp(-(sample(p,2)-C(2,i))*(sample(p,2)-C(2,i))/Variance(2,i));
end
%开始计算第三层
for i=1:5
for j=1:5
TempA=[belong1(i,p) belong2(j,p)];
[Value Index]=min(TempA);
Rule((i-1)*5+j,p)=Value;
if (Rule((i-1)*5+j,p))< 0.005
Rule((i-1)*5+j,p)=0;
end %end if
end % end of j
end %end of i
%第四层
Rule1(:,p)=Rule(:,p)/(sum(Rule(:,p)));
%前件计算结束
%计算后件网络
for i=1:25
Y(i,p)=sample1(p,:)*W(i,:)';
end
YF(p)=Y(:,p)'*Rule1(:,p);
end
%E1=(0.5*(dt-YF)*(dt-YF)')/P;
for i=1:17
for j=1:17
AfterTrain(i,j)=YF(17*(i-1)+j);
end
end
figure('color','white');
load X1
load Y1
surf(X,Y,AfterTrain);
title('训练后f(x1,x2)=sin(\pix1)cos(\pix2)的图形');
tic
toc
基于matlab实现使用模糊神经网络实现非线性函数映射,直接在matlab中运行即可.rar
版权申诉
140 浏览量
2024-04-28
22:11:31
上传
评论
收藏 2KB RAR 举报
依然风yrlf
- 粉丝: 891
- 资源: 3118
最新资源
- 基于Javascript和Python的微商城项目设计源码 - MicroMall
- 基于Java的网上订餐系统设计源码 - online ordering system
- 基于Javascript的超级美眉网络资源管理应用模块设计源码
- 基于Typescript和PHP的编程知识储备库设计源码 - study-php
- Screenshot_2024-05-28-11-40-58-177_com.tencent.mm.jpg
- 基于Dart的Flutter小提琴调音器APP设计源码 - violinhelper
- 基于JavaScript和CSS的随寻订购网页设计源码 - web-order
- 基于MATLAB的声纹识别系统设计源码 - VoiceprintRecognition
- 基于Java的微服务插件集合设计源码 - wsy-plugins
- 基于Vue和微信小程序的监理日志系统设计源码 - supervisionLog
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈