Created
February 2, 2017 07:57
-
-
Save AashishTiwari/3450447625209f809332507b568b9f0a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
"""Normal posterior. | |
""" | |
from __future__ import absolute_import | |
from __future__ import division | |
from __future__ import print_function | |
import edward as ed | |
import tensorflow as tf | |
from edward.models import Normal | |
from edward.stats import norm | |
class NormalPosterior: | |
"""p(x, z) = p(z) = p(z | x) = Normal(z; mu, sigma)""" | |
def log_prob(self, xs, zs): | |
return norm.logpdf(zs['z'], 1.0, 1.0) | |
ed.set_seed(42) | |
model = NormalPosterior() | |
qz_mu = tf.Variable(tf.random_normal([])) | |
qz_sigma = tf.nn.softplus(tf.Variable(tf.random_normal([]))) | |
qz = Normal(mu=qz_mu, sigma=qz_sigma) | |
inference = ed.KLqp({'z': qz}, model_wrapper=model) | |
inference.run(n_iter=250) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@AashishTiwari