pystruct.inference.inference_dispatch(unary_potentials, pairwise_potentials, edges, inference_method, return_energy=False, **kwargs)[source]

Computes the maximizing assignment of a pairwise discrete energy function.

Wrapper function to dispatch between inference method by string.


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

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.

inference_method : string

Possible choices currently are:
  • ‘qpbo’ for QPBO alpha-expansion (fast but approximate).
  • ‘lp’ for build-in lp relaxation via cvxopt (slow).
  • ‘ad3’ for AD^3 subgradient based dual solution of LP.
  • ‘ogm’ for OpenGM wrappers.
  • ‘max-product’ for max-product message passing.
  • ‘unary’ for using unary potentials only.

It is also possible to pass a tuple (string, dict) where the dict contains additional keyword arguments, like ('ad3', {'branch_and_bound': True}).

relaxed : bool (default=False)

Whether to return a relaxed solution (when appropriate) or round to the nearest integer solution. Only used for ‘lp’ and ‘ad3’ inference methods.

return_energy : bool (default=False)

Additionally return the energy of the returned solution (according to the solver). If relaxed=False, this is the energy of the relaxed, not the rounded solution.


labels : nd-array

Approximate (usually) MAP variable assignment. If relaxed=True, this is a tuple of unary and pairwise “marginals” from the LP relaxation.