您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 管理学资料 > 用小波神经网络来对时间序列进行预测
/*Note:YourchoiceisCIDE*/#includestdio.hvoidmain(){}/*用小波神经网络来对时间序列进行预测*//*%Filename:nprogram.m%Description:Thisfilereadsthedatafrom%itssourceintotheirrespectivematricespriorto%performingwaveletdecomposition.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Clearcommandscreenandvariables*/clc;clear;/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%userdesiredresolutionlevel(Tested:resolution=2isbest)*/level=menu('Enterdesiredresolutionlevel:','1',...'2(Selectthisfortesting)','3','4');switchlevelcase1,resolution=1;case2,resolution=2;case3,resolution=3;case4,resolution=4;endmsg=['Resolutionleveltobeusedis',num2str(resolution)];disp(msg);/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%userdesiredamountofdatatouse*/data=menu('Chooseamountofdatatouse:','1day','2days','3days','4days',...'5days','6days','1week(Selectthisfortesting)');switchdatacase1,dataPoints=48;/*%1day=48points*/case2,dataPoints=96;/*%2days=96points*/case3,dataPoints=144;/*%3days=144points*/case4,dataPoints=192;/*%4days=192points*/case5,dataPoints=240;/*%5days=240points*/case6,dataPoints=288;/*%6days=288points*/case7,dataPoints=336;/*%1weeks=336points*/endmsg=['No.ofdatapointstobeusedis',num2str(dataPoints)];disp(msg);/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Menufordatasetselection*/select=menu('UseQLDdataof:','Jan02',...'Feb02','Mar02(Selectthisfortesting)','Apr02','May02');switchselectcase1,demandFile='DATA200601_QLD1';case2,demandFile='DATA200602_QLD1';case3,demandFile='DATA200603_QLD1';case4,demandFile='DATA200604_QLD1';case5,demandFile='DATA200605_QLD1';end/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%ReadingthehistoricalDEMANDdataintotDemandArray*/selectedDemandFile=[demandFile,'.csv'];[regionArray,sDateArray,tDemandArray,rrpArray,pTypeArray]...=textread(selectedDemandFile,'%s%q%f%f%s','headerlines',1,'delimiter',',');/*%Displayno.ofpointsintheselectedtimeseriesdemanddata*/[demandDataPoints,y]=size(tDemandArray);msg=['Theno.ofpointsintheselectedDemanddatais',num2str(demandDataPoints)];disp(msg);/*%Decomposehistoricaldemanddatasignal*/[dD,l]=swtmat(tDemandArray,resolution,'db2');approx=dD(resolution,:);/*%Plottheoriginaldemanddatasignal*/figure(1);subplot(resolution+2,1,1);plot(tDemandArray(1:dataPoints))legend('Demandoriginal');title('QLDDemandDataSignal');/*%Plottheapproximationdemanddatasignal*/fori=1:resolutionsubplot(resolution+2,1,i+1);plot(approx(1:dataPoints))legend('DemandApproximation');end/*%Afterdisplayingapproximationsignal,displaydetailx*/fori=1:resolutionif(i1)detail(i,:)=dD(i-1,:)-dD(i,:);elsedetail(i,:)=tDemandArray'-dD(1,:);endifi==1subplot(resolution+2,1,resolution-i+3);plot(detail(i,1:dataPoints))legendName=['DemandDetail',num2str(i)];legend(legendName);elsesubplot(resolution+2,1,resolution-i+3);plot(detail(i,1:dataPoints))legendName=['DemandDetail',num2str(i)];legend(legendName);endi=i+1;end/*%Normalisingapproximationdemanddata*/maxDemand=max(approx');%FindlargestcomponentnormDemand=approx./maxDemand;/*%Rightdivison*/maxDemandDetail=[];normDemandDetail=[,];detail=detail+4000;fori=1:resolutionmaxDemandDetail(i)=max(detail(i,:));normDemandDetail(i,:)=detail(i,:)./maxDemandDetail(i);end/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%ReadingthehistoricalhistoricalPRICEdataintorrpArray*/selectedPriceFile=[demandFile,'.csv'];[regionArray,sDateArray,tDemandArray,rrpArray,pTypeArray]...=textread(selectedDemandFile,'%s%q%f%f%s','headerlines',1,'delimiter',',');/*%Displayno.ofpointsinPricedata*/[noOfDataPoints,y]=size(rrpArray);msg=['Theno.ofpointsinPricedatadatais',num2str(noOfDataPoints)];disp(msg);/*%DecomposehistoricalPricedatasignal*/[dP,l]=swtmat(rrpArray,resolution,'db2');approxP=dP(resolution,:);/*%PlottheoriginalPricedatasignal*/figure(2);subplot(resolution+3,1,1);plot(rrpArray(2:dataPoints))legend('Priceoriginal');title('PriceDataSignal');/*%PlottheapproximationPricedatasignal*/fori=1:resolutionsubplot(resolution+3,1,i+1);plot(approxP(2:dataPoints))legend('PriceApproximation');end/*%Afterdisplayingapproximationsignal,displaydetailx*/fori=1:resolutionif(i1)detailP(i,:)=dP(i-1,:)-dP(i,:);elsedetailP(i,:)=rrpArray'-dP(1,:);endifi==1[B,A]=butter(1,0.65,'low');result=filter(B,A,detailP(i,1:dataPoints));subplot(resolution+3,1,resolution-i+4);plot(result(i,2:dataPoints))legendName=['lowpassfilter',num2str(i)];legend(legendName);subplot(resolution+3,1,resolution-i+3);plot(detailP(i,2:dataPoints))legendName=['PriceDetail',num2str(i)];legend(legendName);elsesubplot(resolution+3,1,resolution-i+3);plot(detailP(i,2:dataPoints))legendName=['PriceDetail',num2str(i)];legend(legendName);endi=i+1;end/*%NormalisingapproximationPricedata*/maxPrice=max(approxP');%FindlargestcomponentnormPrice=approxP./maxPrice;/*%Rightdivison*/maxPriceDetail=[];normPriceDetail=[,];detailP=detailP+40;fori=1:resolutionmaxPriceDetail(i)=max(detailP(i,:));normPriceDetail(i,:)=detailP(i,:)./maxPriceDetail(i);end/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Functionhereallowsrepetitiveoptionsto,%1)CreatenewNNs,2)RetraintheexistingNNs,%3)Perfo
本文标题:用小波神经网络来对时间序列进行预测
链接地址:https://www.777doc.com/doc-4822620 .html