'Calculate gumbel control variate.'

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

    if (temperature is None):
        temperature = self.hparams.temperature
    h = 0
    extra = []
    for layer in xrange(self.hparams.n_layer):
        (logQ, softSamples) = self._recognition_network(sampler=functools.partial(self._random_sample_switch, switch_layer=layer, temperature=temperature))
        (softELBO, _) = self._generator_network(softSamples, logQ)
        (logQ_v, softSamples_v) = self._recognition_network(sampler=functools.partial(self._random_sample_switch_v, switch_layer=layer, temperature=temperature))
        (softELBO_v, _) = self._generator_network(softSamples_v, logQ_v)
        learning_signal = tf.stop_gradient(softELBO_v)
        h += (((tf.stop_gradient(learning_signal) * logQHard[layer]) - softELBO) + softELBO_v)
        extra.append((softELBO_v, ((- softELBO) + softELBO_v)))
    return (h, extra)
