JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 173
  • Score
    100M100P100Q91323F
  • License MIT

Fast Combinatorial Non-negative Least Squares

Package Exports

  • ml-fcnnls
  • ml-fcnnls/fcnnls.js
  • ml-fcnnls/src/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ml-fcnnls) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

cnnls

NPM version build status Test coverage npm download

Fast Combinatorial Non-negative Least Squares.

Fast algorithm for the solution of large‐scale non‐negativity‐constrained least squares problems from Van Benthem and Keenan (10.1002/cem.889), based on the active-set method algorithm published by Lawson and Hanson.

It solves the following optimisation problem. Given $\mathbf{X}$ an $n \times l$ matrix and $\mathbf{Y}$ an $n\times p$, find $$\mathrm{argmin}_K ||\mathbf{XK} -\mathbf{Y}||^2_F$$ subject to $\mathbf{K}\geq 0$, where $\mathbf{K}$ is an $l \times p$ matrix and $||\ldots||_F$ is the Frobenius norm. In fact, $\mathbf{K}$ is the best solution to the equation: $\mathbf{XK}=\mathbf{Y}$, where $\mathbf{K} \geq 0$, it performs the regular Non-negative Least Squares algorithm and finds a vector as a solution to the problem. Also, performing this algorithm when $\mathbf{Y}$ is a matrix is like running the algorithm on each column of $\mathbf{Y}$, it will give the same result but in a much more efficient way.

https://en.wikipedia.org/wiki/Non-negative_least_squares

Installation

$ npm i ml-fcnnls

API Documentation

Usage

import { Matrix } from 'ml-matrix';
import { fcnnls } from 'ml-fcnnls';

// Example with multiple RHS

let X = new Matrix([
  [1, 1, 2],
  [10, 11, -9],
  [-1, 0, 0],
  [-5, 6, -7],
]);

// Y can either be a Matrix of an array of array
let Y = new Matrix([
  [-1, 0, 0, 9],
  [11, -20, 103, 5],
  [0, 0, 0, 0],
  [1, 2, 3, 4],
]);

let K = fcnnls(X, Y);

/*
K = Matrix([
  [0.461, 0, 4.9714, 0],
  [0.5611, 0, 4.7362, 2.2404],
  [0, 1.2388, 0, 1.9136],
    ])
*/

import { fcnnlsVector } from 'ml-fcnnls';

// Example with single RHS and same X
// Should be giving a vector with the element of the first column of K in the previous example, since y is the first column of Y

let X = new Matrix([
  [1, 1, 2],
  [10, 11, -9],
  [-1, 0, 0],
  [-5, 6, -7],
]);

let y = [-1, 11, 0, 1];

let k = fcnnlsVector(X, y);

/*
k = [0.461, 0.5611, 0]
*/

License

MIT