這是從Neurolab Python Library使用Elman Recurrent Neural Network的an example:爲迴歸神經網絡(LSTM)輸入/輸出的任意長度的
import neurolab as nl
import numpy as np
# Create train samples
i1 = np.sin(np.arange(0, 20))
i2 = np.sin(np.arange(0, 20)) * 2
t1 = np.ones([1, 20])
t2 = np.ones([1, 20]) * 2
input = np.array([i1, i2, i1, i2]).reshape(20 * 4, 1)
target = np.array([t1, t2, t1, t2]).reshape(20 * 4, 1)
# Create network with 2 layers
net = nl.net.newelm([[-2, 2]], [10, 1], [nl.trans.TanSig(), nl.trans.PureLin()])
# Set initialized functions and init
net.layers[0].initf = nl.init.InitRand([-0.1, 0.1], 'wb')
net.layers[1].initf= nl.init.InitRand([-0.1, 0.1], 'wb')
net.init()
# Train network
error = net.train(input, target, epochs=500, show=100, goal=0.01)
# Simulate network
output = net.sim(input)
# Plot result
import pylab as pl
pl.subplot(211)
pl.plot(error)
pl.xlabel('Epoch number')
pl.ylabel('Train error (default MSE)')
pl.subplot(212)
pl.plot(target.reshape(80))
pl.plot(output.reshape(80))
pl.legend(['train target', 'net output'])
pl.show()
在這個例子中它是合併2單位長度輸入並且還它合併2單位長度輸出。之後,它正在使用這些合併陣列來訓練網絡。
首先,它似乎並不像我從here得到了架構:
我的主要問題是;
我具有到網絡的輸入和輸出喜歡這些任意長度培養:
- 任意長度的輸入,以固定長度的輸出
- 固定長度輸入到任意長度輸出
- 任意長度輸入到任意長度輸出
在這一點上,你會想到:「你的回答是Long short-term memory networks。」
我知道它但Neurolab易於使用,因爲它是good features。特別是,它特別是Pythonic。所以我堅持使用Neurolab圖書館爲我的問題。但如果你建議我另一個庫像Neurolab更好的LSTM功能,我會接受它。
最後,如何重新排列這個例子的任意長度的輸入和輸出?
我對RNN和LSTM沒有最好的理解,所以請說明一下。
解決問題,或者我還可以回答? –
@RajarsheeMitra你仍然可以回答。 – mertyildiran
這是什麼答案?使用任意長度的輸入和輸出? – Uzair