例如,请求:递归神经网络,用于预测序列中的下一个值 [英] Request for example: Recurrent neural network for predicting next value in a sequence
问题描述
有人可以给我一个(pybrain)python中的递归神经网络的实际示例,以预测序列的下一个值吗? (我已经阅读了pybrain文档,但我认为没有明确的示例.) 我还发现了这个问题.但是我看不出它在更一般的情况下是如何工作的.因此,因此,我要问的是,这里的人是否可以通过递归神经网络,得出一个如何通过预测大脑中的脑部序列的下一个值的清晰示例.
Can anyone give me a practicale example of a recurrent neural network in (pybrain) python in order to predict the next value of a sequence ? (I've read the pybrain documentation and there is no clear example for it I think.) I also found this question. But I fail to see how it works in a more general case. So therefore I'm asking if anyone here could work out a clear example of how to predict the next value of a sequence in pybrain, with a recurrent neural network.
举个例子.
例如,我们有一个范围为[1,7]的数字序列.
Say for example we have a sequence of numbers in the range [1,7].
First run (So first example): 1 2 4 6 2 3 4 5 1 3 5 6 7 1 4 7 1 2 3 5 6
Second run (So second example): 1 2 5 6 2 4 4 5 1 2 5 6 7 1 4 6 1 2 3 3 6
Third run (So third example): 1 3 5 7 2 4 6 7 1 3 5 6 7 1 4 6 1 2 2 3 7
and so on.
例如,现在给出一个新序列的开始: 1 3 5 7 2 4 6 7 1 3
Now given for example the start of a new sequence: 1 3 5 7 2 4 6 7 1 3
下一个值是什么
这个问题似乎很懒,但是我认为这里没有一个很好的,如何用pybrain做到这一点的好例子.
This question might seem lazy, but I think there lacks a good and decent example of how to do this with pybrain.
此外:如果存在多个功能,该怎么办:
示例:
例如,我们有几个序列(每个序列具有2个特征)在[1,7]范围内.
Say for example we have several sequences (each sequence having 2 features) in the range [1,7].
First run (So first example): feature1: 1 2 4 6 2 3 4 5 1 3 5 6 7 1 4 7 1 2 3 5 6
feature2: 1 3 5 7 2 4 6 7 1 3 5 6 7 1 4 6 1 2 2 3 7
Second run (So second example): feature1: 1 2 5 6 2 4 4 5 1 2 5 6 7 1 4 6 1 2 3 3 6
feature2: 1 2 3 7 2 3 4 6 2 3 5 6 7 2 4 7 1 3 3 5 6
Third run (So third example): feature1: 1 3 5 7 2 4 6 7 1 3 5 6 7 1 4 6 1 2 2 3 7
feature2: 1 2 4 6 2 3 4 5 1 3 5 6 7 1 4 7 1 2 3 5 6
and so on.
例如,现在给出一个新序列的开始:
Now given for example the start of a new sequences:
feature 1: 1 3 5 7 2 4 6 7 1 3
feature 2: 1 2 3 7 2 3 4 6 2 4
下一个值是什么
可以随意使用您自己的示例,只要它与这些示例相似并且有一些深入的解释即可.
Feel free to use your own example as long it is similar to these examples and has some in depth explanation.
推荐答案
Issam Laradji为我预测序列的序列,除了我的pybrain版本要求UnserpervisedDataSet对象有一个元组:
Issam Laradji's worked for me to predict sequence of sequences, except my version of pybrain required a tuple for the UnserpervisedDataSet object:
from pybrain.tools.shortcuts import buildNetwork
from pybrain.supervised.trainers import BackpropTrainer
from pybrain.datasets import SupervisedDataSet,UnsupervisedDataSet
from pybrain.structure import LinearLayer
ds = SupervisedDataSet(21, 21)
ds.addSample(map(int,'1 2 4 6 2 3 4 5 1 3 5 6 7 1 4 7 1 2 3 5 6'.split()),map(int,'1 2 5 6 2 4 4 5 1 2 5 6 7 1 4 6 1 2 3 3 6'.split()))
ds.addSample(map(int,'1 2 5 6 2 4 4 5 1 2 5 6 7 1 4 6 1 2 3 3 6'.split()),map(int,'1 3 5 7 2 4 6 7 1 3 5 6 7 1 4 6 1 2 2 3 7'.split()))
net = buildNetwork(21, 20, 21, outclass=LinearLayer,bias=True, recurrent=True)
trainer = BackpropTrainer(net, ds)
trainer.trainEpochs(100)
ts = UnsupervisedDataSet(21,)
ts.addSample(map(int,'1 3 5 7 2 4 6 7 1 3 5 6 7 1 4 6 1 2 2 3 7'.split()))
[ int(round(i)) for i in net.activateOnDataset(ts)[0]]
给予:
=> [1, 2, 5, 6, 2, 4, 5, 6, 1, 2, 5, 6, 7, 1, 4, 6, 1, 2, 2, 3, 6]
要预测较小的序列,只需将其训练为子序列或重叠序列即可(
To predict smaller sequences, just train it up as such, either as sub sequences or as overlapping sequences (overlapping shown here):
from pybrain.tools.shortcuts import buildNetwork
from pybrain.supervised.trainers import BackpropTrainer
from pybrain.datasets import SupervisedDataSet,UnsupervisedDataSet
from pybrain.structure import LinearLayer
ds = SupervisedDataSet(10, 11)
z = map(int,'1 2 4 6 2 3 4 5 1 3 5 6 7 1 4 7 1 2 3 5 6 1 2 5 6 2 4 4 5 1 2 5 6 7 1 4 6 1 2 3 3 6 1 3 5 7 2 4 6 7 1 3 5 6 7 1 4 6 1 2 2 3 7'.split())
obsLen = 10
predLen = 11
for i in xrange(len(z)):
if i+(obsLen-1)+predLen < len(z):
ds.addSample([z[d] for d in range(i,i+obsLen)],[z[d] for d in range(i+1,i+1+predLen)])
net = buildNetwork(10, 20, 11, outclass=LinearLayer,bias=True, recurrent=True)
trainer = BackpropTrainer(net, ds)
trainer.trainEpochs(100)
ts = UnsupervisedDataSet(10,)
ts.addSample(map(int,'1 3 5 7 2 4 6 7 1 3'.split()))
[ int(round(i)) for i in net.activateOnDataset(ts)[0]]
给予:
=> [3, 5, 6, 2, 4, 5, 6, 1, 2, 5, 6]
不太好...
这篇关于例如,请求:递归神经网络,用于预测序列中的下一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!