{"id":19267042,"url":"https://github.com/mljs/linear-sum-assignment","last_synced_at":"2026-02-07T07:02:08.549Z","repository":{"id":39743169,"uuid":"488319120","full_name":"mljs/linear-sum-assignment","owner":"mljs","description":"Package to perform a linear sum assignment even if the cost matrix is rectangular.","archived":false,"fork":false,"pushed_at":"2024-03-16T10:29:18.000Z","size":465,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-10-19T22:30:04.549Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mljs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-05-03T18:22:46.000Z","updated_at":"2024-03-16T10:26:55.000Z","dependencies_parsed_at":"2024-03-07T17:52:35.455Z","dependency_job_id":"897fa3d0-0266-40ce-b5cd-990c2141d503","html_url":"https://github.com/mljs/linear-sum-assignment","commit_stats":null,"previous_names":["jobo322/linear-sum-assignment"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/mljs/linear-sum-assignment","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Flinear-sum-assignment","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Flinear-sum-assignment/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Flinear-sum-assignment/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Flinear-sum-assignment/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mljs","download_url":"https://codeload.github.com/mljs/linear-sum-assignment/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Flinear-sum-assignment/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29188304,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-07T05:07:31.176Z","status":"ssl_error","status_checked_at":"2026-02-07T05:06:15.227Z","response_time":63,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T20:09:40.962Z","updated_at":"2026-02-07T07:02:08.530Z","avatar_url":"https://github.com/mljs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# linear sum assignment\n\n\u003cp align=\"center\"\u003e\n  Package to perform a linear sum assignment even if the cost matrix is rectangular.\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n  \u003cimg alt=\"NMReDATA\" src=\"images/linear_assignment.svg\"\u003e\n\u003c/p\u003e\n\nThis package is the implementation of Jonker-Volgenant shortest\naugmenting path algorithm based on the publication [On implementing 2D rectangular assignment algorithms](https://doi.org/10.1109/TAES.2016.140952)\n\nIf the number of rows is \u003c= 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.\n\n## Instalation\n\n`$ npm i linear-sum-assignment`\n\n## Usage\n\n```js\nimport linearSumAssignment from 'linear-sum-assignment';\nimport { xCostMatrix } from 'ml-spectra-processing';\n\n/**\n * there is one more value in the experimental values, so one of\n * them will be not assigned.\n **/\nconst experimental = [1, 2, 3, 4, 5, 7];\nconst predicted = [3.1, 1.1, 1.9, 3.99, 5.2];\n\n/**\n * We will compute a cost matrix where experimental are\n * rows and predicted in columns.\n * In this case we will look for the closest peak for each experimental peak value.\n **/\n\nconst diff = xCostMatrix(experimental, predicted, {\n  fct: (a, b) =\u003e Math.abs(a - b),\n});\nconst result = linearSumAssignment(diff, { maximaze: false });\nconsole.log(result);\n/**\n{\n  rowAssignments: Float64Array(6) [ 1, 2, 0, 3, 4, -1 ],\n  columnAssignments: Float64Array(5) [ 2, 0, 1, 3, 4 ],\n  gain: 0.5100000000000002,\n  dualVariableForColumns: Float64Array(5) [\n    0.0900000000000003,\n    0.0900000000000003,\n    0.0900000000000003,\n    0,\n    0.1900000000000004\n  ],\n  dualVariableForRows: Float64Array(6) [ 0, 0, 0, 0, 0, 0 ]\n}\n*/\n```\n\n`rowAssignments` contains the index of the column assigned to each element in the rows (experimental).\n\n`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.\n`dualVariableForColumns` and `dualVariableForRows` are the Lagrange multipliers or dual variables.\n`gain` the sum of the elements in the cost matrix.\n\n## License\n\n[MIT](./LICENSE)\n\n[npm-image]: https://img.shields.io/npm/v/linearSumAssignment.svg\n[npm-url]: https://www.npmjs.com/package/linearSumAssignment\n[ci-image]: https://github.com/mljs/linear-sum-assignment/workflows/Node.js%20CI/badge.svg?branch=main\n[ci-url]: https://github.com/mljs/linear-sum-assignment/actions?query=workflow%3A%22Node.js+CI%22\n[codecov-image]: https://img.shields.io/codecov/c/github/mljs/linear-sum-assignment.svg\n[codecov-url]: https://codecov.io/gh/mljs/linear-sum-assignment\n[download-image]: https://img.shields.io/npm/dm/linearSumAssignment.svg\n[download-url]: https://www.npmjs.com/package/linearSumAssignment\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmljs%2Flinear-sum-assignment","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmljs%2Flinear-sum-assignment","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmljs%2Flinear-sum-assignment/lists"}