A SymbolicFactor
represents the connectivity (topology) between variables in a factor graph without any specific numerical function associated with it. It’s primarily to illustrate symbolic elimination. Internally, GTSAM does analyze the structure of other factor graph types without explicitly converting to a symbolic factor graph.
It inherits from gtsam.Factor
and stores the keys (indices) of the variables it connects.
import gtsam
from gtsam import SymbolicFactor
from gtsam.symbol_shorthand import X
# Example Keys
x0, x1, x2 = X(0), X(1), X(2)
Creating SymbolicFactors¶
SymbolicFactors can be created by specifying the keys they involve.
# Unary factor
f0 = SymbolicFactor(x0)
f0.print("Unary Factor f0: \n")
# Binary factor
f1 = SymbolicFactor(x0, x1)
f1.print("Binary Factor f1: \n")
# Ternary factor
f2 = SymbolicFactor(x1, x2, x0)
f2.print("Ternary Factor f2: \n")
# From a list of keys
keys = gtsam.KeyVector([x0, x1, x2])
f3 = SymbolicFactor.FromKeys(keys)
f3.print("Factor f3 from KeyVector: \n")
Unary Factor f0:
x0
Binary Factor f1:
x0 x1
Ternary Factor f2:
x1 x2 x0
Factor f3 from KeyVector:
x0 x1 x2