def sample_hidden_from_visible(self, visible): """ Sample the hidden units from the visible units. This is the Positive phase of the Contrastive Divergence algorithm. :param visible: activations of the visible units :return: tuple(hidden probabilities, hidden binary states) """ hprobs = tf.nn.sigmoid(tf.matmul(visible, self.W) + self.bh_) hstates = utilities.sample_prob(hprobs, self.hrand) return hprobs, hstates
def _create_decoding_layers(self, decode_input): """ Create the decoding layres of the model. :param decode_input: output of the last encoding layer :return: output of the last decoding layer """ decode_output = decode_input for l in reversed(range(self.n_layers - 1)): vprobs = tf.nn.sigmoid( tf.matmul(decode_output, self.W_vars_t[l]) + self.bv_vars[l]) vstates = utilities.sample_prob(vprobs, self.vrand[l]) decode_output = vstates return decode_output
def _create_encoding_layers(self): """ Create the encoding layers of the model. :return: output of the last encoding layer """ next_layer_feed = self.x for l in range(self.n_layers - 1): hprobs = tf.nn.dropout( tf.nn.sigmoid( tf.matmul(next_layer_feed, self.W_vars[l]) + self.bh_vars[l]), self.keep_prob) hstates = utilities.sample_prob(hprobs, self.hrand[l]) next_layer_feed = hstates return next_layer_feed