如何通过神经网络进行预测?

36次观看(最近30天)
Goryn
Goryn 2011年6月14日
Commented: 埃里克2016年3月18日
我正在使用MATLAB R2011A。我试图通过神经网预测下一个100点的时间表X。首先,我创建输入时间序列XTRA和反馈时间序列YTRA:
lag = 50;
Xu = windowize(X,1:lag+1);%Re-arrange the data points into a Hankel matrix
Xtra = Xu(:,1:lag);%输入时间序列
Ytra = Xu(:,end);%feedback time series
然后,我使用此守则训练神经网:
inputSeries = tonndata(Xtra,false,false);
targetSeries = tonndata(Ytra,false,false);
%创建具有外部输入的非线性自回旋网络
inputDelays = 1:2;
feedbackDelays = 1:2;
hiddenlayersize = 10;
net = narxnet(inputDelays,feffbackDelays,sideenlayerSize);
%准备培训和模拟的数据
[输入,inputstates,layerstates,targets] = preparets(net,inputseries,{},targetSeries);
百分比设置数据分区用于培训,验证,测试
net.divideparam.trainratio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideparam.testratio = 15/100;
% Train the Network
[net,tr] = train(net,输入,目标,输入states,layerstates);
%测试网络
outputs = net(inputs,inputStates,layerStates);
错误= gsubtract(目标,输出);
performance = perform(net,targets,outputs)
然后,我想预测我最初的时间表的下一个100点,我该怎么办?
Thanks in advance for your answers.

接受的答案

格雷格·希思
格雷格·希思 2014年10月22日
0.不正确使用“滞后”一词
1. It is rare that the default input parameters (ID,FD,H) are sufficient. They can be improved by using a subset of significant lags determined from the auto and cross-correlation functions and then searching over a range of H values. The smallest acceptable value of H should be used.
2.应覆盖默认的“ dividerand”(例如,'divideBlock'),以优化1中发现的显着相关性滞后的有效性。
3. Train using the syntax
[net tr ys es xf af] = train(net,xs,ts,xi,ai);
将XF和AF用作延续数据的Intial条件
4.关闭循环后,测试的CL净original data. If performance is not good compared to the OL performance, train the CL net beginning with the weights obtained with the OL training.
5.由于您只有1个系列,因此您应该使用Narnet。继续超越原始数据
Xnew = net(NaN(1,100),Xf,Af);
希望这可以帮助
格雷格
1 Comment
埃里克
埃里克 2016年3月18日
你好,格雷格!关于您的上述答案...
拜托,您能像在(3)中为火车上写下准备书的语法吗?
我想使用narnet来预测超越原始数据的价格。
喜欢尝试您的方法:Xnew = net(Nan(1,100),XF,AF);
Thanks!

登录发表评论。

更多答案(6)

Mark Hudson Beale
Mark Hudson Beale 2011年6月14日
You can convert the NARXNET from open-loop to closed-loop form to predict ahead any number of timesteps for which you have data for your input time series.
如果您想预测n个步骤,那么:
%定义n+2个输入时间段
xtra_predict = {...};
%定义n+2反馈值,但只有前2个需要
% defined, the rest can be NaN (i.e. unknown) values. The N unknown
%值将是网络将做出的n个预测。你可以
%使用YTRA的最后两个值,如果您想直接做出预测
% after your training data sereies.
ttra_predict = {...}
netCL = closeloop(net);
[x,xi,ai,t] = preparets(net,xtra_predict,{},ttra_predict);
y = sim(net,x,xi,ai)
After this code is run, y will now have N preditions based on the input series Xtra_predict and the initial two steps of Ttra_predict.

杰克
杰克 2011年9月4日
大家好,
I have the same problem and looked everwhere to find an answer ... :-((
您如何在此处定义n+2个时间段的输入时间?代码会是什么样?
Xtra_predict = ?????????
ttra_predict = ???????????
非常感谢 !

贾斯汀
贾斯汀 2011年11月2日
看来可以做到这一点,我已经研究了几个星期,尽管似乎有一些有趣的答复,但在应用中,它们总是遇到与输入数量有关的错误网络。

Cristhiano Moreno
Cristhiano Moreno 上5 Nov 2011
我该如何使用NAR网络进行操作?我有一个带有99个值的时间意甲,我想预测100个值。最后绘制了这个2系列y相同的图。
Somebody can help me ?

Vito
Vito 上5 Nov 2011
Let's play game. We throw a coin and we try to guess what side it has fallen. Certainly we don't know, and mathematical expectation = 0.5.
But after 10 throws we can count real mathematical expectation for this game. In due course, we will get used to this coin and we can guess to (predict).
在网络上,相同的原则。她能记住所有游戏的主要优势。因此,我们可以在某些时间间隔中从实际的实际时间获得预期价值的依赖性。
Let's create the elementary linear network.
延迟= [0 1 2 3 4 5];
pi = {1 2 3 4 5};
net = newlin ([0 1], 1, delays);
随机变量。
GamVar = randsample ([0,1], 1, true, [.7,.3]);% one random variable
Also we will play 100 batches on 10 throws.
delays = [0 1 2 3 4 5 ];
pi ={1 2 3 4 5 };
net = newlin([0 1],1,延迟);
s = [];
s = 1;
t = 1;
Me=[];
time=1;
步骤= 1;
gamvar = randsample([[0,1],1,true,[。7,.3]);% one random variable
t = con2seq([[gamvar]);
P = T;
TM = con2seq(median(cat(2,T{:})));
%
奖品= 0;
formm=1:100
%---------------------
hold
C = 0;
y=[];
ifmm == 1
t = {mean(cat(2,t {:}))};
me = t;
P=T;
tm = t;
pm = tm;
else%加入平均值
T={mean([cat(2,T{:}) Me{:}])};
me = t;
P=T;
tm = t;
pm = tm;
end
gamvar =(randsample([0,1],10,true,[。7,.3]));% one random variable
fori = 1:10
GamVarT{i}=GamVar(i);
T{i} = GamVar(i);
P = T;
if我> 1
tm = {t {1:i-1}均值(cat(2,tm {1:i-1}))}};
else
TM{i}=mean(cat(2,TM{:}));
end
pm = tm;
y = sim(net,pm,pi);
% correction
if任何([[(圆形(cat(2,y {1:i})))〜= cat(2,gamvart {1:i})])
tm = t;
%在输入中 - 平均值,输出 - 实际值
[net,y,e]=adapt(net,PM,TM,pi);
plot(i,round(double(y{i})),'or','行宽',2,“标记”,10);
C = C+1;
end
时间=时间+1;
plot(1:size(PM,2),round(double(cat(2,y{:}))),'o--',1:大小(P,2),CAT(2,T {:}),'-*');
Xlabel('Time');
axis([0 i -4 4]);
drawnow
if〜strcmp(get(get(0,'CurrentFigure'),'SelectionType'),'normal')
disp('stop')
break
end
end
disp(“计算错误预测”)
c
disp('Relation error predaction / All samples')
(c/i)*100
s(s)=(c/i)*100;
s=s+1;
方法)
if〜strcmp(get(get(0,'CurrentFigure'),'SelectionType'),'normal')
disp('stop')
break
end
close全部
disp('奖')
Prize= Prize+(10-c)-c
步骤=步骤+10;
end
我们受益!如果我们再次参加比赛,得分就会增加。
这个非常简单的示例表明,可以在很长的时间间隔内预测。其他网络和其他调整允许取得最好的结果。祝你好运。版本7.2的代码。
2 Comments
穆罕默德·哈斯纳特(Muhammad Hasnat)
我不了解与所要求的内容和这个游戏的任何关系。

登录发表评论。


Vito
Vito 2011年11月7日
感谢。:)只显示了一般原则。或一种变体。创建神经系统,以前的艺术。还倾向于创造性的方法。在准确的形式化之前,它仍然很远。您可能会做出决定。
因此,这样的主题 - 思想的交流总是很有趣且非常有用。
此致。

社区寻宝

Find the treasures in MATLAB Central and discover how the community can help you!

开始狩猎!