Inferensys

Glossary

Factor Graph

A factor graph is a bipartite graphical model that represents the factorization of a complex probability distribution, commonly used in robotics to structure and solve large-scale state estimation problems like SLAM and bundle adjustment.
ML engineer managing model versions on laptop, version history visible, technical Git-like workflow.
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 robotics to structure and solve large-scale state estimation problems like SLAM and bundle adjustment.

A factor graph is a bipartite graphical model that explicitly represents the factorization of a global function into a product of local functions, or factors. In robotics and state estimation, this global function is typically a joint probability distribution over unknown variables (e.g., robot poses, landmark positions). The graph's two node types are variable nodes (circles, representing unknown states) and factor nodes (squares, representing probabilistic constraints from sensor measurements or motion models). This structure cleanly separates the unknowns from the constraints that connect them.

The primary computational benefit of the factor graph formulation is that it exposes the sparse structure inherent in many robotics problems, such as Simultaneous Localization and Mapping (SLAM). This sparsity enables the use of highly efficient nonlinear optimization techniques, like Gauss-Newton or Levenberg-Marquardt, to perform Maximum A Posteriori (MAP) estimation. By converting the inference problem into a graph, algorithms can exploit the localized connectivity—where a robot pose is only linked to a small subset of landmarks—to solve for thousands of variables in real-time.

GRAPHICAL MODEL DECOMPOSITION

Key Components of a Factor Graph

A factor graph decomposes a complex estimation problem into a set of local, interconnected functions. Understanding its core components is essential for implementing algorithms like SLAM and bundle adjustment.

01

Factor Nodes

A factor node (often drawn as a square) represents a local function in the global factorization. Each factor encodes a probabilistic constraint or measurement relating to a subset of variables. In robotics, common factors include:

  • Prior Factor: Anchors a variable with an initial guess.
  • Motion Model Factor: Connects consecutive robot poses based on odometry or IMU data.
  • Measurement Factor: Connects a pose variable to a landmark variable based on a sensor observation (e.g., a camera projection).
  • Loop Closure Factor: Adds a constraint between non-consecutive poses when a previously visited location is recognized. The product of all factor functions defines the joint probability distribution over all variables.
02

Variable Nodes

A variable node (often drawn as a circle) represents an unknown state to be estimated. In robotic state estimation, these are typically continuous random variables. Key examples are:

  • Pose Variables: Represent the robot's position and orientation (e.g., SE(2) or SE(3)) at specific timesteps.
  • Landmark Variables: Represent the 3D position of persistent features or objects in the environment.
  • Velocity/Bias Variables: Often included when fusing inertial data. Each variable node is connected to every factor node that depends on it. The graph structure visually encodes the sparsity of the problem—a variable is only connected to the few factors that constrain it.
03

Edges (Connections)

An edge in a factor graph is an undirected connection between a single factor node and a single variable node. It has no weight or direction of its own. Its sole purpose is to indicate that the connected factor's function depends on the state of the connected variable. The complete set of edges defines the factorization of the joint distribution. For example, a factor (f_k) connected to variables (x_1) and (x_2) means the global probability distribution factors as (... f_k(x_1, x_2) ...). This bipartite connectivity is what allows efficient inference via message-passing algorithms.

04

The Joint Probability Distribution

The entire factor graph represents the factorization of a joint probability distribution over all variables. Given a set of variable nodes (X) and factor nodes (F), the distribution is proportional to the product of all factors: [ p(X) \propto \prod_{f_k \in F} f_k(X_k) ] where (X_k) is the subset of variables connected to factor (f_k). In robotics, this is typically a posterior distribution (p(\text{State} | \text{Measurements})). Solving the estimation problem means finding the variable values that maximize this posterior (MAP estimation) or computing marginal distributions. The factorization into many small, local functions is what makes solving this large-scale problem computationally tractable.

05

Inference via Message Passing (Belief Propagation)

Belief Propagation is a fundamental algorithm for performing inference on factor graphs. It works by passing messages along the edges between variable and factor nodes. A message represents a belief about the receiving node's state, informed by a part of the graph. The process involves:

  • Variable-to-Factor Message: A variable sends a summary of beliefs from all other connected factors.
  • Factor-to-Variable Message: A factor sends a message to a variable based on its own function and messages from all other connected variables. After messages converge, the belief (estimated marginal distribution) at each variable node is the product of all incoming messages. For linear-Gaussian models, this is equivalent to sparse linear solving; for non-linear problems, it's the foundation of algorithms like iSAM2.
06

Comparison to Bayes Nets and Markov Random Fields

Factor graphs are a more general and explicit representation than other graphical models:

  • vs. Bayesian Networks: Bayes nets are directed, acyclic graphs representing causal relationships and conditional dependencies. A Bayes net can be converted to a factor graph where each conditional probability table becomes a factor. Factor graphs are often preferred for inference because they make the factorization for message-passing explicit.
  • vs. Markov Random Fields (MRFs): MRFs are undirected graphs where edges represent direct probabilistic interactions between variables. An MRF's clique potentials correspond directly to factors in a factor graph. The factor graph provides a finer-grained view, breaking down clique potentials into singular functions and explicitly showing the bipartite structure crucial for algorithm derivation. This universality makes the factor graph a unifying language for probabilistic inference across many domains.
GRAPHICAL MODELS

How Factor Graphs Work in State Estimation

A factor graph is a bipartite graphical model that structures complex estimation problems by representing the factorization of a joint probability distribution, enabling efficient inference in robotics and computer vision.

A factor graph is a bipartite graphical model that represents the factorization of a complex probability distribution, decomposing a global function into a product of simpler local functions called factors. In robotics and computer vision, this global function is typically a posterior probability over unknown states (like robot poses and landmark positions) given sensor measurements. The graph's two node types are variable nodes (representing unknown states) and factor nodes (representing constraints from measurements or motion models), with edges connecting factors to the variables they depend on. This explicit factorization makes the underlying sparsity of the problem visually apparent and computationally exploitable.

The power of the factor graph lies in its use for inference, most commonly via nonlinear optimization to perform Maximum A Posteriori (MAP) estimation. Algorithms like Gauss-Newton or Levenberg-Marquardt solve for the most likely configuration of all variable nodes by minimizing the sum of squared errors from the factors. This framework is the backbone of modern graph-based SLAM and bundle adjustment, where adding a new sensor measurement simply inserts a new factor node into the graph. The sparse structure allows for the use of highly efficient linear solvers, enabling real-time estimation in large-scale environments by focusing computation only on the parts of the graph that are connected.

FACTOR GRAPH

Primary Applications in Robotics and AI

A factor graph is a bipartite graphical model that represents the factorization of a complex probability distribution. In robotics and AI, it provides a unifying framework for structuring and solving large-scale state estimation problems by breaking them into local constraints.

01

Backbone of Modern SLAM

Factor graphs are the de facto standard representation for modern Simultaneous Localization and Mapping (SLAM) systems. They elegantly model the problem by connecting pose variables (robot positions) to landmark variables (map points) via observation factors. This structure allows for efficient incremental optimization as the robot explores, making systems like iSAM2 possible. The graph explicitly shows loop closure constraints, which are crucial for correcting accumulated odometry drift.

02

Sensor Fusion Unifier

Factor graphs provide a unified probabilistic framework for tightly-coupled sensor fusion. Different sensor modalities contribute distinct factors to the same graph:

  • IMU Preintegration Factors from inertial measurements.
  • Visual Reprojection Factors from camera observations.
  • LiDAR Scan Matching Factors from point cloud alignment.
  • GPS Prior Factors for global anchoring. By adding all constraints to a single graph, the maximum a posteriori (MAP) estimate is found by minimizing the sum of all factor errors, optimally combining heterogeneous data.
03

Efficient Sparse Optimization

The power of factor graphs lies in their sparsity. Each factor typically connects only to a small subset of variables (e.g., a camera observation connects only to the pose from which it was taken and the landmarks it sees). This results in a sparse Jacobian and Hessian matrix during nonlinear optimization (like Gauss-Newton or Levenberg-Marquardt). Solvers exploit this sparsity using Cholesky or QR factorization on a Bayes tree or clique tree, enabling real-time optimization for thousands of variables.

04

Dynamic and Lifelong Mapping

Beyond single-session SLAM, factor graphs enable lifelong and dynamic mapping. The graph can be extended over multiple sessions, with new factors added for re-localization. For dynamic environments, semantic labels can be attached to variables, and parts of the graph can be marginalized or updated. This makes them suitable for long-term autonomy in changing warehouses or cities, where the map must be continuously refined without starting from scratch.

05

Beyond Pose Graphs: Dense & Semantic

While classic pose graphs are a subset, full factor graphs can model richer problems:

  • Bundle Adjustment: Dense structure-from-motion by connecting every camera pose to many 3D point variables.
  • Calibration: Intrinsic and extrinsic sensor parameters can be included as variables optimized jointly with the state.
  • Semantic SLAM: Adding object-level landmarks with shape and class attributes, connected via detection factors.
  • Multi-Robot SLAM: Merging graphs from different agents by identifying shared landmark variables, enabling collaborative mapping.
06

Connection to Inference Algorithms

The factor graph representation directly exposes connections to fundamental inference algorithms:

  • The sum-product algorithm for marginalization (computing beliefs over variables).
  • The max-product algorithm for finding the MAP estimate.
  • Bayesian networks and Markov random fields can be converted to factor graphs, providing a common language. In robotics, optimization dominates, but this theoretical foundation links SLAM back to general probabilistic graphical models, showing it as a specific instance of structured probabilistic inference.
COMPARATIVE ANALYSIS

Factor Graphs vs. Other Estimation Frameworks

A feature comparison of factor graphs against other common probabilistic frameworks used for state estimation and sensor fusion in robotics and embodied intelligence.

Feature / MetricFactor GraphKalman Filter (EKF/UKF)Particle FilterBatch Optimization (e.g., Bundle Adjustment)

Core Representation

Bipartite graph of factors (measurements/priors) and variables (states)

Mean and covariance (Gaussian distribution)

Set of weighted particles (non-parametric distribution)

Single large nonlinear least-squares problem

Inference Method

Sum-Product or Max-Sum (for MAP) via message passing; often solved as nonlinear least squares

Recursive prediction and update (analytical for linear, approximations for nonlinear)

Sequential Importance Resampling (Monte Carlo)

Iterative linearization and solving (e.g., Gauss-Newton, Levenberg-Marquardt)

Problem Structure Exploitation

High (explicitly models sparse dependencies between variables)

Low (assumes Markovian state; dense covariance)

Medium (particles evolve independently but resampling couples them)

High (exploits sparsity of the Jacobian/Hessian matrix)

Handling Nonlinearities

Global optimization handles strong nonlinearities via iterative linearization

Approximated (EKF: first-order; UKF: unscented transform)

Excellent (sampling-based; no linearity assumption)

Excellent (handled via iterative linearization in the optimization loop)

Temporal Model

Arbitrary (can incorporate past states as variables for smoothing)

Strictly filtering (estimates current state given past)

Strictly filtering (estimates current state given past)

Fixed-lag or full smoothing (estimates all states in a window/batch)

Loop Closure Integration

Native (adds a new factor connecting non-sequential variables)

Not native (requires augmenting state or separate mechanism)

Challenging (requires sophisticated proposal distributions)

Native (adds a new constraint to the optimization)

Computational Complexity (Online)

O(n) per iteration for incremental solvers (i.e., iSAM2)

O(k³) where k is state dimension (cubic in state size)

O(N) where N is number of particles (linear in particles)

O(n³) for full solve, impractical for true online operation

Memory Overhead

Moderate (stores graph and linearization points)

Low (stores mean and covariance matrix)

High (stores large set of particles and their histories)

High (stores all measurements and states in the batch)

Incremental Updates

Yes (via efficient variable reordering and factorization, e.g., iSAM2)

Yes (inherently recursive)

Yes (inherently recursive)

No (typically requires re-solving the entire batch)

Output Estimate Type

Maximum a Posteriori (MAP) over all variables

Minimum Mean Square Error (MMSE) for current state

Approximation of full posterior distribution

Maximum Likelihood (ML) or MAP over the batch

Typical Use Case in Robotics

Large-scale SLAM, VIO, LIO with loop closures

IMU integration, simple tracking, GPS-INS fusion

Global localization, non-Gaussian tracking (e.g., robot kidnapped)

Offline map building, camera calibration, bundle adjustment

IMPLEMENTATION TOOLS

Frameworks and Libraries for Factor Graphs

Factor graphs provide the theoretical backbone for modern state estimation. These specialized software libraries translate the bipartite graph model into efficient, solvable optimization problems for robotics and computer vision.

04

The SLAM Problem as a Factor Graph

This card illustrates the core conceptual mapping. In a robotics Simultaneous Localization and Mapping (SLAM) context, the factor graph elegantly structures the problem:

  • Variable Nodes: Represent unknown robot poses (x1, x2, x3) and landmark positions (l1, l2).
  • Factor Nodes: Encode probabilistic constraints between variables.
    • Odometry Factors: Connect sequential robot poses (e.g., between x1 and x2), based on wheel encoder or IMU data.
    • Measurement Factors: Connect a robot pose to a landmark (e.g., between x2 and l1), based on camera or LiDAR observations.
    • Loop Closure Factor: A special measurement factor that connects non-sequential poses (e.g., x3 back to x1), correcting accumulated drift.

Solving the graph via nonlinear least-squares optimization (e.g., Levenberg-Marquardt) yields the most probable configuration of all poses and landmarks.

05

Incremental Inference & The Bayes Tree

For real-time operation, robots cannot re-optimize the entire history every time a new measurement arrives. Incremental inference is key. Libraries like GTSAM use a Bayes tree—a data structure derived from the factor graph's chordal Bayes net—to enable efficient updates.

  • Process: When a new factor is added (e.g., a loop closure), only the affected part of the Bayes tree needs to be re-eliminated and re-solved.
  • Benefit: Computational complexity scales with the size of the update, not the size of the entire map, enabling lifelong operation.
  • Contrast: Batch optimization (as often used with Ceres) solves the entire problem from scratch each time, which becomes intractable for long trajectories.
06

Comparison: Smoothing vs. Filtering

Factor graph libraries typically perform smoothing, which differs fundamentally from the filtering approach of Kalman filters. This distinction is crucial for understanding their application.

  • Filtering (e.g., EKF, UKF): Estimates only the current state x_t given all measurements up to time t. It marginalizes out past states, discarding information.
  • Smoothing (e.g., GTSAM): Estimates the entire trajectory {x_1, x_2, ..., x_t} given all measurements. It retains the full history, leading to higher accuracy.

Why Smoothing for SLAM? Loop closures provide information about the past. A filter must somehow update old states, which is cumbersome. A smoother naturally re-adjusts the entire consistent history when a loop closure is detected, providing globally consistent maps.

FACTOR GRAPH

Frequently Asked Questions

A factor graph is a foundational graphical model in robotics and machine learning used to structure and solve complex state estimation problems. These questions address its core mechanics, applications, and relationship to other algorithms.

A factor graph is a bipartite graphical model that represents the factorization of a complex global function—typically a joint probability distribution—into a product of simpler, local functions called factors. It works by explicitly separating variable nodes (representing unknown states, like robot poses or landmark positions) from factor nodes (representing constraints or measurements that connect those variables). This separation provides a clear, modular structure for framing inference problems, where the goal is to find the most probable configuration of the variables given all the factors. The graph's connectivity defines the problem's sparsity, which is exploited by efficient nonlinear optimization algorithms like Gauss-Newton or Levenberg-Marquardt to find the Maximum A Posteriori (MAP) estimate. In robotics, each factor encodes a probabilistic constraint from a sensor measurement (e.g., an IMU reading, a visual feature match, or a GPS fix) or a prior belief, and solving the graph yields the optimal estimate of the entire system's state trajectory and map.

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.