pygsti.tools.matrixtools.minweight_match#
- minweight_match(a, b, metricfn=None, return_pairs=True, pass_indices_to_metricfn=False)#
Matches the elements of two vectors, a and b by minimizing the weight between them.
The weight is defined as the sum of metricfn(x,y) over all (x,y) pairs (x in a and y in b).
- Parameters:
a (list or numpy.ndarray) – First 1D array to match elements between.
b (list or numpy.ndarray) – Second 1D array to match elements between.
metricfn (function, optional) – A function of two float parameters, x and y,which defines the cost associated with matching x with y. If None, abs(x-y) is used.
return_pairs (bool, optional) – If True, the matching is also returned.
pass_indices_to_metricfn (bool, optional) – If True, the metric function is passed two indices into the a and b arrays, respectively, instead of the values.
- Returns:
weight_array (numpy.ndarray) – The array of weights corresponding to the min-weight matching. The sum of this array’s elements is the minimized total weight.
pairs (list) – Only returned when return_pairs == True, a list of 2-tuple pairs of indices (ix,iy) giving the indices into a and b respectively of each matched pair. The first (ix) indices will be in continuous ascending order starting at zero.