Skip to content
Permalink
Browse files

Now should work with tf 1.2rc2

  • Loading branch information...
m-colombo committed Jun 8, 2017
1 parent c503dbd commit 650d8167b541c4077373121ad60a1964e8adfe43
Showing with 12 additions and 11 deletions.
  1. +1 −1 README.md
  2. 0 __init__.py
  3. +5 −5 esn_cell.py
  4. +5 −4 esn_cell_test.py
  5. +1 −1 example.py
@@ -1,3 +1,3 @@
# Tensorflow-EchoStateNetwork
Echo state network implementation on tensorflow.
Tested on 0.12.1
Tested on 1.2.0rc2
No changes.
@@ -1,4 +1,4 @@
from tensorflow.python.ops import rnn_cell
from tensorflow.python.ops import rnn_cell_impl
from tensorflow.python.ops import init_ops
from tensorflow.python.ops import math_ops
from tensorflow.python.ops import random_ops
@@ -7,7 +7,7 @@
from tensorflow.python.framework.ops import convert_to_tensor


class ESNCell(rnn_cell.RNNCell):
class ESNCell(rnn_cell_impl.RNNCell):
"""Echo State Network Cell.
Based on http://www.faculty.jacobs-university.de/hjaeger/pubs/EchoStatesTechRep.pdf
@@ -55,7 +55,7 @@ def _wr_initializer(shape, dtype, partition_info=None):
connectivity),
dtype)

wr = math_ops.mul(wr, connectivity_mask)
wr = math_ops.multiply(wr, connectivity_mask)

wr_norm2 = math_ops.sqrt(math_ops.reduce_sum(math_ops.square(wr)))

@@ -105,8 +105,8 @@ def __call__(self, inputs, state, scope=None):
trainable=False, initializer=self._wr_initializer)
b = vs.get_variable("Bias", [self._num_units], dtype=dtype, trainable=False, initializer=self._bias_initializer)

in_mat = array_ops.concat(1, [inputs, state])
weights_mat = array_ops.concat(0, [win, wr])
in_mat = array_ops.concat([inputs, state], axis=1)
weights_mat = array_ops.concat([win, wr], axis=0)

output = (1 - self._leaky) * state + self._leaky * self._activation(math_ops.matmul(in_mat, weights_mat) + b)

@@ -22,11 +22,12 @@ def test_esn_dynamics(self):
state, _ = cell(inputs[i, :, :], state)

with self.test_session() as sess:
sess.run(tf.initialize_all_variables())
final_states = sess.run([state])
sess.run(tf.global_variables_initializer())

expected_final_states = [[[0.75952783, -0.96463442, 0.72289173, 0.38016839],
[0.82451594, -0.99358452, 0.86248011, 0.24540841]]]
final_states = sess.run(state)

expected_final_states = [[-0.56735968, -0.21625957, 0.69647415, -0.91361383],
[-0.22654705, -0.15751715, 0.85077971, -0.89757621]]

self.assertAllClose(final_states, expected_final_states)

@@ -18,7 +18,7 @@ def MackeyGlass(tr_size=500, washout_size=50, units=30, connectivity=0.2, scale=
washed = tf.squeeze(tf.slice(outputs, [0, washout_size, 0], [-1, -1, -1]))

with tf.Session() as S:
S.run(tf.initialize_all_variables())
S.run(tf.global_variables_initializer())

print("Computing embeddings...")
res = S.run(washed)

0 comments on commit 650d816

Please sign in to comment.
You can’t perform that action at this time.