I've been trying to convert the classic sprinkler/rain network to tfp and i'm struggling with the inference step.
Here's the model I have so far:
cloudy = ed.Bernoulli(probs=0.5)
p_sprinkler = tf.where(tf.cast(cloudy, tf.bool), 0.5, 0.1)
sprinkler = ed.Bernoulli(probs=p_sprinkler)
p_rain = tf.where(tf.cast(cloudy, tf.bool), 0.2, 0.8)
rain = ed.Bernoulli(probs=p_rain)
p_wetgrass = tf.where(tf.cast(sprinkler, tf.bool),
# Sprinkler=F
tf.where(tf.cast(rain, tf.bool),
# Sprinkler=F, Rain=F
0.0,
# Sprinkler=F, Rain=T
0.9
),
# Sprinkler=T
tf.where(tf.cast(rain, tf.bool),
# Sprinkler=T, Rain=F
0.9,
# Sprinkler=T, Rain=T
0.99
))
wetgrass = ed.Bernoulli(probs=p_wetgrass)
In Edward I can then do VI using something like:
# Compute P(rain | wetgrass)
q_rain = ed.Bernoulli(probs=tf.nn.sigmoid(tf.Variable(tf.random_normal([]))))
inf = edi.KLpq({rain: q_rain}, data={wetgrass: tf.constant(1, dtype=tf.int32)})
inf.run(n_samples=50)
print(q_rain.probs.eval())
What is the equivalent in tfp?
Does the Edward -> Edward2 doc help here?:
https://github.com/tensorflow/probability/blob/master/tensorflow_probability/python/edward2/Upgrading_From_Edward_To_Edward2.md
Any tutorial for building Bayesian networks ( directed acyclic graph ) using Edward2?
Thanks!
@srvasude That link is dead?
@philbinj Did you make headway on this (trying to do the same)?
Most helpful comment
Any tutorial for building Bayesian networks ( directed acyclic graph ) using Edward2?
Thanks!