Skip to content

Instantly share code, notes, and snippets.

@lmcintosh
Created March 7, 2017 19:57
Show Gist options
  • Save lmcintosh/40e57762b9c58aa882caa48cfd7df0d0 to your computer and use it in GitHub Desktop.
Save lmcintosh/40e57762b9c58aa882caa48cfd7df0d0 to your computer and use it in GitHub Desktop.
adaptive integrate and (not yet fire) neuron in tensorflow
class AdaptiveIAF(tf.nn.rnn_cell.RNNCell):
def __init__(self, num_units, dt, reuse=False):
self._dt = tf.constant(dt, dtype=tf.float32)
self._num_units = num_units
self._reuse = reuse
@property
def state_size(self):
return (self._num_units, self._num_units)
@property
def output_size(self):
return self._num_units
def __call__(self, inputs, state, scope=None):
v, w = state
with vs.variable_scope(scope or 'AdaptiveIAF', reuse=self._reuse):
a1 = vs.get_variable("a1", shape=(1,), dtype=tf.float32, initializer=tf.random_uniform_initializer(0, 1))
a2 = vs.get_variable("a2", shape=(1,), dtype=tf.float32, initializer=tf.random_uniform_initializer(0, 1))
a3 = vs.get_variable("a3", shape=(1,), dtype=tf.float32, initializer=tf.random_uniform_initializer(0, 1))
a4 = vs.get_variable("a4", shape=(1,), dtype=tf.float32, initializer=tf.random_uniform_initializer(0, 1))
new_v = v + self._dt * (a1 * v + a2 - w + inputs)
new_w = w + self._dt * (a3 * v - a4 * w)
if not self._reuse:
self._reuse = True
return new_v, (new_v, new_w)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment