code: def testVarGoesInRightDirection(self):
      # This online updating scheme violates detailed balance, and in general
      # will not leave the target distribution invariant. We test a weaker
      # property, which is that the variance gets closer to the target variance,
      # assuming we start at the correct mean. This test does not pass reliably
      # when the mean is not near the true mean.
      error_factor = 5.0
      init_variance = (
          error_factor * tf.convert_to_tensor(self.mvn_scale) ** 2
      )
      init_mean = tf.convert_to_tensor(self.mvn_mean)
      initial_running_variance = (
          sample_stats.RunningVariance.from_stats(
              num_samples=10.0, mean=init_mean, variance=init_variance
          )
      )
      results = self._run_hmc(
          num_results=1000,
          initial_running_variance=initial_running_variance,
      )
  
      # This number started off at `error_factor`, and should be smaller now
      # This makes sure it is 90% closer to equal. The intention is that the
      # precision of the momentum should eventually equal the variance of the
      # state. We test elsewhere that the precision of the momentum faithfully
      # updates according to the draws it makes. This makes sure that those draws
      # are also getting closer to the underlying variance.
      new_error_factor = 1.0 + 0.1 * (error_factor - 1.0)
  
      final_var_ratio = results.final_precision / results.true_variance
      self.assertAllLess(final_var_ratio, new_error_factor)
  
imports: import collections
  from absl.testing import parameterized
  import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.distributions import independent
  from tensorflow_probability.python.distributions import joint_distribution_sequential
  from tensorflow_probability.python.distributions import mvn_diag
  from tensorflow_probability.python.distributions import normal
  from tensorflow_probability.python.distributions import sample
  from tensorflow_probability.python.experimental.mcmc import diagonal_mass_matrix_adaptation
  from tensorflow_probability.python.experimental.mcmc import preconditioned_hmc
  from tensorflow_probability.python.experimental.mcmc import preconditioning_utils
  from tensorflow_probability.python.experimental.stats import sample_stats
  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 sample
label_desc: Use image node_id 6 for calling the DiagonalMassMatrixAdaptationTest obj's underlying member method code with example usage: obj.testVarGoesInRightDirection() without return types