diff --git a/README.md b/README.md index fb890dd..5ea69c7 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/package.json b/package.json index e3849d2..101be1d 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/src/.npmignore b/src/.npmignore index d7a3323..76cf446 100644 --- a/src/.npmignore +++ b/src/.npmignore @@ -1,2 +1,3 @@ __tests__ +.DS_Store .npmignore diff --git a/src/fcnnls.ts b/src/fcnnls.ts index 2a0f063..bf01727 100644 --- a/src/fcnnls.ts +++ b/src/fcnnls.ts @@ -70,10 +70,10 @@ export function fcnnls( // 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;