    def _compile_losses(self, inputs, targets, inc_var_loss=True):
        """Helper method for compiling the loss function.

        The loss function is obtained from the log likelihood, assuming that the output
        distribution is Gaussian, with both mean and (diagonal) covariance matrix being determined
        by network outputs.

        Arguments:
            inputs: (tf.Tensor) A tensor representing the input batch
            targets: (tf.Tensor) The desired targets for each input vector in inputs.
            inc_var_loss: (bool) If True, includes log variance loss.

        Returns: (tf.Tensor) A tensor representing the loss on the input arguments.
        """
        mean, log_var = self._compile_outputs(inputs, ret_log_var=True)
        inv_var = tf.exp(-log_var)

        if inc_var_loss:
            mse_losses = tf.reduce_mean(tf.reduce_mean(tf.square(mean - targets) * inv_var, axis=-1), axis=-1)
            var_losses = tf.reduce_mean(tf.reduce_mean(log_var, axis=-1), axis=-1)
            total_losses = mse_losses + var_losses
        else:
            total_losses = tf.reduce_mean(tf.reduce_mean(tf.square(mean - targets), axis=-1), axis=-1)

        return total_losses
Helper method for compiling the loss function.

The loss function is obtained from the log likelihood, assuming that the output
distribution is Gaussian, with both mean and (diagonal) covariance matrix being determined
by network outputs.

Arguments:
inputs: (tf.Tensor) A tensor representing the input batch
targets: (tf.Tensor) The desired targets for each input vector in inputs.
inc_var_loss: (bool) If True, includes log variance loss.

Returns: (tf.Tensor) A tensor representing the loss on the input arguments.
mbpo/models/bnn.py