Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,30 @@ K = Matrix([
3. Using the options

```js
const K = fcnnls(X, Y, {
const { K, info } = fcnnls(X, Y, {
info: true, // returns the error/iteration.
maxIterations: 5,
gradientTolerance: 0,
});
/* same result than 2*/
/* K is the same result as in 2 */
/* info = { rse: [[...], [...], [...]], iterations: 3 } */
```

### Options

Both `fcnnls` and `fcnnlsVector` accept the same options.

| Option | Type | Default | Description |
| ------------------- | --------- | --------------- | ------------------------------------------------------------------------------------------------------- |
| `maxIterations` | `number` | `3 * X.columns` | Maximum number of iterations of the active-set loop. |
| `gradientTolerance` | `number` | `1e-5` | Larger values (like `1e-4`) can help when the iteration limit is exceeded. |
| `info` | `boolean` | `false` | When `true`, also returns `info` with the root squared error per column of `Y` and the iteration count. |
| `interceptAtZero` | `boolean` | `true` | Set to `false` to add a column of ones to the left of `X`, fitting an intercept. |

### Result

`K` is always a `Matrix` of non-negative coefficients. When `info: true`, the result also carries `info.rse` (root squared error, one row per computation of `K`) and `info.iterations`.

## [API Documentation](https://mljs.github.io/fcnnls/)

## License
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@
},
"homepage": "https://github.com/mljs/fcnnls#readme",
"dependencies": {
"ml-matrix": "^6.13.0"
"ml-matrix": "^6.14.0"
},
"devDependencies": {
"@types/node": "^26.0.0",
"@vitest/coverage-istanbul": "^4.1.9",
"@types/node": "^26.1.2",
"@vitest/coverage-istanbul": "^4.1.10",
"@zakodium/tsconfig": "^1.0.5",
"eslint": "^9.39.4",
"eslint-config-cheminfo-typescript": "^22.1.0",
"prettier": "^3.8.4",
"prettier": "^3.9.6",
"rimraf": "^6.1.3",
"typescript": "^6.0.3",
"vitest": "^4.1.9"
"vitest": "^4.1.10"
}
}
1 change: 1 addition & 0 deletions src/.npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
__tests__
.DS_Store
.npmignore
6 changes: 3 additions & 3 deletions src/fcnnls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ export function fcnnls<T extends boolean | undefined>(
// pre-computes part of pseudo-inverse. XtX is the symmetric Gram matrix XᵀX;
// gram() computes this bit-identically to Xt.mmul(X) but only fills the upper
// triangle, skips zeros and never materializes the transpose, so it is much
// faster on the sparse predictor matrices common here.
const Xt = X.transpose();
// faster on the sparse predictor matrices common here. transposeMultiply()
// applies the same trick to XᵀY.
const XtX = X.gram();
const XtY = Xt.mmul(Y);
const XtY = X.transposeMultiply(Y);

const { columns: nColsY, rows: nRowsY } = Y;
const { columns: nColsX, rows: nRowsX } = X;
Expand Down
Loading