code: def _compute_log_acceptance_correction(
      kinetic_energy_fn,
      current_momentums,
      proposed_momentums,
      name=None,
  ):
      """Helper to `kernel` which computes the log acceptance-correction.
  
      A sufficient but not necessary condition for the existence of a stationary
      distribution, `p(x)`, is "detailed balance", i.e.:
  
      ```none
      p(x'|x) p(x) = p(x|x') p(x')
      ```
  
      In the Metropolis-Hastings algorithm, a state is proposed according to
      `g(x'|x)` and accepted according to `a(x'|x)`, hence
      `p(x'|x) = g(x'|x) a(x'|x)`.
  
      Inserting this into the detailed balance equation implies:
  
      ```none
          g(x'|x) a(x'|x) p(x) = g(x|x') a(x|x') p(x')
      ==> a(x'|x) / a(x|x') = p(x') / p(x) [g(x|x') / g(x'|x)]    (*)
      ```
  
      One definition of `a(x'|x)` which satisfies (*) is:
  
      ```none
      a(x'|x) = min(1, p(x') / p(x) [g(x|x') / g(x'|x)])
      ```
  
      (To see that this satisfies (*), notice that under this definition only at
      most one `a(x'|x)` and `a(x|x') can be other than one.)
  
      We call the bracketed term the "acceptance correction".
  
      In the case of UncalibratedHMC, the log acceptance-correction is not the log
      proposal-ratio. UncalibratedHMC augments the state-space with momentum, z.
      Given a probability density of `m(z)` for momentums, the chain eventually
      converges to:
  
      ```none
      p([x, z]) propto= target_prob(x) m(z)
      ```
  
      Relating this back to Metropolis-Hastings parlance, for HMC we have:
  
      ```none
      p([x, z]) propto= target_prob(x) m(z)
      g([x, z] | [x', z']) = g([x', z'] | [x, z])
      ```
  
      In other words, the MH bracketed term is `1`. However, because we desire to
      use a general MH framework, we can place the momentum probability ratio inside
      the metropolis-correction factor thus getting an acceptance probability:
  
      ```none
                           target_prob(x')
      accept_prob(x'|x) = -----------------  [m(z') / m(z)]
                           target_prob(x)
      ```
      (Note: we actually need to handle the kinetic energy change at each leapfrog
      step, but this is the idea.)
  
      For consistency, we compute this correction in log space, using the kinetic
      energy function, `K(z)`, which is the negative log probability of the momentum
      distribution. So the log acceptance probability is
  
      ```none
      log(correction) = log(m(z')) - log(m(z))
                      = K(z) - K(z')
      ```
  
      Note that this is equality, since the normalization constants on `m` cancel
      out.
  
  
      Args:
        kinetic_energy_fn: Python callable that can evaluate the kinetic energy
          of the given momentum. This is typically the negative log probability of
          the distribution over the momentum.
        current_momentums: (List of) `Tensor`s representing the value(s) of the
          current momentum(s) of the state (parts).
        proposed_momentums: (List of) `Tensor`s representing the value(s) of the
          proposed momentum(s) of the state (parts).
        name: Python `str` name prefixed to Ops created by this function.
          Default value: `None` (i.e., 'compute_log_acceptance_correction').
  
      Returns:
        log_acceptance_correction: `Tensor` representing the `log`
          acceptance-correction.  (See docstring for mathematical definition.)
      """
      with tf.name_scope(name or "compute_log_acceptance_correction"):
          current_kinetic = kinetic_energy_fn(current_momentums)
          proposed_kinetic = kinetic_energy_fn(proposed_momentums)
          return mcmc_util.safe_sum(
              [current_kinetic, -proposed_kinetic]
          )
  
imports: import collections
  import tensorflow.compat.v2
  from tensorflow_probability.python.experimental.mcmc import preconditioning_utils
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.internal import samplers
  from tensorflow_probability.python.mcmc import hmc
  from tensorflow_probability.python.mcmc import metropolis_hastings
  from tensorflow_probability.python.mcmc.internal import leapfrog_integrator
  from tensorflow_probability.python.mcmc.internal import util
label_desc: Use image node_id 1 for calling a global function with example usage: _compute_log_acceptance_correction(kinetic_energy_fn, current_momentums, proposed_momentums, name) and returns: mcmc_util