Probability: Help needed with simple bayesian network

Created on 1 Jul 2018  路  4Comments  路  Source: tensorflow/probability

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?

Most helpful comment

Any tutorial for building Bayesian networks ( directed acyclic graph ) using Edward2?

Thanks!

All 4 comments

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)?

Was this page helpful?
0 / 5 - 0 ratings