docstr: Sampling from a 2-D Multivariate Normal distribution.
docstr_tok: ["Sampling","from","a","2-D","Multivariate","Normal","distribution","."]
code: def testRWM2DNormal(self):
      """Sampling from a 2-D Multivariate Normal distribution."""
      dtype = np.float32
      true_mean = dtype([0, 0])
      true_cov = dtype([[1, 0.5], [0.5, 1]])
      num_results = 500
      num_chains = 100
      # Target distribution is defined through the Cholesky decomposition
      chol = tf.linalg.cholesky(true_cov)
      target = mvn_tril.MultivariateNormalTriL(
          loc=true_mean, scale_tril=chol
      )
  
      # Assume that the state is passed as a list of 1-d tensors `x` and `y`.
      # Then the target log-density is defined as follows:
      def target_log_prob(x, y):
          # Stack the input tensors together
          z = tf.stack([x, y], axis=-1) - true_mean
          return target.log_prob(z)
  
      # Initial state of the chain
      init_state = [
          np.ones([num_chains, 1], dtype=dtype),
          np.ones([num_chains, 1], dtype=dtype),
      ]
  
      # Run Random Walk Metropolis with normal proposal for `num_results`
      # iterations for `num_chains` independent chains:
      states = sample.sample_chain(
          num_results=num_results,
          current_state=init_state,
          kernel=random_walk_metropolis.RandomWalkMetropolis(
              target_log_prob_fn=target_log_prob
          ),
          num_burnin_steps=200,
          num_steps_between_results=1,
          trace_fn=None,
          seed=test_util.test_seed(),
      )
  
      states = tf.stack(states, axis=-1)
      sample_mean = tf.math.reduce_mean(states, axis=[0, 1])
      x = states - sample_mean
      sample_cov = tf.math.reduce_mean(
          tf.linalg.matmul(x, x, transpose_a=True), axis=[0, 1]
      )
      [sample_mean_, sample_cov_] = self.evaluate(
          [sample_mean, sample_cov]
      )
  
      self.assertAllClose(
          np.squeeze(sample_mean_), true_mean, atol=0.1, rtol=0.1
      )
      self.assertAllClose(
          np.squeeze(sample_cov_), true_cov, atol=0.1, rtol=0.1
      )
  
imports: import numpy
  import tensorflow.compat.v1
  import tensorflow.compat.v2
  from tensorflow_probability.python.distributions import cauchy
  from tensorflow_probability.python.distributions import mvn_tril
  from tensorflow_probability.python.distributions import normal
  from tensorflow_probability.python.internal import distribute_lib
  from tensorflow_probability.python.internal import distribute_test_lib
  from tensorflow_probability.python.internal import samplers
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.mcmc import random_walk_metropolis
  from tensorflow_probability.python.mcmc import sample
label_desc: Use image node_id 5 for calling the RWMTest obj's underlying member method code with example usage: obj.testRWM2DNormal() and returns: target