code: def main(_):
      # data
      J = 8
      data_y = np.array([28, 8, -3, 7, -1, 1, 18, 12])
      data_sigma = np.array([15, 10, 16, 11, 9, 11, 10, 18])
  
      # model definition
      mu = Normal(0.0, 10.0)
      logtau = Normal(5.0, 1.0)
      theta_prime = Normal(tf.zeros(J), tf.ones(J))
      sigma = tf.placeholder(tf.float32, J)
      y = Normal(
          mu + tf.exp(logtau) * theta_prime, sigma * tf.ones([J])
      )
  
      data = {y: data_y, sigma: data_sigma}
  
      # ed.KLqp inference
      with tf.variable_scope("q_logtau"):
          q_logtau = Normal(
              tf.get_variable("loc", []),
              tf.nn.softplus(tf.get_variable("scale", [])),
          )
  
      with tf.variable_scope("q_mu"):
          q_mu = Normal(
              tf.get_variable("loc", []),
              tf.nn.softplus(tf.get_variable("scale", [])),
          )
  
      with tf.variable_scope("q_theta_prime"):
          q_theta_prime = Normal(
              tf.get_variable("loc", [J]),
              tf.nn.softplus(tf.get_variable("scale", [J])),
          )
  
      inference = ed.KLqp(
          {logtau: q_logtau, mu: q_mu, theta_prime: q_theta_prime},
          data=data,
      )
      inference.run(n_samples=15, n_iter=60000)
      print("====  ed.KLqp inference ====")
      print("E[mu] = %f" % (q_mu.mean().eval()))
      print("E[logtau] = %f" % (q_logtau.mean().eval()))
      print("E[theta_prime]=")
      print((q_theta_prime.mean().eval()))
      print("====  end ed.KLqp inference ====")
      print("")
      print("")
  
      # HMC inference
      S = 400000
      burn = S // 2
  
      hq_logtau = Empirical(tf.get_variable("hq_logtau", [S]))
      hq_mu = Empirical(tf.get_variable("hq_mu", [S]))
      hq_theta_prime = Empirical(
          tf.get_variable("hq_thetaprime", [S, J])
      )
  
      inference = ed.HMC(
          {logtau: hq_logtau, mu: hq_mu, theta_prime: hq_theta_prime},
          data=data,
      )
      inference.run()
  
      print("====  ed.HMC inference ====")
      print("E[mu] = %f" % (hq_mu.params.eval()[burn:].mean()))
      print("E[logtau] = %f" % (hq_logtau.params.eval()[burn:].mean()))
      print("E[theta_prime]=")
      print(hq_theta_prime.params.eval()[burn:,].mean(0))
      print("====  end ed.HMC inference ====")
      print("")
      print("")
  
file_path: edward/examples/eight_schools/eight_schools.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import edward
  import tensorflow
  import numpy
  from edward.models import Normal, Empirical
label_desc: Use image node_id 1 for calling a global function with example usage: main(_) without return types