{"id":19267091,"url":"https://github.com/mljs/nnls","last_synced_at":"2025-10-26T23:41:12.262Z","repository":{"id":185298192,"uuid":"672671323","full_name":"mljs/nnls","owner":"mljs","description":"Non-Negative Least-Squares","archived":false,"fork":false,"pushed_at":"2023-10-24T13:33:56.000Z","size":97,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-02-15T09:11:28.882Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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}},"created_at":"2023-07-30T21:38:21.000Z","updated_at":"2023-09-28T15:42:37.000Z","dependencies_parsed_at":"2023-08-31T04:46:18.092Z","dependency_job_id":"f1dbb90e-d0be-47fe-90ee-82b9eee19332","html_url":"https://github.com/mljs/nnls","commit_stats":null,"previous_names":["santimirandarp/nnls","mljs/nnls"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Fnnls","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Fnnls/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Fnnls/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Fnnls/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mljs","download_url":"https://codeload.github.com/mljs/nnls/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240367677,"owners_count":19790294,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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:10:20.625Z","updated_at":"2025-10-26T23:41:07.229Z","avatar_url":"https://github.com/mljs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nnls\n\n[![NPM version][npm-image]][npm-url]\n[![build status][ci-image]][ci-url]\n[![Test coverage][codecov-image]][codecov-url]\n[![npm download][download-image]][download-url]\n\nNon-Negative Least-Squares (NNLS) algorithm, by Lawson and Hanson. It was mostly done for learning purposes, and will be improved over time.\n\nCurrently, it seems to match [scipy](https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.nnls.html), at least in some basic tests.\n\nYou are welcome to report issues and contribute to this project.\n\n## Installation\n\n`$ npm i nnls`\n\n## Basic Usage\n\n```js\nimport { nnls } from 'nnls';\n\nconst { x, d } = nnls(X, y); // result and dual vectors\n```\n\nThe code returns also the dual vector.\n\nYou can get execution information using the options:\n\n## Example with options\n\n```js\nimport { nnls } from 'nnls';\nimport { Matrix } from 'ml-matrix'; //npm i ml-matrix\nconst X = new Matrix([\n  [1, 0],\n  [2, 0],\n  [3, 0],\n  [0, 1],\n]);\nconst Y = Matrix.columnVector([1, 2, 3, 4]);\nconst solution = Matrix.columnVector([1, 4]);\nconst result = nnls(X, Y, { info: true });\nconsole.log(result.x.to1DArray(), result.info);\n/*\n  {\n  x: Matrix {\n    [\n      1.000000\n      4\n    ]\n    rows: 2\n    columns: 1\n  },\n  d: Matrix {\n    [\n      -3.6e-15\n       0\n    ]\n    rows: 2\n    columns: 1\n  },\n  info: {\n    rse: [ 5.477225575051661, 4, 1.0175362097255202e-15 ],\n    iterations: 3\n  }\n}\n * /\n```\n\n## [Documentation](https://mljs.github.io/nnls/)\n\n## Misc.\n\nLike other implementations (for example `scipy.optimize.nnls`) it is limited to a single vector $y$, or as it is called in the literature, a single right-hand-side (RHS).\n\nAs a minor addition to other implementations, you can pass `{ interceptAtZero:false }` then the result is consistent with $f(0)=C$.\n\nFor multiple RHS, you can take a look at [Fast-Combinatorial Non-Negative Least-Squares](https://github.com/mljs/fcnnls)\n\n## License\n\n[MIT](./LICENSE)\n\n[npm-image]: https://img.shields.io/npm/v/nnls.svg\n[npm-url]: https://www.npmjs.com/package/nnls\n[ci-image]: https://github.com/mljs/nnls/workflows/Node.js%20CI/badge.svg?branch=main\n[ci-url]: https://github.com/mljs/nnls/actions?query=workflow%3A%22Node.js+CI%22\n[codecov-image]: https://img.shields.io/codecov/c/github/mljs/nnls.svg\n[codecov-url]: https://codecov.io/gh/mljs/nnls\n[download-image]: https://img.shields.io/npm/dm/nnls.svg\n[download-url]: https://www.npmjs.com/package/nnls\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmljs%2Fnnls","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmljs%2Fnnls","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmljs%2Fnnls/lists"}