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.

HybridGaussianFactor

Open In Colab

A HybridGaussianFactor represents a factor where the underlying probability distribution is Gaussian, but which Gaussian distribution applies depends on the assignment of a set of discrete variables. It inherits from HybridFactor.

Mathematically, it represents a factor ϕ(X,M)\phi(X, M) over continuous variables XX and discrete variables MM, defined as:

ϕ(X,M=m)∝exp⁡(−Em−12∣∣AmX−bm∣∣2)\phi(X, M=m) \propto \exp(-E_m - \frac12 ||A_m X - b_m||^2)

where for each discrete assignment mm, we have a standard Gaussian factor defined by AmA_m, bmb_m (and an associated noise model, implicitly defining the Mahalanobis distance), plus an optional scalar energy term EmE_m.

Internally, it uses a DecisionTree<Key, GaussianFactorValuePair> to store the different Gaussian factor components (GaussianFactor::shared_ptr) and their associated scalar energies (double), indexed by the DiscreteKeys.

These factors typically arise from:

  1. Linearizing a HybridNonlinearFactor.

  2. Representing sensor models with discrete operating modes (e.g., a sensor that works differently in rain vs. sun).

  3. As intermediate results during hybrid elimination.

Initialization

Can be initialized with one or more discrete keys and the corresponding Gaussian factor components.

HybridGaussianFactor (factors only):
HybridGaussianFactor

Hybrid [x0; d0]{
 Choice(d0) 
 0 Leaf :
  A[x0] = [
	1
]
  b = [ 0 ]
  Noise model: unit (1) 
scalar: 0

 1 Leaf :
  A[x0] = [
	1
]
  b = [ 5 ]
isotropic dim=1 sigma=2
scalar: 0

}

HybridGaussianFactor (factors + scalars):
HybridGaussianFactor

Hybrid [x0; d0]{
 Choice(d0) 
 0 Leaf :
  A[x0] = [
	1
]
  b = [ 0 ]
  Noise model: unit (1) 
scalar: 0.356675

 1 Leaf :
  A[x0] = [
	1
]
  b = [ 5 ]
isotropic dim=1 sigma=2
scalar: 1.20397

}

In C++ you can create HybridGaussianFactors with multiple discrete keys as well, but that capability is not yet exposed in the wrapper.

Accessing Components

You can retrieve the underlying decision tree structure and select a specific Gaussian factor component based on a discrete assignment.


Factor/Scalar pair for D0=0:
Factor:
  A[x0] = [
	1
]
  b = [ 0 ]
  Noise model: unit (1) 
Scalar: 0.35667494393873245

Factor/Scalar pair for D0=1:
Factor:
  A[x0] = [
	1
]
  b = [ 5 ]
isotropic dim=1 sigma=2
Scalar: 1.2039728043259361

Error Calculation (error, errorTree)

  • error(HybridValues): Calculates the total error Em+12∣∣AmX−bm∣∣2E_m + \frac{1}{2} ||A_m X - b_m||^2 for the specified continuous values XX and discrete assignment M=mM=m.

  • errorTree(VectorValues): Calculates the Gaussian error term 12∣∣AmX−bm∣∣2\frac{1}{2} ||A_m X - b_m||^2 for the given continuous values XX across all discrete assignments mm, returning the results as an AlgebraicDecisionTree indexed by the discrete keys MM. It also adds the scalar energy EmE_m to each leaf.


Error for X0=0.1, D0=0: 0.36167494393873245 (Expected ~ 0.36167494393873245)
Error for X0=4.0, D0=1: 1.3289728043259361 (Expected ~ 1.3289728043259361)

Error Tree for X0=1.0:
ErrorTree
 Choice(d0) 
ErrorTree
 0 Leaf 0.85667494
ErrorTree
 1 Leaf 3.2039728
(Expected Leaf 0 ~ 0.8566749439387324)
(Expected Leaf 1 ~ 3.203972804325936)

Restriction (restrict)

Fixes the discrete variables according to a given assignment, returning the corresponding GaussianFactor component (as a gtsam.Factor::shared_ptr).


Restricted Factor for D0=1:
Continuous [x0]{
 Leaf :
  A[x0] = [
	1
]
  b = [ 5 ]
isotropic dim=1 sigma=2
scalar: 1.20397

}