これは、Neurolab Python LibraryのElman Recurrent Neural Networkの使用例です。
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 単位長の出力をマージ しています。その後、これらのマージされた配列を使用してネットワークをトレーニングします。
まず第一に、私がここから得たスキーマのようには見えません:
私の主な質問は次のとおりです。
次のような任意の長さの 入力と出力でネットワークをトレーニングする必要があります。
- 固定長出力への任意長入力
- 固定長入力から任意長出力へ
- 任意の長さの入力から任意の長さの出力へ
この時点で、「あなたの答えはLong short-term memory networksです」ということが頭に浮かびます。
それはわかっていますが、Neurolabは優れた機能を備えているため使いやすいです。特に、それは非常にPythonicです。だから私は自分の問題にNeurolab Libraryを使うことを主張しています。しかし、より優れたLSTM機能を備えた Neurolab のような別のライブラリを提案していただければ、それを受け入れます。
最終的に、この例を任意の長さの入力と出力に再配置するにはどうすればよいですか?
私は RNN と LSTM についてよく理解していないので、説明してください。