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: Perform sampling and exchange.
      
docstr_tok: ["Perform","sampling","and","exchange","."]
code: def build_update(self):
      """Perform sampling and exchange."""
      # Sample by Metropolis-Hastings for each replica.
      replica_sample = []
      replica_accept = []
      for i in range(self.n_replica):
          sample_, accept_ = self._mh_sample(
              self.replica_vars[i], self.inverse_temperatures[i]
          )
          replica_sample.append(sample_)
          replica_accept.append(accept_)
      accept = replica_accept[0]
  
      # Variable to store order of replicas after exchange
      new_replica_idx = tf.Variable(tf.range(self.n_replica))
      new_replica_idx = tf.assign(
          new_replica_idx, tf.range(self.n_replica)
      )
  
      # Variable to store ratio of current samples
      replica_ratio = tf.Variable(
          tf.zeros(
              self.n_replica, dtype=list(self.latent_vars)[0].dtype
          )
      )
      replica_ratio = self._replica_ratio(replica_ratio, replica_sample)
  
      # Exchange adjacent replicas at frequency of exchange_freq
      u = tf.random_uniform([])
      exchange = u < self.exchange_freq
      new_replica_idx = tf.cond(
          exchange,
          lambda: self._replica_exchange(
              new_replica_idx, replica_ratio
          ),
          lambda: new_replica_idx,
      )
  
      # New replica sorted by new_replica_idx
      new_replica_sample = []
      for i in range(self.n_replica):
          new_replica_sample.append(
              {
                  z: tf.case(
                      {
                          tf.equal(
                              tf.gather(new_replica_idx, i), j
                          ): _stateful_lambda(replica_sample[j][z])
                          for j in range(self.n_replica)
                      },
                      default=lambda: replica_sample[0][z],
                      exclusive=True,
                  )
                  for z, qz in six.iteritems(self.latent_vars)
              }
          )
  
      assign_ops = []
  
      # Update Empirical random variables.
      for z, qz in six.iteritems(self.latent_vars):
          variable = qz.get_variables()[0]
          assign_ops.append(
              tf.scatter_update(
                  variable, self.t, new_replica_sample[0][z]
              )
          )
  
      for i in range(self.n_replica):
          for z, qz in six.iteritems(self.replica_vars[i]):
              variable = qz.get_variables()[0]
              assign_ops.append(
                  tf.scatter_update(
                      variable, self.t, new_replica_sample[i][z]
                  )
              )
  
      # Increment n_accept (if accepted).
      assign_ops.append(
          self.n_accept.assign_add(tf.where(accept, 1, 0))
      )
  
      return tf.group(*assign_ops)
  
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 3 for calling the ReplicaExchangeMC obj's underlying member method code with example usage: obj.build_update() and returns: tf