查看: 86|回复: 2|关注: 0

[未答复] anfis多输入训练后反预测误差很大

[复制链接]

新手

5 麦片

财富积分


050


1

主题

7

帖子

0

最佳答案
发表于 6 天前 | 显示全部楼层 |阅读模式
老师让我做一个故障诊断的anfis,一般输入数据比较多,没有数据,随便在网上找了一个例子的数据,参照例子用了genfis1,有10个输入值,结果隶属度函数哪怕选2规则数都大的不得了,于是我选了先算6个输入。
请教老师,老师又让我用genfis2 减法聚类,用了之后确实10个输入也能算,老师又让我做对比(我就很奇怪第一个都运行不了全数据怎么做对比……)
用genfis生成fis,再用anfis训练,用evalfis输出。
最后我想用chkdata的数据反带回去用evalfis(chkdata,infis(或者用outfis))输出,结果误差特别大。
我想问问:一般做故障诊断是用这种我这种evalfis(data,infis)输出的吗?
我去网上查,有人也用genfis1还有genfis2做但是阶梯输出误差也很大,这种方法输出阶梯数据可以实现吗?我该怎么优化呢?
还有outfis和infis到底有什么区别呢?为什么我用infis和oufis输出结果差这么多,参考例子上训练单一函数时,用两个输出差别并不是很大……
我很迷惑,希望有大佬能指导我一下,或者做相似问题的小伙伴互相交流一下。

以下是我的程序,第一次接触matlab就搞神经网络问题很多,感谢大佬指教



clear all;
%%
A=[0.790000000000000,30.4000000000000,38.9000000000000,19.9000000000000,0.310000000000000,1502,8.20000000000000,77.8000000000000,0.550000000000000,120.700000000000,1;
    0.590000000000000,29.5000000000000,36.5000000000000,22.3000000000000,0.470000000000000,1443,5.20000000000000,90.1000000000000,0.700000000000000,99.2000000000000,1;
    0.610000000000000,30.1000000000000,39.1000000000000,21.5000000000000,0.250000000000000,1492,7.60000000000000,78.2000000000000,0.630000000000000,100.500000000000,1;
    0.630000000000000,25.2000000000000,40.2000000000000,20.3000000000000,0.280000000000000,1434,7.70000000000000,82.5000000000000,0.700000000000000,144.200000000000,1;
    0.710000000000000,28.2000000000000,36.4000000000000,28.9000000000000,0.0100000000000000,1477,7.90000000000000,79.9000000000000,0.470000000000000,100.900000000000,2;
    0.680000000000000,30.2000000000000,40.1000000000000,21.6000000000000,0.170000000000000,1479,5.90000000000000,81.8000000000000,0.660000000000000,119.500000000000,2;
    0.670000000000000,28.1000000000000,42.5000000000000,36.2000000000000,0.0900000000000000,1520,8.90000000000000,81.9000000000000,0.700000000000000,119.200000000000,2;
    0.710000000000000,27.2000000000000,45.6000000000000,31.9000000000000,0.220000000000000,1499,5.60000000000000,85.1000000000000,0.590000000000000,100.900000000000,2;
    0.560000000000000,28.4000000000000,39.2000000000000,34.5000000000000,0.250000000000000,1364,11.1000000000000,86.2000000000000,0.320000000000000,111.900000000000,3;
    0.770000000000000,23.1000000000000,42.7000000000000,36.9000000000000,0.280000000000000,1404,7.90000000000000,99.6000000000000,0.270000000000000,121.200000000000,3;
    0.710000000000000,26.5000000000000,36.2000000000000,31.2000000000000,0.210000000000000,1461,13.2000000000000,83.2000000000000,0.470000000000000,116.900000000000,3;
    0.660000000000000,29.2000000000000,43.7000000000000,33.4000000000000,0.280000000000000,1388,7.20000000000000,96.5000000000000,0.500000000000000,102.100000000000,3;
    0.400000000000000,17.2000000000000,35.9000000000000,26.4000000000000,0.270000000000000,1321,9.40000000000000,79.2000000000000,0.610000000000000,115.200000000000,4;
    0.390000000000000,19.7000000000000,36.2000000000000,27.2000000000000,0.360000000000000,1206,15.1000000000000,86.2000000000000,0.580000000000000,119.700000000000,4;
    0.410000000000000,16.5000000000000,36.4000000000000,21.6000000000000,0.310000000000000,1362,6.70000000000000,78.9000000000000,0.620000000000000,130.900000000000,4;
    0.390000000000000,26.7000000000000,39.2000000000000,17.3000000000000,0.410000000000000,1476,16.2000000000000,95.6000000000000,0.370000000000000,150.900000000000,4;
    0.400000000000000,17.1000000000000,37.1000000000000,25.2000000000000,0.220000000000000,1261,15.9000000000000,97.2000000000000,0.440000000000000,143.200000000000,5;
    0.310000000000000,19.2000000000000,36.9000000000000,19.1000000000000,0.230000000000000,1430,13.2000000000000,93.4000000000000,0.390000000000000,151.100000000000,5;
    0.560000000000000,20.4000000000000,39.5000000000000,23.5000000000000,0.230000000000000,1179,13.5000000000000,99.1000000000000,0.330000000000000,150.300000000000,5;
    0.440000000000000,19.6000000000000,34.6000000000000,21.2000000000000,0.210000000000000,1501,16.7000000000000,94.2000000000000,0.390000000000000,109.200000000000,5;
    0.690000000000000,28.4000000000000,34.9000000000000,19.3000000000000,0.320000000000000,1442,6.20000000000000,67.8000000000000,0.650000000000000,110.700000000000,1;
    0.590000000000000,30.1000000000000,36.5000000000000,22.3000000000000,0.250000000000000,1492,7.60000000000000,90.1000000000000,0.630000000000000,99.2000000000000,1;
    0.520000000000000,28.1000000000000,40.1000000000000,23.6000000000000,0.0900000000000000,1479,8.90000000000000,81.8000000000000,0.660000000000000,117.200000000000,2;
    0.430000000000000,27.2000000000000,45.6000000000000,31.9000000000000,0.180000000000000,1499,5.60000000000000,93.2000000000000,0.690000000000000,121.200000000000,2;
    0.400000000000000,30.4000000000000,36.2000000000000,27.2000000000000,0.270000000000000,1479,13.2000000000000,94.2000000000000,0.440000000000000,150.300000000000,3;
    0.390000000000000,29.2000000000000,43.7000000000000,21.6000000000000,0.360000000000000,1501,7.20000000000000,99.1000000000000,0.390000000000000,109.200000000000,3;
    0.400000000000000,19.7000000000000,37.1000000000000,21.2000000000000,0.210000000000000,1206,16.7000000000000,79.2000000000000,0.610000000000000,116.900000000000,4;
    0.310000000000000,16.5000000000000,36.9000000000000,18.5000000000000,0.230000000000000,1262,13.5000000000000,86.2000000000000,0.580000000000000,102.100000000000,4;
    0.510000000000000,17.2000000000000,34.5000000000000,26.5000000000000,0.260000000000000,1301,6.80000000000000,77.9000000000000,0.710000000000000,99.8000000000000,5;
    0.430000000000000,13.9000000000000,31.9000000000000,23.1000000000000,0.310000000000000,1293,8.10000000000000,81.6000000000000,0.660000000000000,106.100000000000,5];



%载入数据并编辑数据

%导入原数据
%先是trnData
[m1,n1]=size(A);
x0=A(1:20,1:n1-1);  %前nl-1列为输入数据
y0=A(1:20,n1);    %第n1列为输出数据

%数据归一化
x1=x0';  % 按行归一化,先转置
x2=mapminmax(x1,0,1);  %归一化到 0--1,
x3=x2';

y1=y0';
y2=mapminmax(y1,0,1);
y3=y2';

trnData=[x3,y0];
[m2,n2]=size(trnData);
%chkData=[x3(21:30,:),y0(21:30,:)];


Xin=trnData(1:20,1:n1-1);
Xout=trnData(1:20,n1);
% for epoch_n=20:10:200
%%
%或者用于测试的数据单独归一化处理  
%提取
data=A(21:30,:);
X=data(:,1:n1-1);%输入
Y=data(:,n1);%输出
X1=X';
X2=mapminmax(X1,0,1);
X3=X2';
chkData0=[X3,Y];
[m3,n3]=size(chkData0);
    %针对21到30组数据进行归一化

%思路2,换:把anfis
%训练时用的chkdata也换成单独处理的数据,试试看5号故障能不能正常判断。验证了,结果是前几组数据结果变好了,但是第45组还是问题很大
%结果,修改为chkdata 和trndata数据分开归一化


%%
%用genfis1
st1=cputime;                                   %开始计算时间
s=6;                                          %输入数据个数

trnData1=trnData(:,[1:s,n1]);
%chkData1=chkData(:,[1:s,n1]);
chkData00=chkData0(:,[1:s,n1]);
numMFs=2;                                      %隶属度个数
mfType = 'gauss2mf';   
%隶属函数
epoch_n1=200;                                    %训练步数
in_fis1 = genfis1(trnData1,numMFs,mfType);      %生成fis

[in_fis11,trnErr1,ss,out_fis1,chkErr1]=anfis(trnData1,in_fis1,epoch_n1,[],chkData00);%训练fis
%in_fis11=anfis(trnData1,in_fis1,epoch_n1);
yout11=evalfis(trnData1(:,1:s),in_fis11);               %输出
yout12=evalfis(trnData1(:,1:s),out_fis1);
error1=Xout-yout11;    %误差

infor1=getfis(in_fis11);%记得最后输出对比


%输出图像
figure(1)
title('genfis1训练后的图像');
subplot(2,1,1);
plot(1:m2,Xout,'bo',1:m2,yout11,'r*',1:m2,yout12,'g+');
legend('Training Data','ANFIS1 Output','ANFIS2 Output');
xlabel('样本数');
ylabel('目标值');

subplot(2,1,2);
plot(1:m2,error1,'r-');
xlabel('样本数');
ylabel('偏差值');

etime1=cputime-st1;                              %计算运行时间
etime1                                           %记得最后输出


%测试此程序的准确度                           

%out1=evalfis(chkData1(:,1:s),in_fis11);
out1=evalfis(X3(:,1:s),in_fis11);
out11=evalfis(X3(:,1:s),out_fis1);

e1=chkData0(:,n1)-out1;
e11=chkData0(:,n1)-out11;


%%
%用genfis2
st2=cputime;   
epoch_n2=200;

in_fis2= genfis2(Xin,Xout,0.5);
[in_fis21,trnErr2,ss,out_fis2,chkErr2]=anfis(trnData,in_fis2,epoch_n2,[],chkData0);
%in_fis21=anfis(trnData,in_fis2,epoch_n2);
yout21=evalfis(Xin,in_fis2);
yout22=evalfis(Xin,out_fis2);
error2=Xout-yout21;

infor2=getfis(in_fis21);                %记得最后和1输出对比

figure(2)
title('genfis2训练后的图像');
subplot(2,1,1);
plot(1:m2,Xout,'bo',1:m2,yout21,'r*',1:m2,yout22,'g+');
legend('Training Data','ANFIS1 Output','ANFIS2 Output');
xlabel('样本数');
ylabel('目标值');

subplot(2,1,2);
plot(1:m2,error2,'r-');
xlabel('样本数');
ylabel('偏差值');

etime2=cputime-st2;                             %记得最后输出
%测试此程序的准确度                           

%out2=evalfis(chkData(:,1:n1-1),in_fis21);
out2=evalfis(X3,in_fis21);
out22=evalfis(X3,out_fis2);
e2=chkData0(:,n1)-out2;
e22=chkData0(:,n1)-out22;
%%
%输出对比图像,信息等。
infor1
infor2    %输出规则输入输出
etime1
etime2    %输出运行时间(实际上genfis1并不能完全运行运行时间成指数增长)

figure(3)                 %此图为验证对比图,还是输出误差特别大,记得把anfis的文献发给老师,问一问
subplot(2,2,1);
title('genfis1实验验证输出对比');
plot(1:m3,chkData0(:,n1),'r*',1:m3,out1,'cx',1:m3,out11,'k+');
legend('检验数据实际输出','genfis1测试输出','用out的输出数据');
xlabel('样本数');
ylabel('目标值');

subplot(2,2,3);
title('genfis1实验误差');
plot(1:m3,e1,1:m3,e11);
legend('infis输出','outfis输出');
xlabel('样本数');
ylabel('genfis1偏差值');

subplot(2,2,2);
title('genfis2实验验证输出对比');
plot(1:m3,chkData0(:,n1),'r*',1:m3,out2,'cx',1:m3,out22,'k+');
legend('检验数据实际输出','genfis2测试输出','用out输出的数据');
xlabel('样本数');
ylabel('目标值');

subplot(2,2,4);
title('genfis2实验误差');
plot(1:m3,e2,1:m3,e22);
legend('infis输出','Outfis输出');
xlabel('样本数');
ylabel('genfis2偏差值');

figure(4)                         %此图为训练误差随步数变化,并没有出现随步数增加误差减小的情况,记得请教老师
subplot(2,1,1);
plot(1:epoch_n1,trnErr1,'r+',1:epoch_n1,chkErr1,'bo')
title('genfis1随步数误差');
xlabel('训练次数');
ylabel('误差大小');

subplot(2,1,2);
plot(1:epoch_n2,trnErr2,'r+',1:epoch_n2,chkErr2,'bo')
title('genfis2随步数误差');
xlabel('训练次数');
ylabel('误差大小');



QQ图片20200323001555.png
QQ图片20200323001548.png

新手

5 麦片

财富积分


050


1

主题

7

帖子

0

最佳答案
 楼主| 发表于 3 天前 | 显示全部楼层
完了,可能整个论坛没啥人用genfis2吧,我实在是不会了 ……哎

新手

5 麦片

财富积分


050


1

主题

7

帖子

0

最佳答案
 楼主| 发表于 3 天前 | 显示全部楼层
刚才搞了搞,也把论坛里所有关于anfis,genfis的帖子看了一遍,问题解决不了,一直懵懵的,我就把我所有问题都写下来吧。
一开始是老师安排我用anfis,做柴油机故障诊断,我一开始用工具箱,但是工具箱还没做完,老师就说,用工具箱太敷衍了,让我用工具箱函数,于是我就踏上了天天难受的漫漫不归路。
首先,无论是论文参考还是帮助,现成的例子,对于单输出,所有输入个数不超过4个,于是用genfis1都可以完美运行。但是我拿到我的数据,都是10个输入甚至20个输入参数,我甚至分析不出来参数之间的关系,用genfis1生成fis,再用anfis肯定是运行不了的,规则量太大了。
然后我就去查帮助,英文有人回复,输入量超过6个一般就不能用genfis1了,要用genfis2

那些参考论文,文献里写了10组8组输入数据的都是怎么实现的呢,好想请教一下啊,为啥我10组数据genfis规则就过大呢

于是我把数据归一化,用genfis2生成,再用anfis训练,用evalfis做预测输出,结果预测,也就是诊断,并不精准。
问了老师,老师也说不出个123456,现在正在学主元分析法,看能不能精简数据。
可是我看主元分析法也很困难,太头疼了,

今天试了试在genfis2函数那修改了一下
in_fis2= genfis2(Xin,Xout,[0.8 0.8 1 0.3 0.3 0.3  1  1 0.8 1 1]);
应该是修改了聚类中心范围吧,使误差小了点。
输出图像看来
最起码1 2 3 4 种误差能诊断的差不多了,但是第五种误差还是诊断成第4种。
脑袋疼。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐上一条 /4 下一条

快速回复 返回顶部 返回列表