GithubHelp home page GithubHelp logo

fcnnls's Introduction

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

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

fcnnls's People

Contributors

lpatiny avatar targos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.