昌辉9 发表于 2014-9-3 11:10

请问这个代码错在哪里,如何进行修改,谢谢

clear
day=;
dayhistory=day(1:20);%取其中三十天作为历史数据样本
dayhismod=reshape(dayhistory,5,4);% 将历史数据分为6个样本,每个大小为5,其中reshape是以列排序的
dayday=day(1:15);% 取其中的前25天
daypost=day(6:20);%取其中的随后25天
p=reshape(dayday,3,5);% 将前25天数据分为5行5列矩阵作为网络的训练输入样本
t=reshape(daypost,3,5); %将随后的25天分为5行5列矩阵作为网络的目标输出向量
daylast=day(16:20);
h3=reshape(daylast,5,1);% 将倒数第二个样本作为网络测试时的输入样本
r=6:20;
rr=reshape(r,5,3);
%%%%%%%%%%%%%% 新建网络bp %%%%%%%%%%%%%%%%
net=newff(minmax(p),,{'purelin' 'purelin'},'trainlm');
y1=sim(net,p);
% 新建网络,其中minmax(p)为p的没一次输入的最大最小值向量
% 两层的传递函数均为purelin
% 训练函数为trainlm
% 所训练的网络大小为
% 仿真训练前的网络

%%%%%%%%%%%  进行网络训练  %%%%%%%%%%%%%%
% network parameters:
%   epochs--epochs of the train
%   goal--errors goal of the network
%   lr--learning rate
%   shows--epochs between the displays
%   time--Maximum time to train in seconds
net.trainParam.epochs=200000;  % 训练次数
nettrainParam.goal=0.0001;  % 误差期望值
% returns of the train:
%   net--New network
%    tr--Training record (epoch and perf).
%     Y--Network outputs.
%     E--Network errors.
=train(net,p,t);
%%%%%%%%%%%  网络测试 %%%%%%%%%%%%%%%%
% input the testing points here %
title('神经网络训练结果');
xlabel('时间(天)');
ylabel('仿真输出结果');
legend('仿真模拟值','实际值','神经网络预测值');
%%%%%%%%%%%%%%%%%%  绘制误差曲面 %%%%%%%%%%%%%
x=1:5;
y=1:5;
y21=sim(net,p);
y2=reshape(y21,1,15);
clf
plot(r,y2,'b-^')
hold on
plot(1:20,day,'r-*')
%%%%%%%%%%%%% 预测 %%%%%%%%%%%%%%%
y3=sim(net,h3);
plot(21:25,y3,'-*')
hold on
title('神经网络训练结果');
xlabel('时间(天)');
ylabel('仿真输出结果');
legend('仿真模拟值','实际值','神经网络预测值');
%%%%%%%%%%%%%%%%%%  绘制误差曲面 %%%%%%%%%%%%%
x=1:5;
y=1:5;
plot3(x,y,E(x,y))

madio 发表于 2014-9-3 11:10

是维数不一致造成的,我只能把代码调试的能运行,但是可能结果不一定对,你需要对前面的输入数据和网络结构做一些深入的了解clear
day=;
dayhistory=day(1:20);%取其中三十天作为历史数据样本
dayhismod=reshape(dayhistory,5,4);% 将历史数据分为6个样本,每个大小为5,其中reshape是以列排序的
dayday=day(1:15);% 取其中的前25天
daypost=day(6:20);%取其中的随后25天
p=reshape(dayday,3,5);% 将前25天数据分为5行5列矩阵作为网络的训练输入样本
t=reshape(daypost,3,5); %将随后的25天分为5行5列矩阵作为网络的目标输出向量
daylast=day(16:20);
h3=reshape(daylast,5,1);% 将倒数第二个样本作为网络测试时的输入样本
r=6:20;
rr=reshape(r,5,3);
%%%%%%%%%%%%%% 新建网络bp %%%%%%%%%%%%%%%%
net=newff(minmax(p),,{'purelin' 'purelin'},'trainlm');
y1=sim(net,p);
% 新建网络,其中minmax(p)为p的没一次输入的最大最小值向量
% 两层的传递函数均为purelin
% 训练函数为trainlm
% 所训练的网络大小为
% 仿真训练前的网络

%%%%%%%%%%%  进行网络训练  %%%%%%%%%%%%%%
% network parameters:
%   epochs--epochs of the train
%   goal--errors goal of the network
%   lr--learning rate
%   shows--epochs between the displays
%   time--Maximum time to train in seconds
net.trainParam.epochs=200000;  % 训练次数
nettrainParam.goal=0.0001;  % 误差期望值
% returns of the train:
%   net--New network
%    tr--Training record (epoch and perf).
%     Y--Network outputs.
%     E--Network errors.
=train(net,p,t);
%%%%%%%%%%%  网络测试 %%%%%%%%%%%%%%%%
% input the testing points here %
title('神经网络训练结果');
xlabel('时间(天)');
ylabel('仿真输出结果');
legend('仿真模拟值','实际值','神经网络预测值');
%%%%%%%%%%%%%%%%%%  绘制误差曲面 %%%%%%%%%%%%%
x=1:5;
y=1:5;
y21=sim(net,p);
y2=reshape(y21,1,15);
clf
plot(r,y2,'b-^')
hold on
plot(1:20,day,'r-*')
%%%%%%%%%%%%% 预测 %%%%%%%%%%%%%%%
y3=sim(net,h3);
plot(21:21,y3,'-*')
hold on
title('神经网络训练结果');
xlabel('时间(天)');
ylabel('仿真输出结果');
legend('仿真模拟值','实际值','神经网络预测值');
%%%%%%%%%%%%%%%%%%  绘制误差曲面 %%%%%%%%%%%%%
x=1:5;
y=1:5;
plot3(x(1:3),y(1:3),E(x(1:3),y(1:3)))
页: [1]
查看完整版本: 请问这个代码错在哪里,如何进行修改,谢谢