Inferensys

Glossary

Factor Graph

A factor graph is a bipartite graphical model that represents the factorization of a complex probability distribution, commonly used in modern SLAM back-ends to structure the optimization problem.
ML engineer managing model training cluster on laptop, GPU utilization visible, technical deep learning setup.
GRAPHICAL MODEL

What is a Factor Graph?

A factor graph is a bipartite graphical model that represents the factorization of a complex probability distribution, commonly used in modern SLAM back-ends to structure the optimization problem.

A factor graph is a bipartite graphical model that explicitly represents the factorization of a global function into a product of simpler local functions, or factors. In Simultaneous Localization and Mapping (SLAM), this global function is typically a joint probability distribution over unknown variables like robot poses and landmark positions. The graph's two node types are variable nodes (unknown states) and factor nodes (probabilistic constraints from sensor measurements), with edges connecting each factor to the variables it constrains. This structure cleanly separates the estimation problem from the specific sensor models.

The primary power of the factor graph formulation in robotics and computer vision is its efficiency for incremental smoothing and mapping. When a new sensor measurement arrives, it is added as a new factor node, and only affected parts of the graph need re-optimization. This makes it the backbone of modern graph-based SLAM and bundle adjustment systems. Optimization algorithms, like Gauss-Newton or Levenberg-Marquardt, operate directly on this graph to find the maximum a posteriori (MAP) estimate by minimizing the sum of squared residual errors encoded by the factors.

STRUCTURAL ELEMENTS

Key Components of a Factor Graph

A factor graph decomposes a complex probability distribution into a product of simpler local functions. Its structure directly encodes the dependencies and constraints within a SLAM optimization problem.

01

Variable Nodes

Represent the unknown quantities to be estimated. In SLAM, these are typically:

  • Robot poses at different timestamps (e.g., position and orientation).
  • Landmark positions (3D points or features in the map). Each node holds a belief (probability distribution) about its state, which is refined during optimization.
02

Factor Nodes

Encode constraints and measurements that connect variables. Each factor represents a local function in the factorization of the joint probability distribution.

  • Odometry factors model motion between consecutive poses.
  • Landmark observation factors connect a pose to a landmark based on a sensor measurement (e.g., a camera projection).
  • Loop closure factors impose strong constraints when a place is re-recognized, correcting accumulated drift.
  • Prior factors anchor the graph with absolute information (e.g., a known starting pose).
03

Edges (Connections)

Edges connect factor nodes to the variable nodes they constrain. An edge exists only between a factor and a variable. This bipartite structure makes dependencies explicit:

  • A unary factor connects to one variable (e.g., a prior).
  • A binary factor connects to two variables (e.g., an odometry constraint between two poses).
  • A higher-order factor can connect to multiple variables (e.g., a visual reprojection factor linking one landmark and two observing poses).
04

The Joint Probability Distribution

The entire factor graph represents the factorization of the system's posterior probability. If X is the set of all variables and Z is the set of all measurements/factors, the graph models: P(X | Z) ∝ ∏ᵢ fᵢ(Xᵢ) where each fᵢ is a factor function over a subset of variables Xᵢ. In SLAM, this is typically a Maximum A Posteriori (MAP) estimation problem: finding the variable values that maximize this product.

05

The Optimization Back-End

The factor graph structure is solved via non-linear least squares optimization. Under the assumption of Gaussian noise models, each factor corresponds to a squared error term in a cost function. The optimization (e.g., using Gauss-Newton or Levenberg-Marquardt algorithms) adjusts the variable node estimates to minimize the sum of these errors, reconciling all constraints. Libraries like g2o, GTSAM, and Ceres Solver are built to efficiently perform this inference on factor graphs.

06

Comparison to Pose Graphs

A pose graph is a specific, simplified type of factor graph used in SLAM.

  • Pose Graph: Variable nodes are only robot poses. Factors represent constraints between poses (odometry, loop closures). Landmarks are marginalized out.
  • Full Factor Graph: Variable nodes include both poses and landmarks. Factors include direct observation constraints between poses and landmarks. Pose graphs are more compact; full factor graphs preserve more information but are larger. Modern graph SLAM systems often use a hybrid or sliding-window approach.
GRAPHICAL MODELS

How Factor Graphs Work in SLAM

A factor graph is the core data structure used in modern optimization-based SLAM back-ends to represent and solve the underlying inference problem.

A factor graph is a bipartite graphical model that explicitly represents the factorization of a complex probability distribution, structuring the maximum a posteriori (MAP) estimation problem central to Graph SLAM. In SLAM, nodes represent unknown random variables (robot poses and landmark positions), while factors represent probabilistic constraints (sensor measurements and motion models) that connect them. This factorization allows the joint probability of all variables given all measurements to be broken into a product of simpler, local functions.

The graph is optimized by minimizing the negative log-likelihood of all factors, which translates to solving a non-linear least squares problem. Each factor encodes a cost function penalizing deviations from its associated measurement, such as odometry or a landmark observation. Back-end optimization algorithms, like Gauss-Newton or Levenberg-Marquardt, efficiently exploit the graph's sparse connectivity to compute the optimal configuration of all poses and map points, correcting for accumulated drift and enforcing global consistency through loop closure constraints.

IMPLEMENTATIONS

Examples and Frameworks

Factor graphs are a foundational data structure in modern probabilistic robotics. This section details their practical implementations, key software frameworks, and their specific role in structuring the optimization problems central to SLAM.

01

The Core SLAM Back-End

In modern Graph SLAM, the factor graph is the explicit data structure for the back-end optimization. It encodes the complete inference problem:

  • Nodes (Variables): Represent unknown quantities—robot poses (x1, x2,...) and landmark positions (l1, l2,...).
  • Factors (Constraints): Represent probabilistic measurements connecting nodes. Each factor defines a cost function based on sensor models.
  • Examples: An odometry factor connects two consecutive pose nodes. A landmark observation factor connects a pose node and a landmark node. The goal is to find the variable assignments (the map and trajectory) that maximize the product of all factors, which is equivalent to minimizing the sum of negative log-likelihoods—a non-linear least squares problem.
02

iSAM2: Incremental Smoothing and Mapping

iSAM2 (Incremental Smoothing and Mapping 2) is a canonical algorithm for real-time factor graph optimization in SLAM. Its key innovation is incremental and bayesian tree-based updating.

  • Incremental Solving: Instead of re-solving the entire graph from scratch, iSAM2 efficiently updates the solution as new factors (measurements) are added, which is critical for online robotics.
  • Elimination and the Bayes Tree: It uses variable elimination to transform the factor graph into a Bayes tree, a data structure that allows for efficient re-linearization and updates only to affected parts of the solution.
  • Impact: This algorithm enabled practical, large-scale SLAM in real-time and is the optimization engine behind frameworks like GTSAM.
06

From Pose Graphs to Dense Factors

Factor graphs scale in complexity based on the problem formulation:

  • Pose Graph: A simplified factor graph containing only pose variables. Edges are odometry and loop closure constraints. This is the core of pose graph SLAM after marginalizing out landmarks.
  • Landmark-based Graph: Includes both pose and landmark variables, with factors for all observations. This is the full Bundle Adjustment problem.
  • Dense Factors: Modern approaches use photometric error or point-to-plane ICP error as factors, creating a graph with a very large number of constraints (one per pixel or point). This moves from sparse feature-based to direct or dense SLAM formulations, where the factor graph principle remains the same but the computational challenge increases significantly.
FACTOR GRAPH

Frequently Asked Questions

A factor graph is a core data structure in modern probabilistic robotics, providing the mathematical scaffolding for solving complex state estimation problems like SLAM. These questions address its fundamental mechanics, role, and practical implementation.

A factor graph is a bipartite graphical model that explicitly represents the factorization of a complex, global probability distribution into a product of simpler, local functions called factors. It works by structuring an inference problem—like estimating a robot's trajectory and a map in SLAM—as a graph with two types of nodes: variable nodes (representing unknown states like robot poses and landmark positions) and factor nodes (representing probabilistic constraints or measurements connecting those variables). The graph's connectivity encodes which variables are involved in each measurement. Solving the estimation problem then becomes the task of finding the variable values that maximize the product of all factors, which is typically achieved through non-linear least squares optimization.

For example, in a SLAM context, a factor graph might have:

  • Variable Nodes: pose_1, pose_2, landmark_A
  • Factor Nodes: An odometry factor connecting pose_1 and pose_2 (from wheel encoders/IMU), and a landmark observation factor connecting pose_2 and landmark_A (from a camera or LiDAR). The optimizer adjusts the values of the variable nodes to best satisfy all the constraints imposed by the factors.
Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.