|
楼主 |
发表于 2006-9-29 11:16
|
显示全部楼层
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%使用anfis函数进行给定数据的神经网络模糊建模
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
numEpochs=40; %训练次数为40
[fismat1,trnErr,ss,fismat2,chkErr]=anfis(trnData,fismat,numEpochs,NaN,chkData);
%计算训练后神经网络模糊系统的输出与训练数据的均方根误差
%trnData2= reshape(trnData,45,2);
trnOut=evalfis(trnData(:,1:2),fismat1);
trnRMSE=norm(trnOut-trnData(:,3))/sqrt(length(trnOut));
%绘制训练过程中均方根误差的变化情况
epoch=1:numEpochs;
figure(3);
plot(epoch,trnErr,'o',epoch,chkErr,'kx')
%绘制训练过程中的最小二乘误差变化情况,如果训练数据和核对数据的误差同时减小,模型才是有效的
hold on;
plot(epoch,[trnErr chkErr]);
hold off
%绘制训练过程中步长的变化情况
figure(4)
plot(epoch,ss,'-',epoch,ss,'ko')
xlabel('epochs'),ylabel('ss'),title('Step Sizes')
%下面绘制训练后面模糊推理系统的隶属度函数曲线
figure(5)
[x,mf]=plotmf(fismat1,'input',1);
subplot(2,1,1),plot(x,mf);
xlabel('input 1 (pimf)');
title('训练后隶属度函数')
[x,mf]=plotmf(fismat1,'input',2);
subplot(2,1,2),plot(x,mf);
xlabel('input 2 (pimf)');
writefis(fismat1,'fuzzyrule'); |
|