Markov random field

Also known as: MRF · Markov network · undirected graphical model

On this page 7

A Markov random field (MRF), also called a Markov network or undirected graphical model, is a probability distribution over a set of random variables whose conditional independence structure is described by an undirected graph. Each node is a variable, and each edge indicates a direct dependency. Within probabilistic models in artificial intelligence, MRFs are the standard tool for describing symmetric, non-causal interactions, such as neighboring pixels in an image or interacting spins in a physical lattice.

Instead of conditional probability tables, an MRF defines the joint distribution as a normalized product of non-negative potential functions over cliques of the graph. This makes the model flexible to specify, but it introduces a global normalizing constant that makes exact learning and inference difficult in most real problems.

How a Markov random field defines a distribution

An MRF assigns probability through clique potentials: functions that score how compatible the joint values of a fully connected group of variables are. The joint distribution is p(x) = (1/Z) * prod_C psi_C(x_C), where each psi_C is a potential over clique C and Z is the partition function that sums the product over all possible configurations.

Potentials are often written in exponential form, psi_C = exp(-E_C), which turns the model into an energy-based model: low total energy means high probability. When the energy is linear in a set of features with weights, the MRF becomes a log-linear model, the form used in most practical learning.

The table below summarizes the core components of the formulation and what each controls.

ComponentDefinitionRole in the model
Undirected graphNodes for variables, edges for direct dependenciesEncodes conditional independence
CliqueSet of nodes that are all mutually connectedScope of each potential function
Potential functionNon-negative compatibility scoreShapes local preferences
Energy functionNegative log of the unnormalized probabilityAllows optimization view of inference
Partition function ZSum or integral over all configurationsNormalizes the distribution
Components of a Markov random field

Markov properties and the Hammersley-Clifford theorem

The graph of an MRF expresses independence through graph separation: if every path between two sets of nodes passes through a third set, the first two sets are conditionally independent given the third. This is simpler than d-separation in directed networks because edges have no direction.

  • Pairwise Markov property: two non-adjacent variables are independent given all other variables.
  • Local Markov property: a variable is independent of all others given its Markov blanket, which in an MRF is simply its set of neighbors.
  • Global Markov property: any two sets separated by a third set are conditionally independent given that set.

The Hammersley-Clifford theorem links these properties to the factorized form. For any strictly positive distribution, satisfying the Markov properties of a graph is equivalent to factorizing over its cliques. If some configurations have zero probability, the equivalence can fail, which matters for models with hard constraints.

Common types of Markov random fields

Most applied MRFs fall into a few well-studied families, which differ in variable type, graph structure and potential form. The table compares the variants that appear most often in research and practice.

VariantVariables and structureTypical use
Ising modelBinary spins on a lattice, pairwise termsStatistical physics, binary image denoising
Potts modelDiscrete labels, penalty for unequal neighborsImage segmentation, clustering
Gaussian MRFContinuous variables, sparse precision matrixSpatial statistics, sensor networks
Boltzmann machineBinary units, visible and hidden layersEarly generative neural models
Conditional random fieldMRF conditioned on observed inputsSequence labeling, structured prediction
Frequently used MRF variants

In a Gaussian MRF, a zero entry in the precision matrix means the two variables are conditionally independent, so learning a sparse precision matrix is equivalent to learning the graph structure, which is the idea behind the graphical lasso.

How Markov random fields compare with Bayesian networks

MRFs and Bayesian networks are the two main classes of probabilistic graphical models, and each can express independence patterns the other cannot. A Bayesian network can express the explaining-away effect of a v-structure, while an MRF can represent a cycle of four variables with symmetric dependencies that no directed graph captures exactly.

AspectMarkov random fieldBayesian network
Edge semanticsSymmetric associationDirected, often causal influence
ParameterizationClique potentials, unnormalizedLocal conditional probabilities
NormalizationGlobal partition function requiredAutomatically normalized
Independence testSimple graph separationD-separation
SamplingUsually MCMC such as Gibbs samplingExact ancestral sampling
Undirected versus directed graphical models

Both representations can be converted into a factor graph, which makes the factorization explicit and serves as the common input for belief propagation and related message-passing algorithms.

Inference, learning and practical limitations

Exact inference in a general MRF is NP-hard, because computing the partition function requires summing over exponentially many configurations. Exact methods such as variable elimination or the junction tree algorithm are practical only when the graph has low treewidth.

For larger models, practitioners rely on approximations. The decision table below matches common tasks to suitable methods.

TaskRecommended methodReason
Exact marginals on a treeBelief propagationExact and linear in graph size
Approximate marginals on loopy graphsLoopy belief propagation or mean-fieldFast, often accurate enough
Most probable labeling, submodular energyGraph cutsExact or near-exact in polynomial time
Unbiased estimates of expectationsGibbs samplingSimple local updates using the Markov blanket
Parameter learning with intractable ZPseudo-likelihood or contrastive divergenceAvoids computing the partition function
Choosing an inference or learning method

The main limitations are costly parameter learning, because the likelihood gradient needs model expectations, and weak interpretability of potentials, which are not probabilities and cannot be read as local conditional distributions. A common mistake is to treat a potential value as a probability.

Put simply

A Markov random field is a map of which things influence each other directly. Think of houses on a street. Each house tends to look like its neighbors. Paint colors spread from house to house.

The model does not say who influenced whom. It only says neighbors tend to agree. If you know all the neighbors of one house, the rest of the street tells you nothing new about it. This simple rule lets computers reason about large, connected systems such as the pixels of a photo.

In practice

A medical imaging team needs to separate a tumor from healthy tissue in MRI scans. A pixel classifier alone gives noisy, speckled masks, because individual pixels are ambiguous, and single misclassified pixels appear far from the real lesion.

The team adds a Potts-type MRF on the pixel grid. Unary potentials come from the classifier scores, and pairwise potentials penalize neighboring pixels with different labels unless the image shows a strong intensity edge between them. The most probable labeling is computed with graph cuts in well under a second per slice.

The resulting masks have smooth, connected boundaries that follow real tissue edges. Radiologists spend less time correcting outlines, and the volume measurements used to track treatment response become more consistent between scans.