高级会员
- 积分
- 609
- 威望
- 415
- 贡献
- 158
- 兑换币
- 10
- 注册时间
- 2012-5-30
- 在线时间
- 18 小时
|
clc
clear all
close all
aa=xlsread('sy1.xls');
at=[{'日期:2005-6-30至2006-12-1'},{'开盘价'},{'成交量'},{'最高价'},{'最低价'},{'收盘价'}];
ys='brgmcyk';
pd=aa(1:330,';
[pn,minp,maxp]=premnmx(pd);
pr=[pn(:,1:320);pn(:,2:321);pn(:,3:322);pn(:,4:323);pn(:,5:324)];
% px=[pn(:,1:300);pn(:,2:301);pn(:,3:302);pn(:,4:303);pn(:,5:304)];
px=pr(:,1:300);
py=pn(5,6:305);
pX=pr(:,301:320)
pY=pd(5,306:325); %pn(5,306:325);
net1=newff(minmax(px),[16,1],{'tansig','purelin'},'trainlm'); %{'tansig','logsig'},'traingdx'); {'logsig','purelin'}
net1.trainParam.show=1;
net1.trainParam.epochs=2000;
net1.trainParam.goal=0.001;
net1.trainParam.max_fail=5;
net1=init(net1);
[net1,tr,Y,E]=train(net1,px,py);
s=sim(net1,px);
er=py-s;
figure
plot(py,'b');
hold on
plot(s,'r*');
title('神经网络训练图');
pp=sim(net1,pX);
legend('实际目标值','网络拟合值',2);
% pp=pp+0.015*pp.*randn(1,length(pp)); %加噪声
disp('实际值')
pY
disp('预测值')
pp=minp(5)+(maxp(5)-minp(5))*(pp+1)/2
disp('预测产生的误差')
pY-pp
figure;
plot(pY,'g-');
hold on
plot(pp,'m*');
title('神经网络预测图');
legend('实际目标值','预测值',2)
figure;
plot(er,'m');
title('神经网络训练误差曲线');
|
|