3
$\begingroup$

My goal is to infer the conditional probability tables (CPT) from the classic rain, sprinker, wet grass problem. Normally in this problem we know the CPTs and, given an observation like "the grass is wet" we query the bayes net for the marginal probabilities of rain or sprinkler.

Instead, I have a set of state observations of each node in the graph:

rain, sprinkler, wet grass
T, F, T
F, F, F
T, F, T
T, T, T

and so on.

I want to infer the CPTs using pymc but I'm having trouble thinking of how to express the graph in the model. In my mind I have the following:

import pymc as pm
import numpy as np
p_rain = pm.Beta('p_rain',1,1)
rain = pm.Bernoulli('rain', p_rain)
sprinkler = [pm.Dirichlet('sprinkler%i' % i, np.ones(2)) for i in xrange(2)]
grass_wet = [pm.Dirichlet('grass_wet%i' % i, np.ones(2)) for i in xrange(4)] 

This describes the CPTs seen here for this problem.

The difficulty I'm having now is thinking about how to use the observations I have to train this model. pymc will perform the sampling chain of drawing from p_rain which provides a realization of rain. This is then used to set the CPT of sprinkler which will return a conditional probability of sprinkler on or off and a bernoulli trial from that will return the state of the sprinkler which is then used, in conjunction with rain, to choose the conditional probability of grass_wet.

The steps of turning rain into a CPT from sprinkler and both of those into a CPT for grass_wet are missing in my code.

How does one specify that chain within two (I assume) pymc stochastic variables that will then be fed observations?

Any examples outside this of parameter learning that are applicable I'm up for. Or any examples in other Bayes net packages would help. I can work to translate what I see into my specific syntax/package.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.