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.

DecisionTreeFactor

A DecisionTreeFactor represents a function over a set of discrete variables, f(X1,X2,...,Xn)f(X_1, X_2, ..., X_n). It is a versatile building block for representing potentials or probabilities in discrete factor graphs.

Internally, it uses an AlgebraicDecisionTree (ADT) to store the function’s values. This representation can be very efficient, especially for sparse factors where many assignments have the same value (e.g., zero).

DecisionTreeFactor is the base class for more specialized factors like DiscreteConditional.

Open In Colab

Creating a DecisionTreeFactor

A factor is defined by its DiscreteKeys (the variables it depends on) and a table of values. The table specifies the factor’s output for every possible assignment of its variables. The values in the table are ordered such that the last key varies fastest.

--- Factor f1 from string ---
DecisionTreeFactor
 f[ (a0,2), (b0,2), ]
 Choice(b0) 
 0 Choice(a0) 
 0 0 Leaf    1
 0 1 Leaf    3
 1 Choice(a0) 
 1 0 Leaf    2
 1 1 Leaf    4

--- Factor f2 from vector ---
DecisionTreeFactor
 f[ (a0,2), ]
 Choice(a0) 
 0 Leaf  0.8
 1 Leaf  0.2

Operations on DecisionTreeFactor

Value of f1 at A=1, B=0: 3.0

--- Product Factor f3 = f1 * f2 ---
Loading...

Visualization

We can visualize the underlying Algebraic Decision Tree structure. This shows how the factor’s values are stored efficiently. Each path from the root to a leaf corresponds to an assignment, and the leaf holds the value.

Loading...

Rich Display in Jupyter

In a notebook, factors are displayed as easy-to-read tables.

Loading...