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.

HybridFactorGraph

Open In Colab

HybridFactorGraph is a gtsam.FactorGraph specifically designed to hold gtsam.Factor types that can represent hybrid discrete-continuous systems. While it can store any factor type (like its base class), it provides convenience methods for working with hybrid systems.

It serves as a base class for more specialized hybrid factor graphs:

  • gtsam.HybridGaussianFactorGraph: Holds factors that are either Gaussian, discrete, or hybrid Gaussian (linear conditional Gaussians dependent on discrete modes). Result of linearizing a HybridNonlinearFactorGraph.

  • gtsam.HybridNonlinearFactorGraph: Holds factors that can be nonlinear, discrete, or hybrid nonlinear (nonlinear functions dependent on discrete modes).

This notebook focuses on the base HybridFactorGraph interface. See the derived classes for specific elimination and usage examples.

Initialization and Adding Factors

HybridFactorGraph size: 4

Graph Contents: 
size: 4
factor 0: PriorFactor on x0
  prior mean:  (0, 0, 0)
  noise model: unit (3) 
factor 1:  f[ (d0,2), (d1,2), ]
 Choice(d1) 
 0 Choice(d0) 
 0 0 Leaf  0.1
 0 1 Leaf  0.2
 1 Choice(d0) 
 1 0 Leaf  0.9
 1 1 Leaf  0.8
factor 2: 
Hybrid [x5; d2]{
 Choice(d2) 
 0 Leaf :
  A[x5] = [
	2
]
  b = [ 0 ]
  Noise model: unit (1) 
scalar: 0

 1 Leaf :
  A[x5] = [
	0.5
]
  b = [ 1 ]
  Noise model: unit (1) 
scalar: 0

}
factor 3: 
  A[x6] = [
	1
]
  b = [ 0 ]
  Noise model: unit (1) 
Loading...

Inspecting Keys

HybridFactorGraph provides methods to easily retrieve sets of discrete and continuous keys present in the graph.

Discrete KeySet: d0d1d2
Continuous KeySet: x0x5x6
All Keys (including nonlinear): d0d1d2x0x5x6

Error Calculation

The error method sums the errors of all contained factors, assuming appropriate Values (or HybridValues) are provided. The exact interpretation depends on the factor types (nonlinear error, Gaussian negative log-likelihood, etc.).


Evaluating error with HybridValues:
HybridValues: 
  Continuous: 2 elements
  x5: 0.1
  x6: 0.2
  Discrete: (d0, 0)(d1, 1)(d2, 0)
  Nonlinear
Values with 2 values:
Value x0: (gtsam::Pose2)
(0.1, 0, 0)

Value x1: (gtsam::Pose2)
(1.1, 0, 0)


Total graph error: 0.15036051565782632

Further Operations

Operations like elimination (eliminateSequential, eliminateMultifrontal) are typically performed on the more specific derived classes (HybridGaussianFactorGraph, HybridNonlinearFactorGraph). See their documentation for details.