pylibmgm.CostMap

class pylibmgm.CostMap

Container for unary and pairwise costs in a graph matching problem.

Stores assignment costs (unary) and edge costs (pairwise) for a GM model. Provides efficient lookup of costs using node indices or assignment/edge structures.

Only exposed for lookup. Setting of costs is handled by GmModel class.

Uses a ankerl::unordered_dense::map HashMap in the background. Especially designed for very sparse problems. Not ideal for dense, and not as sparse problems could potentially benefit from a sparse matrix instead.

Methods

__init__(*args, **kwargs)

contains(*args, **kwargs)

Overloaded function.

pairwise(*args, **kwargs)

Overloaded function.

unary(*args, **kwargs)

Overloaded function.

contains(node1: int, node2: int) bool

Check if unary cost exists for given node pair.

contains(assignment: tuple[int, int]) bool

Check if unary cost exists for given (node1, node2) assignment tuple.

contains(assignment1_left: int, assignment1_right: int, assignment2_left: int, assignment2_right: int) bool

Check if pairwise cost exists for given node quadruple.

contains(edge: tuple[tuple[int, int], tuple[int, int]]) bool

Check if pairwise cost exists for given edge ((assignment1_left, assignment1_right), (assignment2_left, assignment2_right)) tuple.

pairwise(assignment1_left: int, assignment1_right: int, assignment2_left: int, assignment2_right: int) float

Get pairwise cost for edge defined by a node quadruple.

pairwise(edge: tuple[tuple[int, int], tuple[int, int]]) float

Get pairwise cost for an edge index.

unary(node1: int, node2: int) float

Get unary cost for matching node1 (from graph1) to node2 (from graph2).

unary(assignment: tuple[int, int]) float

Get unary cost for an assignment index.

__init__(*args, **kwargs)