## ⓘ Markov random field

In the domain of physics and probability, a Markov random field, Markov network or undirected graphical model is a set of random variables having a Markov property described by an undirected graph. In other words, a random field is said to be a Markov random field if it satisfies Markov properties.

A Markov network or MRF is similar to a Bayesian network in its representation of dependencies; the differences being that Bayesian networks are directed and acyclic, whereas Markov networks are undirected and may be cyclic. Thus, a Markov network can represent certain dependencies that a Bayesian network cannot such as cyclic dependencies; on the other hand, it cant represent certain dependencies that a Bayesian network can such as induced dependencies. The underlying graph of a Markov random field may be finite or infinite.

When the joint probability density of the random variables is strictly positive, it is also referred to as a Gibbs random field, because, according to the Hammersley–Clifford theorem, it can then be represented by a Gibbs measure for an appropriate locally defined energy function. The prototypical Markov random field is the Ising model; indeed, the Markov random field was introduced as the general setting for the Ising model. In the domain of artificial intelligence, a Markov random field is used to model various low- to mid-level tasks in image processing and computer vision.

## 1. Definition

Given an undirected graph G = V, E {\displaystyle G=V,E}, a set of random variables X = X v ∈ V {\displaystyle X=X_{v}_{v\in V}} indexed by V {\displaystyle V} form a Markov random field with respect to G {\displaystyle G} if they satisfy the local Markov properties:

Pairwise Markov property: Any two non-adjacent variables are conditionally independent given all other variables: X u ⊥ ⊥ X v ∣ X V ∖ { u, v } {\displaystyle X_{u}\perp \!\!\!\perp X_{v}\mid X_{V\setminus \{u,v\}}} Local Markov property: A variable is conditionally independent of all other variables given its neighbors: X v ⊥ ⊥ X V ∖ N =v\cup \operatorname {N} v} is the closed neighbourhood of v {\displaystyle v}. Global Markov property: Any two subsets of variables are conditionally independent given a separating subset: X A ⊥ ⊥ X B ∣ X S {\displaystyle X_{A}\perp \!\!\!\perp X_{B}\mid X_{S}} where every path from a node in A {\displaystyle A} to a node in B {\displaystyle B} passes through S {\displaystyle S}.The Global Markov property is stronger than the Local Markov property, which in turn is stronger than the Pairwise one. However, the above three Markov properties are equivalent for a positive probability.

## 2. Clique factorization

As the Markov property of an arbitrary probability distribution can be difficult to establish, a commonly used class of Markov random fields are those that can be factorized according to the cliques of the graph.

Given a set of random variables X = X v ∈ V {\displaystyle X=X_{v}_{v\in V}}, let P X = x {\displaystyle PX=x} be the probability of a particular field configuration x {\displaystyle x} in X {\displaystyle X}. That is, P X = x {\displaystyle PX=x} is the probability of finding that the random variables X {\displaystyle X} take on the particular value x {\displaystyle x}. Because X {\displaystyle X} is a set, the probability of x {\displaystyle x} should be understood to be taken with respect to a joint distribution of the X v {\displaystyle X_{v}}.

If this joint density can be factorized over the cliques of G {\displaystyle G}:

P X = x = ∏ C ∈ cl G ϕ C x C {\displaystyle PX=x=\prod _{C\in \operatorname {cl} G}\phi _{C}x_{C}}then X {\displaystyle X} forms a Markov random field with respect to G {\displaystyle G}. Here, cl G {\displaystyle \operatorname {cl} G} is the set of cliques of G {\displaystyle G}. The definition is equivalent if only maximal cliques are used. The functions φ C are sometimes referred to as factor potentials or clique potentials. Note, however, conflicting terminology is in use: the word potential is often applied to the logarithm of φ C. This is because, in statistical mechanics, logφ C has a direct interpretation as the potential energy of a configuration x C {\displaystyle x_{C}}.

Some MRFs do not factorize: a simple example can be constructed on a cycle of 4 nodes with some infinite energies, i.e. configurations of zero probabilities, even if one, more appropriately, allows the infinite energies to act on the complete graph on V {\displaystyle V}.

MRFs factorize if at least one of the following conditions is fulfilled:

- the graph is chordal by equivalence to a Bayesian network
- the density is positive by the Hammersley–Clifford theorem

When such a factorization does exist, it is possible to construct a factor graph for the network.

## 3. Exponential family

Any positive Markov random field can be written as exponential family in canonical form with feature functions f k {\displaystyle f_{k}} such that the full-joint distribution can be written as

P X = x = 1 Z exp ∑ k w k ⊤ f k x { k }) {\displaystyle PX=x={\frac {1}{Z}}\exp \left\sum _{k}w_{k}^{\top }f_{k}x_{\{k\}}\right)}where the notation

w k ⊤ f k x { k } = ∑ i = 1 N k w k, i ⋅ f k, i x { k } {\displaystyle w_{k}^{\top }f_{k}x_{\{k\}}=\sum _{i=1}^{N_{k}}w_{k,i}\cdot f_{k,i}x_{\{k\}}}is simply a dot product over field configurations, and Z is the partition function:

Z = ∑ x ∈ X exp ∑ k w k ⊤ f k x { k }). {\displaystyle Z=\sum _{x\in {\mathcal {X}}}\exp \left\sum _{k}w_{k}^{\top }f_{k}x_{\{k\}}\right).}Here, X {\displaystyle {\mathcal {X}}} denotes the set of all possible assignments of values to all the networks random variables. Usually, the feature functions f k, i {\displaystyle f_{k,i}} are defined such that they are indicators of the cliques configuration, i.e. f k, i x { k } = 1 {\displaystyle f_{k,i}x_{\{k\}}=1} if x { k } {\displaystyle x_{\{k\}}} corresponds to the i -th possible configuration of the k -th clique and 0 otherwise. This model is equivalent to the clique factorization model given above, if N k = | dom C k | {\displaystyle N_{k}=|\operatorname {dom} C_{k}|} is the cardinality of the clique, and the weight of a feature f k, i {\displaystyle f_{k,i}} corresponds to the logarithm of the corresponding clique factor, i.e. w k, i = log ϕ c k, i {\displaystyle w_{k,i}=\log \phi c_{k,i}}, where c k, i {\displaystyle c_{k,i}} is the i -th possible configuration of the k -th clique, i.e. the i -th value in the domain of the clique C k {\displaystyle C_{k}}.

The probability P is often called the Gibbs measure. This expression of a Markov field as a logistic model is only possible if all clique factors are non-zero, i.e. if none of the elements of X {\displaystyle {\mathcal {X}}} are assigned a probability of 0. This allows techniques from matrix algebra to be applied, e.g. that the trace of a matrix is log of the determinant, with the matrix representation of a graph arising from the graphs incidence matrix.

The importance of the partition function Z is that many concepts from statistical mechanics, such as entropy, directly generalize to the case of Markov networks, and an intuitive understanding can thereby be gained. In addition, the partition function allows variational methods to be applied to the solution of the problem: one can attach a driving force to one or more of the random variables, and explore the reaction of the network in response to this perturbation. Thus, for example, one may add a driving term J v, for each vertex v of the graph, to the partition function to get:

Z }{\partial J_{u}\partial J_{v}}}\right|_{J_{u}=0,J_{v}=0}.}Unfortunately, though the likelihood of a logistic Markov network is convex, evaluating the likelihood or gradient of the likelihood of a model requires inference in the model, which is generally computationally infeasible see Inference below.

## 4. Examples

### Gaussian

A multivariate normal distribution forms a Markov random field with respect to a graph G = V, E {\displaystyle G=V,E} if the missing edges correspond to zeros on the precision matrix the inverse covariance matrix:

X = X v ∈ V ∼ N μ, Σ {\displaystyle X=X_{v}_{v\in V}\sim {\mathcal {N}}{\boldsymbol {\mu }},\Sigma}such that

Σ − 1 u v = 0 iff { u, v } ∉ E. {\displaystyle \Sigma ^{-1}_{uv}=0\quad {\text{iff}}\quad \{u,v\}\notin E.}## 5. Inference

As in a Bayesian network, one may calculate the conditional distribution of a set of nodes V ′ = { v 1, …, v i } {\displaystyle V=\{v_{1},\ldots,v_{i}\}} given values to another set of nodes W ′ = { w 1, …, w j } {\displaystyle W=\{w_{1},\ldots,w_{j}\}} in the Markov random field by summing over all possible assignments to u ∉ V ′, W ′ {\displaystyle u\notin V,W} ; this is called exact inference. However, exact inference is a #P-complete problem, and thus computationally intractable in the general case. Approximation techniques such as Markov chain Monte Carlo and loopy belief propagation are often more feasible in practice. Some particular subclasses of MRFs, such as trees see Chow–Liu tree, have polynomial-time inference algorithms; discovering such subclasses is an active research topic. There are also subclasses of MRFs that permit efficient MAP, or most likely assignment, inference; examples of these include associative networks. Another interesting sub-class is the one of decomposable models when the graph is chordal: having a closed-form for the MLE, it is possible to discover a consistent structure for hundreds of variables.

## 6. Conditional random fields

One notable variant of a Markov random field is a conditional random field, in which each random variable may also be conditioned upon a set of global observations o {\displaystyle o}. In this model, each function ϕ k {\displaystyle \phi _{k}} is a mapping from all assignments to both the clique k and the observations o {\displaystyle o} to the nonnegative real numbers. This form of the Markov network may be more appropriate for producing discriminative classifiers, which do not model the distribution over the observations. CRFs were proposed by John D. Lafferty, Andrew McCallum and Fernando C.N. Pereira in 2001.

## 7. Varied applications

Markov random fields find application in a variety of fields, ranging from computer graphics to computer vision, machine learning or computational biology. MRFs are used in image processing to generate textures as they can be used to generate flexible and stochastic image models. In image modelling, the task is to find a suitable intensity distribution of a given image, where suitability depends on the kind of task and MRFs are flexible enough to be used for image and texture synthesis, image compression and restoration, image segmentation, 3D image inference from 2D images, image registration, texture synthesis, super-resolution, stereo matching and information retrieval. They can be used to solve various computer vision problems which can be posed as energy minimization problems or problems where different regions have to be distinguished using a set of discriminating features, within a Markov random field framework, to predict the category of the region. Markov random fields were a generalization over the Ising model and have, since then, been used widely in combinatorial optimizations and networks.