docstr: Tests against scipy for a (batch of) mixture(s) of seven gaussians.
docstr_tok: ["Tests","against","scipy","for","a","(","batch","of",")","mixture","(","s",")","of","seven","gaussians","."]
code: def testCdfBatchUnivariate(self):
      """Tests against scipy for a (batch of) mixture(s) of seven gaussians."""
      n_components = 7
      batch_size = 5
      mixture_weight_logits = np.random.uniform(
          low=-1, high=1, size=(batch_size, n_components)
      ).astype(np.float32)
  
      def _batch_univariate_softmax(x):
          e_x = np.exp(x)
          e_x_sum = np.expand_dims(np.sum(e_x, axis=1), axis=1)
          return e_x / np.tile(e_x_sum, reps=[1, x.shape[1]])
  
      psize = (batch_size,)
      mixture_weights = _batch_univariate_softmax(mixture_weight_logits)
      means = [
          np.random.uniform(low=-10, high=10, size=psize).astype(
              np.float32
          )
          for _ in range(n_components)
      ]
      sigmas = [
          np.ones(shape=psize, dtype=np.float32)
          for _ in range(n_components)
      ]
      cat_tf = categorical.Categorical(probs=mixture_weights)
      components_tf = [
          normal.Normal(loc=mu, scale=sigma)
          for (mu, sigma) in zip(means, sigmas)
      ]
      mixture_tf = mixture.Mixture(
          cat=cat_tf, components=components_tf, validate_args=True
      )
  
      xs_to_check = [
          np.array([1.0, 5.9, -3, 0.0, 0.0], dtype=np.float32),
          np.random.randn(batch_size).astype(np.float32),
      ]
  
      for x_tensor in xs_to_check:
          x_cdf_tf_result, x_log_cdf_tf_result = self.evaluate(
              [mixture_tf.cdf(x_tensor), mixture_tf.log_cdf(x_tensor)]
          )
  
          # Compute the cdf with scipy.
          scipy_component_cdfs = [
              stats.norm.cdf(x=x_tensor, loc=mu, scale=sigma)
              for (mu, sigma) in zip(means, sigmas)
          ]
          weights_and_cdfs = zip(
              np.transpose(mixture_weights, axes=[1, 0]),
              scipy_component_cdfs,
          )
          final_cdf_probs_per_component = [
              np.multiply(c_p_value, d_cdf_value)
              for (c_p_value, d_cdf_value) in weights_and_cdfs
          ]
          scipy_cdf_result = np.sum(
              final_cdf_probs_per_component, axis=0
          )
          self.assertAllClose(x_cdf_tf_result, scipy_cdf_result)
          self.assertAllClose(
              np.exp(x_log_cdf_tf_result), scipy_cdf_result
          )
  
imports: import contextlib
  import warnings
  import numpy
  from scipy import stats
  import tensorflow.compat.v1
  import tensorflow.compat.v2
  from tensorflow_probability.python.distributions import categorical
  from tensorflow_probability.python.distributions import dirichlet
  from tensorflow_probability.python.distributions import distribution
  from tensorflow_probability.python.distributions import gamma
  from tensorflow_probability.python.distributions import half_normal
  from tensorflow_probability.python.distributions import independent
  from tensorflow_probability.python.distributions import mixture
  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.internal import hypothesis_testlib
  from tensorflow_probability.python.internal import reparameterization
  from tensorflow_probability.python.internal import tensorshape_util
  from tensorflow_probability.python.internal import test_util
label_desc: Use image node_id 24 for calling the MixtureTest obj's underlying member method code with example usage: obj.testCdfBatchUnivariate() and returns: unknown