我试图根据下面的定义在Tensorflow中定义我自己的RNNCell(回声状态网络)。在
x(t+1)=tanh(Win*u(t)+W*x(t)+Wfb*y(t))
y(t)=不会*z(t)
z(t)=[x(t),u(t)]
x是状态,u是输入,y是输出。Win、W和Wfb不可培训。所有权重都是随机初始化的,但是W是这样修改的:“将W元素的某个百分比设置为0,缩放W以使其光谱半径保持在1.0以下
我有这个代码来生成方程。在
x = tf.Variable(tf.reshape(tf.zeros([N]), [-1, N]), trainable=False, name="state_vector")
W = tf.Variable(tf.random_normal([N, N], 0.0, 0.05), trainable=False)
# TODO: setup W according to the ESN paper
W_x = tf.matmul(x, W)
u = tf.placeholder("float", [None, K], name="input_vector")
W_in = tf.Variable(tf.random_normal([K, N], 0.0, 0.05), trainable=False)
W_in_u = tf.matmul(u, W_in)
z = tf.concat(1, [x, u])
W_out = tf.Variable(tf.random_normal([K + N, L], 0.0, 0.05))
y = tf.matmul(z, W_out)
W_fb = tf.Variable(tf.random_normal([L, N], 0.0, 0.05), trainable=False)
W_fb_y = tf.matmul(y, W_fb)
x_next = tf.tanh(W_in_u + W_x + W_fb_y)
y_ = tf.placeholder("float", [None, L], name="train_output")
我的问题是双重的。首先,我不知道如何将其作为rncell的超类来实现。第二,我不知道如何根据上述规范生成W张量。在
如果有任何问题需要帮助,我们将不胜感激。也许我可以想出一种方法来准备W,但我肯定不明白如何将我自己的RNN作为rncell的超类来实现。在
快速总结:
请查看
python/ops/rnn_cell.py
下的TensorFlow源代码,了解如何子类rncell。通常是这样的:相关问题 更多 >
编程相关推荐