title: How can I implement a custom RNN (specifically an ESN) in Tensorflow?
body: <p>I am trying to define my own RNNCell (Echo State Network) in Tensorflow, according to below definition.</p>
  
  <p>x(t + 1) = tanh(Win*u(t) + W*x(t) + Wfb*y(t))</p>
  
  <p>y(t) = Wout*z(t)</p>
  
  <p>z(t) = [x(t), u(t)]</p>
  
  <p>x is state, u is input, y is output. Win, W, and Wfb are not trainable. All weights are randomly initialized, but W is modified like this: "Set a certain percentage of elements of W to 0, scale W to keep its spectral radius below 1.0</p>
  
  <p>I have this code to generate the equation.</p>
  
  <pre><code>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")
  </code></pre>
  
  <p>My problem is two-fold. First I don't know how to implement this as a superclass of RNNCell. Second I don't know how to generate a W tensor according to above specification.</p>
  
  <p>Any help about any of these question is greatly appreciated. Maybe I can figure out a way to prepare W, but I sure as hell don't understand how to implement my own RNN as a superclass of RNNCell.</p>