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.

Hybrid Data Association: Bayes Net and Bayes Tree

This short tutorial builds a one-scan data-association model for three objects with 2D positions, chooses a strong ordering, and solves the same hybrid posterior with sequential and multifrontal elimination.

Open In Colab

1. Decision tree factor

We first create the factor c(a0,a1,a2)c(a_0,a_1,a_2) drawn at the bottom of the factor graph. It is 1 when all three association variables have different values, and 0 otherwise.

GTSAM stores a DecisionTreeFactor as an algebraic decision tree. Each circular node branches on the value of one discrete variable, while each square leaf stores the resulting factor value. GTSAM puts the highest key at the root, so this tree starts with a2a_2. A branch ends early when its value is already known: for example, a2=a1a_2=a_1 immediately gives 0.

DecisionTreeFactor with 27 table entries
Decision tree for the all-different factor

2. Factor graph

The variables xi∈R2x_i\in\mathbb R^2 are object positions. Each variable ai∈{0,1,2}a_i\in\{0,1,2\} selects one measurement. The factors pip_i are Gaussian priors, lil_i are hybrid measurement likelihoods, and cc enforces that the three associations are all different.

Loading...
HybridGaussianFactorGraph with 7 factors

In the figure, cyan circles are the continuous position variables xix_i, and orange circles are the discrete association variables aia_i. Green squares are the Gaussian priors pip_i, red squares are the hybrid measurement likelihoods lil_i, and the gray square is the all-different factor cc.

3. Ordering

Hybrid elimination uses a strong ordering: eliminate all continuous positions before the discrete association variables.

Position 0: x0, x1, x2, a0, a1, a2

4. Bayes net: create and optimize

Sequential elimination produces a HybridBayesNet. Its discrete part factors as p(a2)p(a1∣a2)p(a0∣a1,a2)p(a_2)p(a_1\mid a_2)p(a_0\mid a_1,a_2), and each continuous conditional is p(xi∣ai,Z)p(x_i\mid a_i,Z). optimize() selects the most probable integrated association and then optimizes the continuous variables conditioned on it.

HybridBayesNet with 6 conditionals
association: (2, 0, 1)
x0: [ 0.1  -0.05]
x1: [2.9 0.1]
x2: [-0.05  3.05]

5. Bayes tree: create and optimize

Multifrontal elimination represents the same posterior as a HybridBayesTree. Here its root is one discrete clique over (a0,a1,a2)(a_0,a_1,a_2), with three continuous child cliques. The two optimize() calls must agree. The Plotly chart shows the shared discrete posterior p(A∣Z)p(A\mid Z) over the six legal associations.

HybridBayesTree with 4 cliques
association: (2, 0, 1)
x0: [ 0.1  -0.05]
x1: [2.9 0.1]
x2: [-0.05  3.05]

Below we show the probability distribution in the root clique.

Loading...