code: def testCovariance(self):
      # Shape [2]
      alpha = [1.0, 2]
      alpha_0 = np.sum(alpha)
  
      # Diagonal entries are of the form:
      # Var(X_i) = n * alpha_i / alpha_sum * (1 - alpha_i / alpha_sum) *
      # (alpha_sum + n) / (alpha_sum + 1)
      variance_entry = lambda a, a_sum: a / a_sum * (1 - a / a_sum)
      # Off diagonal entries are of the form:
      # Cov(X_i, X_j) = -n * alpha_i * alpha_j / (alpha_sum ** 2) *
      # (alpha_sum + n) / (alpha_sum + 1)
      covariance_entry = lambda a, b, a_sum: -a * b / a_sum**2
      # Shape [2, 2].
      shared_matrix = np.array(
          [
              [
                  variance_entry(alpha[0], alpha_0),
                  covariance_entry(alpha[0], alpha[1], alpha_0),
              ],
              [
                  covariance_entry(alpha[1], alpha[0], alpha_0),
                  variance_entry(alpha[1], alpha_0),
              ],
          ]
      )
  
      # ns is shape [4, 1] and alpha is shape [2].
      ns = [[2.0], [3.0], [4.0], [5.0]]
      dist = dm.DirichletMultinomial(ns, alpha, validate_args=True)
      covariance = self.evaluate(dist.covariance())
      for i in range(len(ns)):
          n = ns[i][0]
          expected_covariance = (
              n * (n + alpha_0) / (1 + alpha_0) * shared_matrix
          )
          self.assertAllClose(
              expected_covariance, np.squeeze(covariance[i])
          )
  
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 18 for calling the DirichletMultinomialTest obj's underlying member method code with example usage: obj.testCovariance() without return types