Graph cut optimization explained

f

, if it is possible to construct a flow network with positive weights such that

C

of the network can be mapped to an assignment of variables

x

to

f

(and vice versa), and

C

equals

f(x)

(up to an additive constant)then it is possible to find the global optimum of

f

in polynomial time by computing a minimum cut of the graph. The mapping between cuts and variable assignments is done by representing each variable with one node in the graph and, given a cut, each variable will have a value of 0 if the corresponding node belongs to the component connected to the source, or 1 if it belong to the component connected to the sink.

Not all pseudo-Boolean functions can be represented by a flow network, and in the general case the global optimization problem is NP-hard. There exist sufficient conditions to characterise families of functions that can be optimised through graph cuts, such as submodular quadratic functions. Graph cut optimization can be extended to functions of discrete variables with a finite number of values, that can be approached with iterative algorithms with strong optimality properties, computing one graph cut at each iteration.

Graph cut optimization is an important tool for inference over graphical models such as Markov random fields or conditional random fields, and it has applications in computer vision problems such as image segmentation, denoising, registration and stereo matching.

Representability

f:\{0,1\}n\toR

is said to be representable if there exists a graph

G=(V,E)

with non-negative weights and with source and sink nodes

s

and

t

respectively, and there exists a set of nodes

V0=\{v1,...,vn\}\subsetV-\{s,t\}

such that, for each tuple of values

(x1,...,xn)\in\{0,1\}n

assigned to the variables,

f(x1,...,xn)

equals (up to a constant) the value of the flow determined by a minimum cut

C=(S,T)

of the graph

G

such that

vi\inS

if

xi=0

and

vi\inT

if

xi=1

.

It is possible to classify pseudo-Boolean functions according to their order, determined by the maximum number of variables contributing to each single term. All first order functions, where each term depends upon at most one variable, are always representable. Quadratic functions

f(x)=w0+\sumiwi(xi)+\sumiwij(xi,xj).

are representable if and only if they are submodular, i.e. for each quadratic term

wij

the following condition is satisfied

wij(0,0)+wij(1,1)\lewij(0,1)+wij(1,0).

Cubic functions

f(x)=w0+\sumiwi(xi)+\sumiwij(xi,xj)+\sumiwijk(xi,xj,xk)

are representable if and only if they are regular, i.e. all possible binary projections to two variables, obtained by fixing the value of the remaining variable, are submodular. For higher-order functions, regularity is a necessary condition for representability.

Graph construction

Graph construction for a representable function is simplified by the fact that the sum of two representable functions

f'

and

f''

is representable, and its graph

G=(V'\cupV'',E'\cupE'')

is the union of the graphs

G'=(V',E')

and

G''=(V'',E'')

representing the two functions. Such theorem allows to build separate graphs representing each term and combine them to obtain a graph representing the entire function.

The graph representing a quadratic function of

n

variables contains

n+2

vertices, two of them representing the source and sink and the others representing the variables. When representing higher-order functions, the graph contains auxiliary nodes that allow to model higher-order interactions.

Unary terms

A unary term

wi

depends only on one variable

xi

and can be represented by a graph with one non-terminal node

vi

and one edge

svi

with weight

wi(1)-wi(0)

if

wi(1)\gewi(0)

, or

vit

with weight

wi(0)-wi(1)

if

wi(1)<wi(0)

.

Binary terms

A quadratic (or binary) term

wij

can be represented by a graph containing two non-terminal nodes

vi

and

vj

. The term can be rewritten as

wij(xi,xj)=wij(0,0)+kixi+kjxj+kij\left((1-xi)xj+xi(1-xj)\right)

with

\begin{align} ki&=

1
2

(wij(1,0)-wij(0,0))\\ kj&=

1
2

(wij(1,1)-wij(1,0))\\ kij&=

1
2

(wij(0,1)+wij(1,0)-wij(0,0)-wij(1,1)). \end{align}

In this expression, the first term is constant and it is not represented by any edge, the two following terms depend on one variable and are represented by one edge, as shown in the previous section for unary terms, while the third term is represented by an edge

vivj

with weight

wij(0,1)+wij(1,0)-wij(0,0)-wij(1,1)

(submodularity guarantees that the weight is non-negative).

Ternary terms

A cubic (or ternary) term

wijk

can be represented by a graph with four non-terminal nodes, three of them (

vi

,

vj

and

vk

) associated to the three variables plus one fourth auxiliary node

vijk

. A generic ternary term can be rewritten as the sum of a constant, three unary terms, three binary terms, and a ternary term in simplified form. There may be two different cases, according to the sign of

p=wijk(0,0,0)+wijk(0,1,1)+wijk(1,0,1)+wijk(1,1,0)

. If

p>0

then

wijk(xi,xj,xk)= wijk(0,0,0) +p1(xi-1)+p2(xj-1)+p3(xk-1) +p23(xj-1)xk+p31xi(xk-1)+p12(xi-1)xj -pxixjxk

with

\begin{align} p1&=wijk(1,0,1)-wijk(0,0,1)\\ p2&=wijk(1,1,0)-wijk(1,0,1)\\ p3&=wijk(0,1,1)-wijk(0,1,0)\\ p23&=wijk(0,0,1)+wijk(0,1,0)-wijk(0,0,0)-wijk(0,1,1)\\ p31&=wijk(0,0,1)+wijk(1,0,0)-wijk(0,0,0)-wijk(1,0,1)\\ p12&=wijk(0,1,0)+wijk(1,0,0)-wijk(0,0,0)-wijk(1,1,0). \end{align}

If

p<0

the construction is similarly, but the variables will have opposite value. If the function is regular, then all its projections of two variables will be submodular, implying that

p23

,

p31

and

p12

are positive and then all terms in the new representation are submodular.

In this decomposition, the constant, unary and binary terms can be represented as shown in the previous sections. If

p>0

the ternary term can be represented with a graph with four edges

vivijk

,

vjvijk

,

vkvijk

,

vijkt

, all with weight

p

, while if

p<0

the term can be represented by four edges

vijkvi

,

vijkvj

,

vijkvk

,

svijk

with weight

-p

.

Minimum cut

After building a graph representing a pseudo-Boolean function, it is possible to compute a minimum cut using one among the various algorithms developed for flow networks, such as Ford–Fulkerson, Edmonds–Karp, and Boykov–Kolmogorov algorithm. The result is a partition of the graph in two connected components

S

and

T

such that

s\inS

and

t\inT

, and the function attains its global minimum when

xi=0

for each

i

such that the corresponding node

vi\in S

, and

xi=1

for each

i

such that the corresponding node

vi\inT

.

Max-flow algorithms such as Boykov - Kolmogorov's are very efficient in practice for sequential computation, but they are difficult to parallelise, making them not suitable for distributed computing applications and preventing them from exploiting the potential of modern CPUs. Parallel max-flow algorithms were developed, such as push-relabel and jump-flood, that can also take advantage of hardware acceleration in GPGPU implementations.

Functions of discrete variables with more than two values

The previous construction allows global optimization of pseudo-Boolean functions only, but it can be extended to quadratic functions of discrete variables with a finite number of values, in the form

f(x)=\sumiD(xi)+\sum(i,S(xi,xj)

where

E\subseteqV x V

and

xi\inΛ=\{1,...,k\}

. The function

D(xi)

represents the unary contribution of each variable (often referred as data term), while the function

S(xi,xj)

represents binary interactions between variables (smoothness term). In the general case, optimization of such functions is a NP-hard problem, and stochastic optimization methods such as simulated annealing are sensitive to local minima and in practice they can generate arbitrarily sub-optimal results. With graph cuts it is possible to construct move-making algorithms that allow to reach in polynomial time a local minima with strong optimality properties for a wide family of quadratic functions of practical interest (when the binary interaction

S(xi,xj)

is a metric or a semimetric), such that the value of the function in the solution lies within a constant and known factor from the global optimum.

Given a function

f:Λn\toR

with

Λ=\{1,...,k\}

, and a certain assignment of values

x=(x1,...,xn)\inΛn

to the variables, it is possible to associate each assignment

x

to a partition

P=\{Pl|l\inΛ\}

of the set of variables, such that,

Pl=\{xi|xi=l\inΛ\}

. Give two distinct assignments

P

and

P'

and a value

\alpha\inΛ

, a move that transforms

P

into

P'

is said to be an

\alpha

-expansion if

P\alpha\subsetP'\alpha

and

P'l\subsetPl\foralll\inΛ-\{\alpha\}

. Given a couple of values

\alpha

and

\beta

, a move is said to be an

\alpha\beta

-swap if

Pl=P'l\foralll\inΛ-\{\alpha,\beta\}

. Intuitively, an

\alpha

-expansion move from

x

assigns the value of

\alpha

to some variables that have a different value in

x

, while an

\alpha\beta

-swap move assigns

\alpha

to some variables that have value

\beta

in

x

and vice versa.

For each iteration, the

\alpha

-expansion algorithm computes, for each possible value

\alpha

, the minimum of the function among all assignments

\Alpha(x)

that can be reached with a single

\alpha

-expansion move from the current temporary solution

x

, and takes it as the new temporary solution.

x:=arbitraryvalueinΛn

exit:=0

while

exit\ne1

:

exit=1

foreach

\alpha\inΛ

:

\hat{x

} := \arg \min_ f(\mathbf) if

f(\hat{x

}) < f(\mathbf):

x=\hat{x

}

exit:=0

The

\alpha\beta

-swap algorithm is similar, but it searches for the minimum among all assignments

\Alpha\Beta(x)

reachable with a single

\alpha\beta

-swap move from

x

.

x:=arbitraryvalueinΛn

exit:=0

while

exit\ne1

:

exit=1

foreach

(\alpha,\beta)\inΛ2

:

\hat{x

} := \arg \min_ f(\mathbf) if

f(\hat{x

}) < f(\mathbf):

x=\hat{x

}

exit:=0

In both cases, the optimization problem in the innermost loop can be solved exactly and efficiently with a graph cut. Both algorithms terminate certainly in a finite number of iterations of the outer loop, and in practice such number is small, with most of the improvement happening at the first iteration. The algorithms can generate different solutions depending on the initial guess, but in practice they are robust with respect to initialisation, and starting with a point where all variables are assigned to the same random value is usually sufficient to produce good quality results.

The solution generated by such algorithms is not necessarily a global optimum, but it has strong guarantees of optimality. If

S(xi,xj)

is a metric and

x

is a solution generated by the

\alpha

-expansion algorithm, or if

S(xi,xj)

is a semimetric and

x

is a solution generated by the

\alpha\beta

-swap algorithm, then

f(x)

lies within a known and constant factor from the global minimum

f(x*)

:

f(x)\le2

max\alphaS(\alpha,\beta)
min\alphaS(\alpha,\beta)

f(x*).

Non-submodular functions

See also: Quadratic pseudo-Boolean optimization.

Generally speaking, the problem of optimizing a non-submodular pseudo-Boolean function is NP-hard and cannot be solved in polynomial time with a simple graph cut. The simplest approach is to approximate the function with a similar but submodular one, for instance truncating all non-submodular terms or replacing them with similar submodular expressions. Such approach is generally sub-optimal, and it produces acceptable results only if the number of non-submodular terms is relatively small.

In case of quadratic non-submodular functions, it is possible to compute in polynomial time a partial solution using algorithms such as QPBO. Higher-order functions can be reduced in polynomial time to a quadratic form that can be optimised with QPBO.

Higher-order functions

Quadratic functions are extensively studied and were characterised in detail, but more general results were derived also for higher-order functions. While quadratic functions can indeed model many problems of practical interest, they are limited by the fact they can represent only binary interactions between variables. The possibility to capture higher-order interactions allows to better capture the nature of the problem and it can provide higher quality results that could be difficult to achieve with quadratic models. For instance in computer vision applications, where each variable represents a pixel or voxel of the image, higher-order interactions can be used to model texture information, that would be difficult to capture using only quadratic functions.

Sufficient conditions analogous to submodularity were developed to characterise higher-order pseudo-Boolean functions that can be optimised in polynomial time, and there exists algorithms analogous to

\alpha

-expansion and

\alpha\beta

-swap for some families of higher-order functions. The problem is NP-hard in the general case, and approximate methods were developed for fast optimization of functions that do not satisfy such conditions.

Notes

[1] [2]

Bibliography

External links

Notes and References

  1. Algorithms such as simulated annealing have strong theoretical convergence properties for some scheduling of the temperature to infinity. Such scheduling cannot be realised in practice.
  2. Adding one node is necessary, graphs without auxiliary nodes can only represent binary interactions between variables.