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.

ExpressionFactorGraph

This API walkthrough introduces the wrapped classes ExpressionFactorGraph declared by ExpressionFactorGraph.h and demonstrates their principal Python operations.

Open In Colab
import gtsam
import numpy as np
from gtsam.symbol_shorthand import L, X

Overview

The ExpressionFactorGraph class in GTSAM is a specialized factor graph designed to work with expressions. It extends the capabilities of a standard factor graph by allowing factors created from GTSAM expressions, that implement automatic differentiation. It creates ExpressionFactors.

Adding Expression Factors

use addExpressionFactor: This method allows the user to add a new factor to the graph based on a symbolic expression. The expression defines the relationship between the variables involved in the factor.

  template<typename T>
  void addExpressionFactor(const Expression<T>& h, const T& z,
      const SharedNoiseModel& R) {
    using F = ExpressionFactor<T>;
    push_back(std::allocate_shared<F>(Eigen::aligned_allocator<F>(), R, z, h));
  }

Python wrapper walkthrough

The following cell exercises the wrapped API directly.

print(gtsam.ExpressionFactorGraph.__init__.__doc__)
print([name for name in dir(gtsam.ExpressionFactorGraph) if not name.startswith('_')])