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.
| Component | Definition | Role in the model |
|---|---|---|
| Undirected graph | Nodes for variables, edges for direct dependencies | Encodes conditional independence |
| Clique | Set of nodes that are all mutually connected | Scope of each potential function |
| Potential function | Non-negative compatibility score | Shapes local preferences |
| Energy function | Negative log of the unnormalized probability | Allows optimization view of inference |
| Partition function Z | Sum or integral over all configurations | Normalizes the distribution |
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.
| Variant | Variables and structure | Typical use |
|---|---|---|
| Ising model | Binary spins on a lattice, pairwise terms | Statistical physics, binary image denoising |
| Potts model | Discrete labels, penalty for unequal neighbors | Image segmentation, clustering |
| Gaussian MRF | Continuous variables, sparse precision matrix | Spatial statistics, sensor networks |
| Boltzmann machine | Binary units, visible and hidden layers | Early generative neural models |
| Conditional random field | MRF conditioned on observed inputs | Sequence labeling, structured prediction |
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.
| Aspect | Markov random field | Bayesian network |
|---|---|---|
| Edge semantics | Symmetric association | Directed, often causal influence |
| Parameterization | Clique potentials, unnormalized | Local conditional probabilities |
| Normalization | Global partition function required | Automatically normalized |
| Independence test | Simple graph separation | D-separation |
| Sampling | Usually MCMC such as Gibbs sampling | Exact ancestral sampling |
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.
| Task | Recommended method | Reason |
|---|---|---|
| Exact marginals on a tree | Belief propagation | Exact and linear in graph size |
| Approximate marginals on loopy graphs | Loopy belief propagation or mean-field | Fast, often accurate enough |
| Most probable labeling, submodular energy | Graph cuts | Exact or near-exact in polynomial time |
| Unbiased estimates of expectations | Gibbs sampling | Simple local updates using the Markov blanket |
| Parameter learning with intractable Z | Pseudo-likelihood or contrastive divergence | Avoids computing the partition function |
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.