A SymbolicJunctionTree
(often used interchangeably with Clique Tree in GTSAM documentation) is a data structure used in multifrontal variable elimination. It’s derived from an EliminationTree
.
Key differences from an Elimination Tree:
- Nodes are Cliques: Each node in a Junction Tree represents a clique (a group of variables eliminated together), not just a single variable.
- Stores Factors: Nodes (
SymbolicCluster
objects) store the symbolic factors associated with the variables in that clique.
The Junction Tree organizes the factors and variables for efficient multifrontal elimination, which processes variables in these larger cliques simultaneously. The result of eliminating a Junction Tree is a SymbolicBayesTree
.
from gtsam import SymbolicJunctionTree, SymbolicEliminationTree, SymbolicFactorGraph, Ordering
from gtsam.symbol_shorthand import X, L
Creating a SymbolicJunctionTree¶
A Junction Tree is constructed from a SymbolicEliminationTree
.
# Create a factor graph
graph = SymbolicFactorGraph()
graph.push_factor(X(0))
graph.push_factor(X(0), X(1))
graph.push_factor(X(1), X(2))
graph.push_factor(X(0), L(1))
graph.push_factor(X(1), L(2))
# Define an elimination ordering
ordering = Ordering([L(1), L(2), X(0), X(1), X(2)])
# Construct the elimination tree first
elimination_tree = SymbolicEliminationTree(graph, ordering)
# Construct the junction tree from the elimination tree
junction_tree = SymbolicJunctionTree(elimination_tree)
# Print the tree structure (text representation)
junction_tree.print("Symbolic Junction Tree:\n")
Symbolic Junction Tree:
- (6) x1 x2
Symbolic Junction Tree:
| - (6) x0
Symbolic Junction Tree:
| | - (2) l1
Symbolic Junction Tree:
| - (2) l2
(Note: The SymbolicCluster
class represents the nodes within the Junction Tree, containing the factors and frontal/separator keys for that clique. Direct visualization is usually done via the resulting Bayes Tree.)