linear sum assignment
Package to perform a linear sum assignment even if the cost matrix is rectangular.
This package is the implementation of Jonker-Volgenant shortest
augmenting path algorithm based on the publication On implementing 2D rectangular assignment algorithms
If the number of rows is <= the number of columns, then every row is assigned to one column; otherwise every column is assigned to one row. The assignment minimizes the sum of the assigned elements.
Instalation
$ npm i linear-sum-assignment
Usage
import linearSumAssignment from 'linear-sum-assignment';
const xValueExperimental = [1, 2, 3, 4, 5, 7];
const xValuePredicted = [3.1, 1.1, 1.9, 3.99, 5.2];
const diff = xValueExperimental.map((experimental) => {
return xValuePredicted.map((predicted) => {
return Math.abs(predicted - experimental);
});
});
const result = linearSumAssignment(diff, { maximaze: false });
console.log(result);
rowAssignments
contains the index of the column assigned to each element in the rows (xValueExperimental). So the first element in xValueExperimental array is assigned to the second element of xValuePredicted.
columnAssignments
contains the index of the row assigned to
each element in the columns. So the first element in
xValuePredicted is assigned to third element in
xValueExperimental.
dualVariableForColumns
and dualVariableForRows
are the Lagrange multipliers or dual variables.
gain
the sum of the elements in the cost matrix.
License
MIT