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.

DiscreteFactorGraph

A DiscreteFactorGraph is a factor graph consisting of DiscreteFactors, such as DecisionTreeFactor. It represents a joint probability distribution (or a general function) over a set of discrete variables as a product of factors:

P(X1,...,Xn)∝∏ifi(Scopei)P(X_1, ..., X_n) \propto \prod_i f_i(\text{Scope}_i)

where each fif_i is a factor over a subset of the variables (its scope).

This is an undirected graphical model (a Markov Random Field), and it is used to perform inference tasks like finding the most likely state (optimize) or computing marginals (via elimination).

Open In Colab

Creating a DiscreteFactorGraph

A DiscreteFactorGraph is created by adding DiscreteFactors. We will create a simple graph with three variables and three factors.

Manually Constructed DiscreteFactorGraph:

size: 3
factor 0:  f[ (x0,2), ]
 Choice(x0) 
 0 Leaf  0.3
 1 Leaf  0.7
factor 1:  f[ (x0,2), (y0,2), ]
 Choice(y0) 
 0 Choice(x0) 
 0 0 Leaf  0.5
 0 1 Leaf  0.1
 1 Choice(x0) 
 1 0 Leaf  0.2
 1 1 Leaf  0.9
factor 2:  f[ (y0,2), (z0,2), ]
 Choice(z0) 
 0 Choice(y0) 
 0 0 Leaf  0.8
 0 1 Leaf  0.3
 1 Choice(y0) 
 1 0 Leaf  0.1
 1 1 Leaf  0.6
Loading...

Rich Display in Jupyter

A factor graph can be displayed as a list of its component factor tables.

Loading...

Inference on a DiscreteFactorGraph

Unnormalized probability at (X=1, Y=1, Z=0): 0.1890

Most Probable Explanation (MPE) Solution:
DiscreteValues{8646911284551352320: 1, 8718968878589280256: 1, 8791026472627208192: 1}
--- Resulting Bayes Net after elimination ---
Loading...
Loading...
--- Resulting Bayes Tree after elimination ---
Loading...
Loading...