Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

DiscreteBayesNet

A DiscreteBayesNet is a BayesNet of DiscreteConditionals. It represents a joint probability distribution over a set of discrete variables as a product of conditional probabilities:

P(X1,...,Xn)=∏iP(Xi∣Parents(Xi))P(X_1, ..., X_n) = \prod_i P(X_i | \text{Parents}(X_i))

Each conditional P(Xi∣Parents(Xi))P(X_i | \text{Parents}(X_i)) is a gtsam.DiscreteConditional.

A DiscreteBayesNet is typically obtained by eliminating a DiscreteFactorGraph, but it can also be constructed manually.

Open In Colab

Creating a DiscreteBayesNet

We will manually construct the classic “Wet Grass” Bayes Net, which models the relationships between Cloudy, Sprinkler, Rain, and Wet Grass.

Manually Constructed DiscreteBayesNet:
DiscreteBayesNet
 
size: 4
conditional 0:  P( w0 | s0 r0 ):
 Choice(w0) 
 0 Choice(s0) 
 0 0 Choice(r0) 
 0 0 0 Leaf    1
 0 0 1 Leaf  0.1
 0 1 Choice(r0) 
 0 1 0 Leaf  0.1
 0 1 1 Leaf 0.01
 1 Choice(s0) 
 1 0 Choice(r0) 
 1 0 0 Leaf    0
 1 0 1 Leaf  0.9
 1 1 Choice(r0) 
 1 1 0 Leaf  0.9
 1 1 1 Leaf 0.99

conditional 1:  P( s0 | c0 ):
 Choice(s0) 
 0 Choice(c0) 
 0 0 Leaf  0.5
 0 1 Leaf  0.9
 1 Choice(c0) 
 1 0 Leaf  0.5
 1 1 Leaf  0.1

conditional 2:  P( r0 | c0 ):
 Choice(r0) 
 0 Choice(c0) 
 0 0 Leaf  0.8
 0 1 Leaf  0.2
 1 Choice(c0) 
 1 0 Leaf  0.2
 1 1 Leaf  0.8

conditional 3:  P( c0 ):
 Leaf  0.5

Loading...

Operations on DiscreteBayesNet

Joint Probability P(C=T,S=F,R=T,W=T): 0.3240
Log Probability: -1.1270

Sampled values:
DiscreteValues{7133701809754865664: 1, 8214565720323784704: 1, 8286623314361712640: 0, 8574853690513424384: 1}

MAP Solution (Optimize):
DiscreteValues{7133701809754865664: 1, 8214565720323784704: 1, 8286623314361712640: 0, 8574853690513424384: 1}

Displaying with Markdown/HTML

The rich display for a Bayes Net shows the CPT for each conditional.

Loading...