'Compute the NVIL gradient.'

def get_nvil_gradient(self):

    (logQHard, samples) = self._recognition_network()
    (ELBO, reinforce_model_grad) = self._generator_network(samples, logQHard)
    logQHard = tf.add_n(logQHard)
    learning_signal = (tf.stop_gradient(ELBO) - self._create_baseline())
    self.baseline_loss.append(tf.square(learning_signal))
    optimizerLoss = (- ((tf.stop_gradient(learning_signal) * logQHard) + reinforce_model_grad))
    optimizerLoss = tf.reduce_mean(optimizerLoss)
    nvil_gradient = self.optimizer_class.compute_gradients(optimizerLoss)
    debug = {'ELBO': ELBO, 'RMS    of    centered    learning    signal': U.rms(learning_signal)}
    return (nvil_gradient, debug)
