JSPM

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

Fast Combinatorial Non-negative Least Squares

Package Exports

  • ml-fcnnls

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

fcnnls

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 an matrix and an matrix, find subject to , where is an matrix and is the Frobenius norm. In fact, is the best solution to the equation: , where . Note that if is a column vector, it performs the regular Non-negative Least Squares algorithm and finds a vector as a solution to the problem. Also, performing this algorithm when is a matrix is like running the algorithm on each column of , 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