% _________________
% 回归神经网络
% _________________
clear all
close all
clc
[file1,path1]=uigetfile('*.*','打开数据文件');
filename1=strcat(path1,file1);
fid1=fopen(filename1,'r');
prompt={'除Y外的列数','样本总数','取其中用于拟合的样本个数'};
def={'6','45','40'};
lineNo=1;
dlgTitle='数据参数输入:';
answer=inputdlg(prompt,dlgTitle,lineNo,def);
answer=char(answer);
ny=str2num(answer(1,:));
nx=str2num(answer(2,:));
it=str2num(answer(3,:));
gx=1;
[file2,path2]=uiputfile('*.*','请选择要保存结果的文件夹名');
filename2=strcat(path2,file2);
fid2=fopen(filename2,'w');
AA=fscanf(fid1,'%f');
BB=reshape(AA,ny+1,nx)';
[px,py]=size(BB);
fprintf(fid2,'****############******************#############****\n');
fprintf(fid2,'******#######################原始数据得结果距阵#######################################******\n');
for i=1:nx
for j=1:ny+gx
fprintf(fid2,'%12.2f',BB(i,j));
end
fprintf(fid2,'\n');
end
sw1w=it;
for TGB=1:(nx-sw1w);
BB1=BB(1:it,1:ny);
BB2=BB(1:it,ny+1:ny+gx);
BB3=BB(it+1,1:ny);
BB4=BB(it+1,ny+1:ny+gx);
Y1=BB2;
Y2=BB4;
xx=[BB1;BB3];
[pn,ps]=mapminmax(xx');
[t1,ts]=mapminmax(Y1');
p1=pn(:,1:it);
p2=pn(:,1+it);
E0=3;
net=newgrnn(p1,t1,E0);
y1=sim(net,p1);
y2=sim(net,p2);
%%预报量还原原来的数量级
Yfr1=mapminmax('reverse',y1,ts)';
Yfr2=mapminmax('reverse',y2,ts)';
%---------------
rejust1=[Y1,Yfr1,abs(Y1-Yfr1),abs(Y1-Yfr1)./Y1];
W1WSD1(TGB,:)=mean(rejust1);
rejust2=[Y2,Yfr2,(Y2-Yfr2),abs(Y2-Yfr2)./Y2];
W2WSD(TGB,:)=rejust2;
it=it+1
close all
end
[pow1,pow2]=size(W1WSD1);
fprintf(fid2,'***************************************拟合值****************************************************************\n');
fprintf(fid2,'**(原始值平均值) (拟合值平均值) (误差) (相对误差) **\n');
for i=1:pow1
for j=1:pow2
fprintf(fid2,'%14.5f',W1WSD1(i,j));
end
fprintf(fid2,'\n');
end
fprintf(fid2,'\n');
[pow3,pow4]=size(W2WSD);
fprintf(fid2,'****************************************预测值***************************************************************\n');
fprintf(fid2,'**(原始值) (预测值) (误差) (相对误差) **\n');
for i=1:pow3
for j=1:pow4
fprintf(fid2,'%14.5f',W2WSD(i,j));
end
fprintf(fid2,'\n');
end
ASDWQ=mean(abs(W2WSD(1:TGB,:)));
[pow5,pow6]=size(ASDWQ);
fprintf(fid2,'\n');
fprintf(fid2,'********************************************平均值*******************************************\n')
for i=1:pow5
for j=1:pow6
fprintf(fid2,'%14.5f',ASDWQ(i,j));
end
fprintf(fid2,'\n');
end
fprintf(fid2,'\n');
fprintf(fid2,'\n');
fclose(fid1);
fclose(fid2);
评论0