pystruct.inference.inference_ogm

pystruct.inference.inference_ogm(unary_potentials, pairwise_potentials, edges, return_energy=False, alg='dd', init=None, reserveNumFactorsPerVariable=2, **kwargs)[source]

Inference with OpenGM backend.

Parameters:

unary_potentials : nd-array, shape (n_nodes, n_nodes)

Unary potentials of energy function.

pairwise_potentials : nd-array, shape (n_states, n_states) or (n_states, n_states, n_edges).

Pairwise potentials of energy function. If the first case, edge potentials are assumed to be the same for all edges. In the second case, the sequence needs to correspond to the edges.

edges : nd-array, shape (n_edges, 2)

Graph edges for pairwise potentials, given as pair of node indices. As pairwise potentials are not assumed to be symmetric, the direction of the edge matters.

alg : string

Possible choices currently are:
  • ‘bp’ for Loopy Belief Propagation.
  • ‘dd’ for Dual Decomposition via Subgradients.
  • ‘trws’ for Vladimirs TRWs implementation.
  • ‘trw’ for OGM TRW.
  • ‘gibbs’ for Gibbs sampling.
  • ‘lf’ for Lazy Flipper
  • ‘fm’ for Fusion Moves (alpha-expansion fusion)
  • ‘dyn’ for Dynamic Programming (message passing in trees)
  • ‘gc’ for Graph Cut
  • ‘alphaexp’ for Alpha Expansion using Graph Cuts
  • ‘mqpbo’ for multi-label qpbo

init : nd-array

Initial solution for starting inference (ignored by some algorithms).

reserveNumFactorsPerVariable : :

reserve a certain number of factors for each variable can speed up the building of a graphical model. ( For a 2d grid with second order factors one should set this to 5

4 2-factors and 1 unary factor for most pixels )

Returns:

labels : nd-array

Approximate (usually) MAP variable assignment.