-
-
Save nirum/fda5803966e86b06d79b47e04be3e393 to your computer and use it in GitHub Desktop.
adaptive integrate and (not yet fire) neuron in tensorflow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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