code: def main(_):
      ed.set_seed(42)
  
      # DATA
      X_train, y_train = build_toy_dataset(FLAGS.N)
      X_test, y_test = build_toy_dataset(FLAGS.N)
  
      # MODEL
      X = tf.placeholder(tf.float32, [FLAGS.N, FLAGS.D])
      w = Normal(loc=tf.zeros(FLAGS.D), scale=tf.ones(FLAGS.D))
      b = Normal(loc=tf.zeros(1), scale=tf.ones(1))
      y = Normal(loc=ed.dot(X, w) + b, scale=tf.ones(FLAGS.N))
  
      # INFERENCE
      qw = Empirical(
          params=tf.get_variable("qw/params", [FLAGS.T, FLAGS.D])
      )
      qb = Empirical(params=tf.get_variable("qb/params", [FLAGS.T, 1]))
  
      inference = ed.SGHMC(
          {w: qw, b: qb}, data={X: X_train, y: y_train}
      )
      inference.run(step_size=1e-3)
  
      # CRITICISM
  
      # Plot posterior samples.
      sns.jointplot(
          qb.params.eval()[FLAGS.nburn : FLAGS.T : FLAGS.stride],
          qw.params.eval()[FLAGS.nburn : FLAGS.T : FLAGS.stride],
      )
      plt.show()
  
      # Posterior predictive checks.
      y_post = ed.copy(y, {w: qw, b: qb})
      # This is equivalent to
      # y_post = Normal(loc=ed.dot(X, qw) + qb, scale=tf.ones(FLAGS.N))
  
      print("Mean squared error on test data:")
      print(
          ed.evaluate(
              "mean_squared_error", data={X: X_test, y_post: y_test}
          )
      )
  
      print("Displaying prior predictive samples.")
      n_prior_samples = 10
  
      w_prior = w.sample(n_prior_samples).eval()
      b_prior = b.sample(n_prior_samples).eval()
  
      plt.scatter(X_train, y_train)
  
      inputs = np.linspace(-1, 10, num=400)
      for ns in range(n_prior_samples):
          output = inputs * w_prior[ns] + b_prior[ns]
          plt.plot(inputs, output)
  
      plt.show()
  
      print("Displaying posterior predictive samples.")
      n_posterior_samples = 10
  
      w_post = qw.sample(n_posterior_samples).eval()
      b_post = qb.sample(n_posterior_samples).eval()
  
      plt.scatter(X_train, y_train)
  
      inputs = np.linspace(-1, 10, num=400)
      for ns in range(n_posterior_samples):
          output = inputs * w_post[ns] + b_post[ns]
          plt.plot(inputs, output)
  
      plt.show()
  
file_path: edward/examples/bayesian_linear_regression.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import edward
  import matplotlib.pyplot
  import seaborn
  import numpy
  import tensorflow
  from edward.models import Normal, Empirical
label_desc: Use image node_id 2 for calling a global function with example usage: main(_) without return types