Created
November 11, 2018 21:36
-
-
Save NMZivkovic/20d188f1867facfe9cf983d4010b8191 to your computer and use it in GitHub Desktop.
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
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