You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

ml-fcnnls

Package Overview
Dependencies
Maintainers
5
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ml-fcnnls

Fast Combinatorial Non-negative Least Squares


Version published
Weekly downloads
295
decreased by-22.98%
Maintainers
5
Install size
582 kB
Created
Weekly downloads
 

Readme

Source

fcnnls

NPM version build status Test coverage npm download DOI

Fast Combinatorial Non-negative Least Squares.

As described in the publication by Van Benthem and Keenan (10.1002/cem.889), which is in turn based on the active-set method algorithm previously published by Lawson and Hanson. The basic active-set method is implemented in the nnls repository.

Given the matrices $\mathbf{X}$ and $\mathbf{Y}$, the code finds the matrix $\mathbf{K}$ that minimises the squared Frobenius norm $$\mathrm{argmin}_K ||\mathbf{XK} -\mathbf{Y}||^2_F$$ subject to $\mathbf{K}\geq 0$.

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

Installation

npm i ml-fcnnls

Usage Example

  1. Single $y$, using arrays as inputs.
import { fcnnlsVector } from 'ml-fcnnls';

const X = [
  [1, 1, 2],
  [10, 11, -9],
  [-1, 0, 0],
  [-5, 6, -7],
];
const y = [-1, 11, 0, 1];

const k = fcnnlsVector(X, y).K.to1DArray();
/* k = [0.4610, 0.5611, 0] */
  1. Multiple RHS, using Matrix instances as inputs.
import { fcnnls } from 'ml-fcnnls';
import { Matrix } from 'ml-matrix'; //npm i ml-matrix

// Example with multiple RHS

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

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

const K = fcnnls(X, Y).K;
// `K.to2DArray()` converts the matrix to array.
/*
K = Matrix([
  [0.4610, 0, 4.9714, 0],
  [0.5611, 0, 4.7362, 2.2404],
  [0, 1.2388, 0, 1.9136],
])
*/
  1. Using the options
const K = fcnnls(X, Y, {
  info: true, // returns the error/iteration.
  maxIterations: 5,
  gradientTolerance: 0,
});
/* same result than 2*/

API Documentation

License

MIT

Keywords

FAQs

Package last updated on 12 Oct 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc