📄 fuzzyts.m
字号:
%Takagi-Sugeno Fuzzy Inference System (no delay)(add y(k-1))
clear;
load average22.txt;%yhl826.txt;
a=average22;%yhl826;
a1=(a(:,5)+a(:,6)+a(:,7))/3;
a2=(a(:,8)+a(:,9)+a(:,10))/3;
a3=(a(:,11)+a(:,12)+a(:,13))/3;
b=[a1 a2 a3];
yhl=[a(:,1:4) b a(:,14:22)];
P=yhl(:,1:15);
T1=yhl(:,16);
X=P;
Y=T1;
exty=zeros(300,1);
exty(1)=0;
for i=2:300
exty(i)=T1(i-1);
end
[Xn,minX,maxX,Yn,minY,maxY] = premnmx(P',T1');%P'and T',not P and T in order that
%columns of P' and T' is consistent
[mX,nX]=size(X);
[mY,nY]=size(Y);
nTest=100;
Xn1=Xn(:,1:(mX-nTest));%train patterns
Xn2=Xn(:,(mX-nTest+1):mX);%test patterns
Yn1=Yn(:,1:(mX-nTest));
Yn2=Yn(:,(mX-nTest+1):mX);
exty1=exty(1:mX-nTest,:);
exty2=exty((mX-nTest+1):mX,:);
Y1=Y(1:(mX-nTest),:);
Y2=Y((mX-nTest+1):mX,:);
%process of data
[T,P,W] = pca(Xn',5);
t1=T';
y1=Y';
[tn,mint,maxt,yn,miny,maxy] = premnmx(t1,y1);
tn1=tn(:,1:(mX-nTest));
tn2=tn(:,(mX-nTest+1):mX);
yn1=yn(:,1:(mX-nTest));
yn2=yn(:,(mX-nTest+1):mX);
%Train and test of the fuzzy model
trnData=[tn1' exty1 yn1'];%6 columns
mf_n=2;
mf_type='gbellmf';
%generate the structure of the fuzzy inference system
fis1=genfis1(trnData,mf_n,mf_type);
%option of training
epoch=40;
errorgoal=0.1;
step=0.01;
trnOpt=[epoch errorgoal step NaN NaN];
dispOpt=[1 1 1 1];
chkData=[tn2' exty2 yn2'];
optMethod=1;
%train the fuzzy inference system
st = cputime;%the computation time of start
[fis2,error,st,fis3,e2]=anfis(trnData,fis1,trnOpt,dispOpt,chkData,optMethod);
fprintf('Execution time : %20.19f seconds\n',cputime - st);
%checking the performance of the fuzzy inference system
x=trnData(:,1:6);
y=evalfis(x,fis2);
Yb1 = postmnmx(y,miny,maxy);
figure;
ct=1:1:(mX-nTest);
plot(ct,Y1','b:',ct,Yb1,'r-');
legend('Analysis value','Fuzzy model output');
xlabel('Sample No.');
ylabel('Value');
disp('training Error is:');
%compute RMSE
RMSE1=sqrt(sumsqr(Y1-Yb1)/(size(Yn1,2)))
%training result
x_new=chkData(:,1:6); %linspace(-1,1,newdata_n)';
y_new=evalfis(x_new,fis2);
Yb2 = postmnmx(y_new,miny,maxy);
disp('testing Error is:');
RMSE2=sqrt(sumsqr(Y2-Yb2)/(size(Yn2,2)))
figure;
ct=(mX-nTest+1):1:mX;
%axis([200,300,0.4,0.6]);
%axis([100,200,0.3,0.8]);
plot(ct,Y2','b:',ct,Yb2,'r-');
legend('Analysis value','Fuzzy model output');
xlabel('Sample No.');
ylabel('Value');
%plot the block of the fuzzy inference system
%figure;
%plotfis(fis1);
%show the fuzzy rules
%showrule(fis1)
%show the result of fis
%showfis(fis2);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -