Inferensys

Glossary

Factor Graph

A factor graph is a bipartite graph that visually represents the factorization of a complex probability distribution, structuring large-scale optimization problems in sensor fusion and robotics.
Performance engineer optimizing AI latency on laptop, latency charts visible, technical optimization session.
SENSOR FUSION ARCHITECTURES

What is a Factor Graph?

A factor graph is a probabilistic graphical model used to structure and solve large-scale inference problems, such as those in sensor fusion and robotics.

A factor graph is a bipartite graph that explicitly represents the factorization of a complex, global function—typically a joint probability distribution or an optimization objective. It consists of two node types: variable nodes (representing unknown states, like robot poses or landmark positions) and factor nodes (representing constraints or measurements that connect those variables). This graphical structure decomposes a high-dimensional problem into a product of simpler, local functions, making it computationally tractable to perform inference or maximum a posteriori (MAP) estimation.

In sensor fusion and Simultaneous Localization and Mapping (SLAM), factor graphs provide the backbone for modern graph optimization techniques like g2o or GTSAM. Each sensor measurement (e.g., from lidar, IMU, or GPS) introduces a factor that constrains the relationship between variable nodes. The system then solves for the most probable configuration of all variables by minimizing the error across all factors, often using nonlinear least squares solvers. This approach is more flexible than traditional Kalman filters for handling loops and large-scale, nonlinear problems.

SENSOR FUSION ARCHITECTURES

Key Components of a Factor Graph

A factor graph decomposes a complex probability distribution into a product of simpler functions. In sensor fusion, this structure elegantly represents the relationships between unknown states (robot poses, landmark positions) and noisy sensor measurements.

01

Factor Nodes

Factor nodes (typically squares) represent the local functions in the factorization. Each factor encodes a constraint or a measurement likelihood. For example:

  • A binary factor might connect a robot pose and a landmark, representing the constraint from a lidar measurement.
  • A unary factor connects to a single variable, often representing a prior belief (e.g., the robot's known starting location).
  • The factor's mathematical form defines the error model, such as a Gaussian for a Kalman filter-like constraint or a robust cost function for outlier rejection.
02

Variable Nodes

Variable nodes (typically circles) represent the unknown random variables we wish to estimate. In robotics and SLAM, these are often:

  • Robot poses (position and orientation) at different timestamps.
  • Landmark positions (3D points in the environment).
  • Sensor calibration parameters (e.g., camera intrinsics). Each variable node can be connected to multiple factor nodes, showing how different measurements inform the same unknown state. The graph structure visually reveals which variables are coupled by shared measurements.
03

Edges (Connections)

Edges are undirected connections that define the bipartite structure of the graph. An edge exists only between a factor node and a variable node, never between two nodes of the same type. This bipartite property is fundamental. The connectivity pattern determines:

  • Sparsity: Real-world problems yield sparse graphs, where each variable is connected to only a few factors, enabling efficient computation.
  • The Markov Property: A variable is conditionally independent of all other variables given its immediate neighbors (the factors it connects to). This local structure is key to distributed inference algorithms like belief propagation.
04

The Probabilistic Model

The graph represents the factorization of a global probability distribution. The joint distribution over all variables (X) is proportional to the product of all factors: [ p(X) \propto \prod_{f \in \mathcal{F}} f(X_f) ] where (X_f) is the subset of variables connected to factor (f), and (\mathcal{F}) is the set of all factors. Each factor (f(X_f)) is a non-negative function, often derived from:

  • A sensor model (likelihood): ( p(\text{measurement} \mid \text{state}) ).
  • A process/motion model: ( p(\text{next state} \mid \text{current state}, \text{control}) ).
  • A prior distribution on a variable.
05

Inference via Message Passing

The primary computational benefit of a factor graph is enabling efficient inference (estimating variable states) via message-passing algorithms. Beliefs about variables are refined by passing local messages along edges:

  • Sum-Product Algorithm: Computes marginal distributions for each variable.
  • Max-Sum Algorithm: Finds the most likely joint assignment (the MAP estimate). In robotics, this is often implemented as nonlinear least squares optimization (e.g., using Gauss-Newton). Each factor contributes a residual term to a large but sparse cost function, which is minimized to find the optimal variable values.
06

Incremental Graph Construction (iSAM2)

For real-time applications like SLAM, the factor graph is built incrementally. The iSAM2 (Incremental Smoothing and Mapping) algorithm is a landmark technique. It:

  • Adds new variable and factor nodes as the robot moves and observes landmarks.
  • Maintains a Bayes tree data structure for efficient re-linearization and variable re-ordering.
  • Performs fluid relinearization only on the part of the graph affected by new measurements. This allows for constant-time incremental updates in typical scenarios, rather than re-solving the entire optimization from scratch, which is critical for long-term autonomy.
SENSOR FUSION ARCHITECTURES

How Factor Graphs Work in Sensor Fusion

A factor graph is a probabilistic graphical model that structures complex estimation problems, such as those in sensor fusion and SLAM, into a computationally efficient optimization.

A factor graph is a bipartite graph that represents the factorization of a complex probability distribution. In sensor fusion, it structures the estimation problem by connecting variable nodes (representing unknown states like robot poses or landmark positions) to factor nodes (representing sensor measurements and process models). This explicit factorization allows large-scale, nonlinear optimization problems, common in Simultaneous Localization and Mapping (SLAM), to be solved efficiently using algorithms like Gaussian Belief Propagation or nonlinear least squares.

The power of the factor graph lies in its sparsity and modularity. Each new sensor measurement adds a factor node, constraining only the relevant variable nodes. This local connectivity enables incremental inference, where only parts of the graph need updating. This is critical for real-time robotic systems fusing data from lidar, inertial measurement units (IMUs), and cameras. The graph optimization framework, often implemented in libraries like g2o or GTSAM, directly minimizes the error from all factors to produce the most probable state estimate.

SENSOR FUSION & ROBOTICS

Primary Applications and Examples

Factor graphs provide a unifying graphical framework for structuring complex probabilistic models. Their primary power lies in representing large-scale optimization problems common in robotics, computer vision, and signal processing as sparse computational graphs.

02

Visual-Inertial Odometry (VIO)

VIO systems fuse high-frequency inertial measurement unit (IMU) data with lower-frequency camera images to estimate precise, high-rate motion. A factor graph elegantly handles this multi-rate sensor fusion:

  • IMU measurements between camera frames create pre-integrated factors that connect consecutive pose nodes, providing a motion prior.
  • Visual observations of feature tracks create factors between the pose node where the feature was first seen and subsequent pose nodes where it was re-observed.
  • The graph structure allows for efficient sliding window optimization, where only a recent history of poses is kept in the graph to bound computational cost. This is the core of state-of-the-art VIO systems like OKVIS and VINS-Fusion.
03

Multi-Object Tracking (MOT)

Factor graphs provide a clean formulation for the data association problem in tracking multiple objects. Here:

  • Nodes represent both the states of objects (position, velocity) over time and assignment variables linking detections to tracks.
  • Factors encode multiple constraints:
    • Motion factors between an object's state at time t and t+1 (e.g., a constant velocity model).
    • Measurement factors linking an object's state node to a detection node, if the assignment variable indicates a match.
    • Exclusivity factors that enforce that one detection is assigned to at most one track.
  • Inference on this graph solves for the most probable set of trajectories and associations jointly, which is more robust than greedy sequential association methods.
04

Calibration and Synchronization

Determining the spatial (extrinsic) and temporal relationships between sensors is a prerequisite for fusion. Factor graphs frame this as a joint optimization problem:

  • Extrinsic Calibration: Nodes represent the rigid transformation (rotation and translation) between sensor coordinate frames. Factors are created from paired observations of the same physical feature (e.g., a checkerboard corner seen by both a camera and a lidar). The graph is solved to find the optimal transform.
  • Temporal Synchronization: Nodes can represent clock offsets and drifts. Factors are created from timestamped events or measurements that should be coincident. This allows software correction of hardware synchronization errors.
  • This approach enables online calibration, where calibration parameters are continuously refined during operation.
05

Decentralized Sensor Fusion

In distributed systems like sensor networks or multi-robot teams, a single central factor graph is impractical. Decentralized fusion uses a network of local factor graphs:

  • Each robot or sensor node maintains its own local factor graph of its observations.
  • When robots communicate, they exchange linearized factors or summarized constraints (e.g., using Hessian matrices).
  • These transmitted constraints are incorporated into each local graph as virtual factors, allowing all nodes to converge toward a consensus on the global state estimate without sharing raw data.
  • This architecture provides scalability, robustness to single-point failures, and preserves bandwidth by communicating only summarized information.
06

Error Detection and Robust Estimation

Real sensor data contains outliers (e.g., incorrect loop closures in SLAM). Factor graphs integrate robust cost functions to mitigate their effect:

  • Standard factors use a quadratic cost (Gaussian noise assumption), which is highly sensitive to outliers.
  • Robust kernels (e.g., Huber, Cauchy, DCS) replace the quadratic cost with a function that grows more slowly for large errors, effectively down-weighting outlier constraints during optimization.
  • The graph structure makes it easy to attach fault detection factors or to use expectation-maximization to estimate the inlier probability of each factor. This results in systems that can automatically identify and reject erroneous GPS jumps, incorrect visual matches, or faulty lidar returns.
COMPARISON

Factor Graphs vs. Other Probabilistic Graphical Models

A structural and functional comparison of factor graphs against other common probabilistic graphical models used in sensor fusion and state estimation.

FeatureFactor GraphBayesian NetworkMarkov Random Field

Graph Structure

Bipartite (factor nodes, variable nodes)

Directed Acyclic Graph (DAG)

Undirected Graph

Primary Representation

Factorization of a global function

Conditional probability dependencies

Gibbs distribution / potential functions

Core Use Case in Sensor Fusion

Graph optimization / bundle adjustment (e.g., SLAM)

Causal reasoning, diagnostic systems

Image segmentation, spatial modeling

Inference Algorithm Example

Sum-Product Algorithm, Belief Propagation

Variable Elimination, Junction Tree Algorithm

Loopy Belief Propagation, Gibbs Sampling

Explicitly Shows Factorization

Naturally Handles Soft Constraints

Standard for Large-Scale Optimization Problems

Typical Application Context

Robotics (SLAM, VIO), communications (decoding)

Medical diagnosis, risk assessment

Computer vision, texture synthesis

FACTOR GRAPH

Frequently Asked Questions

A factor graph is a core data structure in probabilistic graphical models, widely used in robotics, sensor fusion, and Simultaneous Localization and Mapping (SLAM) to efficiently solve large-scale estimation problems. These questions address its core mechanics, applications, and relationship to other algorithms.

A factor graph is a bipartite graph that visually represents the factorization of a complex, global function—typically a joint probability distribution or an optimization objective—into a product of simpler, local functions called factors. It works by structuring a large inference problem into a network of two types of nodes: variable nodes (representing unknown states, like robot poses or landmark positions) and factor nodes (representing constraints or measurements that connect those variables, like sensor observations or motion models). By breaking down the problem this way, algorithms like belief propagation or nonlinear least-squares optimization (e.g., Levenberg-Marquardt) can be applied efficiently to compute marginal probabilities or find the most likely configuration of all variables.

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.