code: def test_mog(self):
      x_val = np.array([1.1, 1.2, 2.1, 4.4, 5.5, 7.3, 6.8], np.float32)
      z_val = np.array([0, 0, 0, 1, 1, 2, 2], np.int32)
      pi_val = np.array([0.2, 0.3, 0.5], np.float32)
      mu_val = np.array([1.0, 5.0, 7.0], np.float32)
  
      N = x_val.shape[0]
      K = z_val.max() + 1
  
      pi_alpha = 1.3 + np.zeros(K, dtype=np.float32)
      mu_sigma = 4.0
      sigmasq = 2.0**2
  
      pi = rvs.Dirichlet(pi_alpha)
      mu = rvs.Normal(0.0, mu_sigma, sample_shape=[K])
  
      x = rvs.ParamMixture(
          pi,
          {"loc": mu, "scale": tf.sqrt(sigmasq)},
          rvs.Normal,
          sample_shape=N,
      )
      z = x.cat
  
      mu_cond = ed.complete_conditional(mu)
      pi_cond = ed.complete_conditional(pi)
      z_cond = ed.complete_conditional(z)
  
      with self.test_session() as sess:
          pi_cond_alpha, mu_cond_mu, mu_cond_sigma, z_cond_p = sess.run(
              [
                  pi_cond.concentration,
                  mu_cond.loc,
                  mu_cond.scale,
                  z_cond.probs,
              ],
              {z: z_val, x: x_val, pi: pi_val, mu: mu_val},
          )
  
      true_pi = pi_alpha + np.unique(z_val, return_counts=True)[1]
      self.assertAllClose(pi_cond_alpha, true_pi)
      for k in range(K):
          sigmasq_true = (
              1.0 / 4**2 + 1.0 / sigmasq * (z_val == k).sum()
          ) ** -1
          mu_true = sigmasq_true * (
              1.0 / sigmasq * x_val[z_val == k].sum()
          )
          self.assertAllClose(np.sqrt(sigmasq_true), mu_cond_sigma[k])
          self.assertAllClose(mu_true, mu_cond_mu[k])
      true_log_p_z = (
          np.log(pi_val)
          - 0.5 / sigmasq * (x_val[:, np.newaxis] - mu_val) ** 2
      )
      true_log_p_z -= true_log_p_z.max(1, keepdims=True)
      true_p_z = np.exp(true_log_p_z)
      true_p_z /= true_p_z.sum(1, keepdims=True)
      self.assertAllClose(z_cond_p, true_p_z)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import edward
  import numpy
  import tensorflow
  from edward import models
label_desc: Use image node_id 16 for calling the test_conjugacy_class obj's underlying member method code with example usage: obj.test_mog() without return types