code: def testCorrelated2dNormalwithinMCError(self):
      strm = test_util.test_seed_stream()
      dtype = np.float64
  
      # We run nreplica independent test to improve test robustness.
      nreplicas = 20
      nchains = 100
      num_steps = 1000
      mu = np.asarray([0.0, 3.0], dtype=dtype)
      rho = 0.75
      sigma1 = 1.0
      sigma2 = 2.0
      cov = np.asarray(
          [
              [sigma1 * sigma1, rho * sigma1 * sigma2],
              [rho * sigma1 * sigma2, sigma2 * sigma2],
          ],
          dtype=dtype,
      )
      true_param = np.hstack(
          [mu, np.array([sigma1**2, sigma2**2, rho])]
      )
      scale_tril = np.linalg.cholesky(cov)
      initial_state = np.zeros((nchains, nreplicas, 2), dtype)
  
      @tf.function(autograph=False)
      def run_chain_and_get_estimation_error():
          target_log_prob = mvn_tril.MultivariateNormalTriL(
              loc=mu, scale_tril=scale_tril
          ).log_prob
          nuts_kernel = nuts.NoUTurnSampler(
              target_log_prob,
              step_size=tf.constant([sigma1, sigma2], dtype),
          )
          chain_state = sample.sample_chain(
              num_results=num_steps,
              num_burnin_steps=20,
              current_state=initial_state,
              kernel=duassa.DualAveragingStepSizeAdaptation(
                  nuts_kernel, 20, 0.8
              ),
              seed=strm(),
              trace_fn=None,
          )
          variance_est = tf.square(chain_state - mu)
          correlation_est = tf.reduce_prod(
              chain_state - mu, axis=-1, keepdims=True
          ) / (sigma1 * sigma2)
          mcmc_samples = tf.concat(
              [chain_state, variance_est, correlation_est], axis=-1
          )
  
          expected = tf.reduce_mean(mcmc_samples, axis=[0, 1])
  
          ess = tf.reduce_sum(
              diagnostic.effective_sample_size(mcmc_samples), axis=0
          )
          avg_monte_carlo_standard_error = tf.reduce_mean(
              tf.math.reduce_std(mcmc_samples, axis=0), axis=0
          ) / tf.sqrt(ess)
          scaled_error = (
              tf.abs(expected - true_param)
              / avg_monte_carlo_standard_error
          )
  
          return normal.Normal(
              loc=tf.zeros([], dtype), scale=1.0
          ).survival_function(scaled_error)
  
      # Run chains, compute the error, and compute the probability of getting
      # a more extreme error. `error_prob` has shape (nreplica * 5)
      error_prob = run_chain_and_get_estimation_error()
  
      # Check convergence using Markov chain central limit theorem, this is a
      # z-test at p=.01
      is_converged = error_prob > 0.005
      # Test at most 5% test fail out of total number of independent tests.
      n_total_tests = nreplicas * len(true_param)
      num_test_failed = self.evaluate(
          tf.math.reduce_sum(tf.cast(is_converged, dtype))
      )
      self.assertLessEqual(
          n_total_tests - num_test_failed,
          np.round(n_total_tests * 0.05),
      )
  
imports: from absl.testing import parameterized
  import numpy
  import tensorflow.compat.v1
  import tensorflow.compat.v2
  from tensorflow_probability.python.bijectors import exp
  from tensorflow_probability.python.bijectors import identity
  from tensorflow_probability.python.distributions import beta
  from tensorflow_probability.python.distributions import half_normal
  from tensorflow_probability.python.distributions import independent
  from tensorflow_probability.python.distributions import joint_distribution_coroutine
  from tensorflow_probability.python.distributions import joint_distribution_sequential
  from tensorflow_probability.python.distributions import mvn_diag
  from tensorflow_probability.python.distributions import mvn_tril
  from tensorflow_probability.python.distributions import normal
  from tensorflow_probability.python.distributions import sample
  from tensorflow_probability.python.distributions import sigmoid_beta
  from tensorflow_probability.python.distributions import student_t
  from tensorflow_probability.python.distributions.internal import statistical_testing
  from tensorflow_probability.python.internal import assert_util
  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.math import generic
  from tensorflow_probability.python.mcmc import diagnostic
  from tensorflow_probability.python.mcmc import dual_averaging_step_size_adaptation
  from tensorflow_probability.python.mcmc import nuts
  from tensorflow_probability.python.mcmc import sample
  from tensorflow_probability.python.mcmc import transformed_kernel
  from tensorflow_probability.python.stats import sample_stats
label_desc: Use image node_id 10 for calling the NutsTest obj's underlying member method code with example usage: obj.testCorrelated2dNormalwithinMCError() and returns: normal