T-S模糊神经网络算法

%数据点个数51
numpts=51;
x1=linspace(0,1,numpts);
y=.6*sin(pi*x1)+.3*sin(3*pi*x1)+.1*sin(5*pi*x1);
data=[x1' y']; %整个数据集
trndata=data(1:2:numpts,:); %训练数据集
chkdata=data(2:2:numpts,:); %测试数据集
%训练数据和检验数据的分布曲线
plot(trndata(:,1),trndata(:,2),'o',chkdata(:,1),chkdata(:,2),'x')

%建立T_S模糊模型
%采用genfis1()函数直接由训练数据生成模糊推理系统
nummfs=5; %隶属度函数个数
mftype='gbellmf'; %隶属度函数类型
fismat=genfis1(trndata,nummfs,mftype);
%绘制模糊推理系统的初始隶属度函数
[x,mf]=plotmf(fismat,'input',1);
figure
plot(x,mf);
title('initial menbership functions')

%使用函数anfis()进行神经模糊建摸
numepochs=40; %训练次数40
[fismat1,truerr,ss,fismat2,chkerr]=anfis(trndata,fismat,numepochs,nan,chkdata);
%计算训练后神经模糊系统的输出与训练数据的均方根误差
trnout=evalfis(trndata(:,1),fismat1);
trnrmse=norm(trnout-trndata(:,2))/sqrt(length(trnout));
%绘制训练过程中均方根误差的变化情况
epoch=1:numepochs;
figure
plot(epoch,truerr,'o',epoch,chkerr,'x')
hold on
plot(epoch,[truerr,chkerr]);
hold off
%绘制训练过程中的步长的变化的情况
figure
plot(epoch,ss,'-',epoch,ss,'x');
%绘制训练后模糊推理系统的隶书度函数曲线
[x,mf]=plotmf(fismat1,'input',1);
figure
plot(x,mf)
title('fiual membership function');
%绘制神经模糊推理系统的输出曲线
anfis_y=evalfis(x1,fismat1);
figure
plot(x1,y,'-',x1,anfis_y,'x');


相关文档
最新文档