Giter VIP home page Giter VIP logo

linear-sum-assignment's Introduction

linear sum assignment

Package to perform a linear sum assignment even if the cost matrix is rectangular.

NMReDATA

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';
import { xCostMatrix } from 'ml-spectra-processing';

/**
 * there is one more value in the experimental values, so one of
 * them will be not assigned.
 **/
const experimental = [1, 2, 3, 4, 5, 7];
const predicted = [3.1, 1.1, 1.9, 3.99, 5.2];

/**
 * We will compute a cost matrix where experimental are
 * rows and predicted in columns.
 * In this case we will look for the closest peak for each experimental peak value.
 **/

const diff = xCostMatrix(experimental, predicted, {
  fct: (a, b) => Math.abs(a - b),
});
const result = linearSumAssignment(diff, { maximaze: false });
console.log(result);
/**
{
  rowAssignments: Float64Array(6) [ 1, 2, 0, 3, 4, -1 ],
  columnAssignments: Float64Array(5) [ 2, 0, 1, 3, 4 ],
  gain: 0.5100000000000002,
  dualVariableForColumns: Float64Array(5) [
    0.0900000000000003,
    0.0900000000000003,
    0.0900000000000003,
    0,
    0.1900000000000004
  ],
  dualVariableForRows: Float64Array(6) [ 0, 0, 0, 0, 0, 0 ]
}
*/

rowAssignments contains the index of the column assigned to each element in the rows (experimental).

columnAssignments contains the index of the row assigned to each element in the columns. So the first element in predicted is assigned to third element in experimental. dualVariableForColumns and dualVariableForRows are the Lagrange multipliers or dual variables. gain the sum of the elements in the cost matrix.

License

MIT

linear-sum-assignment's People

Contributors

jobo322 avatar lpatiny avatar targos avatar

Watchers

 avatar  avatar  avatar  avatar

linear-sum-assignment's Issues

Simpler way ?

Could we have another method that calculates this internally ?

const diff = xValueExperimental.map((experimental) => {
  return xValuePredicted.map((predicted) => {
    return Math.abs(predicted - experimental);
  });
});

I don't know about a correct name but it would be something like:

abcd(experimental, predicted, {})

And one of the options could be a callback like
distance: (a,b) => Math.abs(a-b)

Add npm owners

Could you add 2 owners on npm

  • npm owner add lpatiny
  • npm owner add cheminfo-bot

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.