code: def testCovarianceFromSampling(self):
      alpha = np.array([[1.0, 2, 3], [2.5, 4, 0.1]], dtype=np.float32)
      n = np.array([10, 30], dtype=np.float32)
      # batch_shape=[2], event_shape=[3]
      dist = dm.DirichletMultinomial(n, alpha, validate_args=True)
      # Sample count chosen based on what can be drawn in about 1 minute.
      x = dist.sample(int(25e3), seed=test_util.test_seed())
      sample_mean = tf.reduce_mean(x, axis=0)
      x_centered = x - sample_mean[tf.newaxis, ...]
      sample_cov = tf.reduce_mean(
          tf.matmul(
              x_centered[..., tf.newaxis],
              x_centered[..., tf.newaxis, :],
          ),
          axis=0,
      )
      sample_var = tf.linalg.diag_part(sample_cov)
      sample_stddev = tf.sqrt(sample_var)
      [
          x_,
          sample_cov_,
          sample_var_,
          sample_stddev_,
          analytic_mean,
          analytic_cov,
          analytic_var,
          analytic_stddev,
      ] = self.evaluate(
          [
              x,
              sample_cov,
              sample_var,
              sample_stddev,
              dist.mean(),
              dist.covariance(),
              dist.variance(),
              dist.stddev(),
          ]
      )
      # Tolerances tuned as follows:
      # - Run with 1000 independent seeds until < 5% fail
      # - Then double the relative tolerance
      # If the sampled quantities are normally distributed, a 5% failure rate
      # corresponds to a z-score of about 2; doubling this should give a z-score
      # of 4, which corresponds to a failure rate of 6.4e-5
      self.assertAllMeansClose(x_, analytic_mean, axis=0, rtol=0.1)
      self.assertAllClose(sample_cov_, analytic_cov, rtol=0.3)
      self.assertAllClose(sample_var_, analytic_var, rtol=0.2)
      self.assertAllClose(sample_stddev_, analytic_stddev, rtol=0.1)
  
imports: import numpy
  import tensorflow.compat.v1
  import tensorflow.compat.v2
  from tensorflow_probability.python.distributions import dirichlet_multinomial
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.math import gradient
label_desc: Use image node_id 17 for calling the DirichletMultinomialTest obj's underlying member method code with example usage: obj.testCovarianceFromSampling() without return types