大家好,求助!
手头有一个大致以天为周期的小时数据,共4000个数据。
我想做一个实验,用前面的2400个数据建立一个网络,在这个网络内第1~12个数据预测出第13个数据,
第2~13个数据预测出第14个数据。。。
最后希望基于这个网络,利用第2389~2400个数据来预测第2401个数据。
然后如此循环建立网络,预测2402, 2403, 。。。的过程。
但是现在得到的结果总是没有体现出预测来,如附图所示,蓝线是原始值,红线是这样的网络预测值,绿线是将这个预测值的线向左移动一下得到的。
求大侠指点应该如何修改?
源程序如下
%%%%% load the data and forecast
%%%%% it's not working.....
warning('off'); %#ok<WNOFF>
close all
clear
clc
load ttt
strip=12;
lenth=strip*200;
times=20;
err=zeros(times,strip);
rec_t=zeros(times,strip);
rec_tf=zeros(times,strip);
for time=1:times
msg = sprintf('forecasting iteration %g/%g...\n',time,times);
fprintf('%s',msg);
signal=ttt(time:time+lenth-1); %%% lenth
%%%% strip data to predict 'strip+1' point
in=zeros(strip,lenth-strip);
for i=1: (lenth-strip)
in(:,i)=signal(i:i+strip-1);
end
tgt=signal(strip+1:lenth);
in_f=signal(lenth-strip+1:lenth);
in_f=reshape(in_f,strip,1);
%%%%%%%%%%%%%% network %%%%%%%%%%%%%%%%
net=newff(minmax(in),[strip*4,1],{'purelin','purelin'},'trainlm');
net.trainParam.epochs=1000; %
nettrainParam.goal=0.001; %
[net,tr,Y,E]=train(net,in,tgt);
% % %%%%%%%%%%% chek the network %%%%%%%%%%%%%%%%
% % out=sim(net,in);
% % figure
% % plot(reshape(tgt,1,strip*(cnt_strip-1)),'r-*');
% % hold on
% % plot(reshape(out,1,strip*(cnt_strip-1)),'b-d');
% % legend('orignal','net(in)');
% %%%%%%%%%%%%% prediction %%%%%%%%%%%%%%%
out_f=sim(net,in_f);
%%%%%% record the series
rec_t(time,1)=ttt(time+lenth);
rec_tf(time,1)=out_f;
err(time,1)=rec_tf(time,1)-rec_t(time,1);
end
figure;
plot(lenth+1:lenth+times,rec_t(:,1),'b-*');
hold on
plot(lenth+1:lenth+times,rec_tf(:,1),'r');
hold on
plot(lenth:lenth+times-1,rec_tf(:,1),'g-o');
legend('orignal','prediction','left-shifted');
title(strcat('pred == ',num2str(1,'%2.2d')));
![如何人工神经网络来预测下一个数值???]()
untitled.jpg![如何人工神经网络来预测下一个数值???-1]()
untitled.jpg
[ Last edited by gohomeba on 2014-3-6 at 10:04 ] |