Skip to content

Instantly share code, notes, and snippets.

@NMZivkovic
Created November 11, 2018 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NMZivkovic/20d188f1867facfe9cf983d4010b8191 to your computer and use it in GitHub Desktop.
Save NMZivkovic/20d188f1867facfe9cf983d4010b8191 to your computer and use it in GitHub Desktop.
def gibsSampling(self, number_of_iterations):
counter = tf.constant(0)
[_, _, visible_cdstates] = control_flow_ops.while_loop(lambda count, num_iter, *args: count < num_iter,
self.singleStep, [counter, tf.constant(number_of_iterations), self._input])
# Stop tensorflow from propagating gradients back through the gibbs step
visible_cdstates = tf.stop_gradient(visible_cdstates)
return visible_cdstates
def callculate_state(self, probability):
return tf.floor(probability + tf.random_uniform(tf.shape(probability), 0, 1))
def singleStep(self, count, index, input_indexed):
hidden_states = self.callculate_state(tf.sigmoid(tf.matmul(input_indexed, self._weights) + self._hidden_bias))
visible_cdstates = self.callculate_state(tf.sigmoid(tf.matmul(hidden_states, tf.transpose(self._weights)) + self._visible_bias))
return count+1, index, visible_cdstates
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment