'Calculate gumbel control variate.'

def _create_gumbel_control_variate(self, logQHard, temperature=None):

    if (temperature is None):
        temperature = self.hparams.temperature
    (logQ, softSamples) = self._recognition_network(sampler=functools.partial(self._random_sample_soft, temperature=temperature))
    (softELBO, _) = self._generator_network(softSamples, logQ)
    logQ = tf.add_n(logQ)
    (logQ_v, softSamples_v) = self._recognition_network(sampler=functools.partial(self._random_sample_soft_v, temperature=temperature))
    (softELBO_v, _) = self._generator_network(softSamples_v, logQ_v)
    logQ_v = tf.add_n(logQ_v)
    learning_signal = tf.stop_gradient(softELBO_v)
    h = (((tf.stop_gradient(learning_signal) * tf.add_n(logQHard)) - softELBO) + softELBO_v)
    extra = (softELBO_v, ((- softELBO) + softELBO_v))
    return (h, extra)
