class_docstr: Replica Exchange MCMC [@swendsen1986replica; @hukushima1996exchange].
  
  #### Examples
  ```python
  cat = Categorical(probs=[0.5,0.5])
  x = Mixture(cat=cat, components=[
      MultivariateNormalDiag([0.0,0.0], [1.0,1.0]),
      MultivariateNormalDiag([10.0,10.0], [1.0,1.0])])
  proposal_x = MultivariateNormalDiag(x, [1.0,1.0])
  qx = Empirical(tf.Variable(tf.zeros([10000, 2])))
  inference = ed.ReplicaExchangeMC(latent_vars={x: qx},
                                   proposal_vars={x: proposal_x})
  ```
class_docstr_tok: ["Replica","Exchange","MCMC","[","@","swendsen1986replica",";","@","hukushima1996exchange","]",".","#","#","#","#","Examples","``","`","python","cat","=","Categorical","(","probs=","[","0.5,0.5","]",")","x","=","Mixture","(","cat=cat",",","components=","[","MultivariateNormalDiag","(","[","0.0,0.0","]",",","[","1.0,1.0","]",")",",","MultivariateNormalDiag","(","[","10.0,10.0","]",",","[","1.0,1.0","]",")","]",")","proposal_x","=","MultivariateNormalDiag","(","x",",","[","1.0,1.0","]",")","qx","=","Empirical","(","tf.Variable","(","tf.zeros","(","[","10000",",","2","]",")",")",")","inference","=","ed.ReplicaExchangeMC","(","latent_vars=","{","x",":","qx","}",",","proposal_vars=","{","x",":","proposal_x","}",")","``","`"]
docstr: Exchange replica according to the Metropolis-Hastings criterion.
  $\text{ratio} =
        (\log p(x, z_i) - \log p(x, x_j))(\text{inverse_temperature}_j -
        \text{inverse_temperature}_i)
docstr_tok: ["Exchange","replica","according","to","the","Metropolis-Hastings","criterion",".","$","\\text","{","ratio","}","=","(","\\log","p","(","x",",","z_i",")","-","\\log","p","(","x",",","x_j",")",")","(","\\text","{","inverse_temperature","}","_j","-","\\text","{","inverse_temperature","}","_i",")"]
code: def _replica_exchange(self, new_replica_idx, replica_ratio):
      """Exchange replica according to the Metropolis-Hastings criterion.
      $\\text{ratio} =
            (\log p(x, z_i) - \log p(x, x_j))(\\text{inverse_temperature}_j -
            \\text{inverse_temperature}_i)
      """
      i = tf.random_uniform((), maxval=2, dtype=tf.int32)
  
      def cond(i, new_replica_idx):
          return tf.less(i, self.n_replica - 1)
  
      def body(i, new_replica_idx):
          ratio = replica_ratio[i] - replica_ratio[i + 1]
          ratio *= (
              self.inverse_temperatures[i + 1]
              - self.inverse_temperatures[i]
          )
          u = tf.random_uniform([], dtype=ratio.dtype)
          exchange = tf.log(u) < ratio
          new_replica_idx = tf.cond(
              exchange,
              lambda: tf.scatter_update(
                  new_replica_idx, [i, i + 1], [i + 1, i]
              ),
              lambda: new_replica_idx,
          )
          return [i + 2, new_replica_idx]
  
      return tf.while_loop(cond, body, loop_vars=[i, new_replica_idx])[
          1
      ]
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import six
  import tensorflow
  import numpy
  from collections import OrderedDict
  from edward.inferences.monte_carlo import MonteCarlo
  from edward.models import Empirical, RandomVariable
  from edward.util import check_latent_vars, copy
label_desc: Use image node_id 5 for calling the ReplicaExchangeMC obj's underlying member method code with example usage: obj._replica_exchange(new_replica_idx, replica_ratio) and returns: tf, tf, list