(self)
Define the cost function.

        The loss is composed of two terms:
        1.) The reconstruction loss (the negative log probability of the
            input under the reconstructed Bernoulli distribution induced by
            the decoder in the data space). This can be interpreted as the
            number of "nats" required for reconstructing the input when the
            activation in latent space is given.

        2.) The latent loss (the Kullback-Leibler divergence between the
            distribution in latent space induced by the encoder on the data
            and some prior). This acts as a kind of regularizer, and can be
            interpreted as the number of "nats" required for transmitting the
            latent space distribution given the prior.
Define the cost function.
Define the cost function .
def _create_loss_optimizer(self):
        """Define the cost function.

        The loss is composed of two terms:
        1.) The reconstruction loss (the negative log probability of the
            input under the reconstructed Bernoulli distribution induced by
            the decoder in the data space). This can be interpreted as the
            number of "nats" required for reconstructing the input when the
            activation in latent space is given.

        2.) The latent loss (the Kullback-Leibler divergence between the
            distribution in latent space induced by the encoder on the data
            and some prior). This acts as a kind of regularizer, and can be
            interpreted as the number of "nats" required for transmitting the
            latent space distribution given the prior.
        """
        reconstr_loss = binary_crossentropy(self.x_reconstr_mean, self.x)
        latent_loss = -0.5 * tf.reduce_mean(1 + self.z_log_sigma_sq
                                            - tf.square(self.z_mean)
                                            - tf.exp(self.z_log_sigma_sq), 1)
        self.cost = tf.reduce_mean(
            tf.add(
                reconstr_loss,
                latent_loss))  # average over batch
        # Use ADAM optimizer.
        opt = tf.train.AdamOptimizer(learning_rate=self.learning_rate)
        self.opt = opt.minimize(self.cost)
def _create_loss_optimizer ( self ) : reconstr_loss = binary_crossentropy ( self . x_reconstr_mean , self . x ) latent_loss = - 0.5 * tf . reduce_mean ( 1 + self . z_log_sigma_sq - tf . square ( self . z_mean ) - tf . exp ( self . z_log_sigma_sq ) , 1 ) self . cost = tf . reduce_mean ( tf . add ( reconstr_loss , latent_loss ) ) # average over batch # Use ADAM optimizer. opt = tf . train . AdamOptimizer ( learning_rate = self . learning_rate ) self . opt = opt . minimize ( self . cost )