docstr: Tests CDF against scipy for a mixture of seven gaussians.
docstr_tok: ["Tests","CDF","against","scipy","for","a","mixture","of","seven","gaussians","."]
code: def testCdfScalarUnivariate(self):
      """Tests CDF against scipy for a mixture of seven gaussians."""
      # Construct a mixture of gaussians with seven components.
      n_components = 7
  
      # pre-softmax mixture probabilities.
      mixture_weight_logits = np.random.uniform(
          low=-1, high=1, size=(n_components,)
      ).astype(np.float32)
  
      def _scalar_univariate_softmax(x):
          e_x = np.exp(x - np.max(x))
          return e_x / e_x.sum()
  
      # Construct the mixture.Mixture object.
      mixture_weights = _scalar_univariate_softmax(
          mixture_weight_logits
      )
      means = [
          np.random.uniform(low=-10, high=10, size=()).astype(
              np.float32
          )
          for _ in range(n_components)
      ]
      sigmas = [
          np.ones(shape=(), 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
      )
  
      # These are two test cases to verify.
      xs_to_check = [
          np.array(1.0, dtype=np.float32),
          np.array(np.random.randn()).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)
          ]
          scipy_cdf_result = np.dot(
              mixture_weights, np.array(scipy_component_cdfs)
          )
          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 23 for calling the MixtureTest obj's underlying member method code with example usage: obj.testCdfScalarUnivariate() and returns: unknown