A SymbolicConditional
represents a conditional probability distribution P(Frontals | Parents) in purely symbolic form. It only stores the keys of the frontal variables and the parent variables, without any associated numerical probability function.
SymbolicConditional
objects are typically produced as the result of symbolic elimination on a SymbolicFactorGraph
. A collection of these forms a SymbolicBayesNet
.
from gtsam import SymbolicConditional
from gtsam.symbol_shorthand import X, L
Creating SymbolicConditionals¶
Conditionals specify frontal (conditioned) variables and parent variables.
# P(X(0))
c0 = SymbolicConditional(X(0))
c0.print("P(X(0)): ")
print(f" Nr Frontals: {c0.nrFrontals()}, Nr Parents: {c0.nrParents()}\n")
# P(X(1) | X(0))
c1 = SymbolicConditional(X(1), X(0))
c1.print("P(X(1) | X(0)): ")
print(f" Nr Frontals: {c1.nrFrontals()}, Nr Parents: {c1.nrParents()}\n")
# P(X(2) | X(0), X(1))
c2 = SymbolicConditional(X(2), X(0), X(1))
c2.print("P(X(2) | X(0), X(1)): ")
print(f" Nr Frontals: {c2.nrFrontals()}, Nr Parents: {c2.nrParents()}\n")
# P(L(1) | X(0), X(1))
c3 = SymbolicConditional(L(1), X(0), X(1))
c3.print("P(L(1) | X(0), X(1)): ")
print(f" Nr Frontals: {c3.nrFrontals()}, Nr Parents: {c3.nrParents()}\n")
# Create from keys and number of frontals, e.g. P(X(2), L(1) | X(0), X(1))
# Keys = [Frontals..., Parents...]
c4 = SymbolicConditional.FromKeys([X(2), L(1), X(0), X(1)], 2)
c4.print("P(X(2), L(1) | X(0), X(1)): ")
print(f" Nr Frontals: {c4.nrFrontals()}, Nr Parents: {c4.nrParents()}")
P(X(0)): P( x0)
Nr Frontals: 1, Nr Parents: 0
P(X(1) | X(0)): P( x1 | x0)
Nr Frontals: 1, Nr Parents: 1
P(X(2) | X(0), X(1)): P( x2 | x0 x1)
Nr Frontals: 1, Nr Parents: 2
P(L(1) | X(0), X(1)): P( l1 | x0 x1)
Nr Frontals: 1, Nr Parents: 2
P(X(2), L(1) | X(0), X(1)): P( x2 l1 | x0 x1)
Nr Frontals: 2, Nr Parents: 2