essy-nnls
v1.0.3
Published
Wrapper for native C non-negative least squares (NNLS) algorithm.
Downloads
3
Readme
README
Wrapper for nnls.c as implemented in Chordino / Chroma NNLS by Matthias Mauch and Chris Cannon. See http://www.isophonics.net/nnls-chroma.
Documentation
The package exposes a single function NNLS(a, b, m, n, tol)
.
a {Float32Array}
A flat m x n matrix. m0n0, m1,n0, m2,n0 ... mN,nN.b {Float32Array}
An m-length vector.m {Number}
Number of rows.n {Number}
Number of columns.tol {Number}
Tolerance for precision. 0 produces best results, higher values (eg, 0.01) faster but more approximate.
Returns an n-length Float32Array
.
Example usage.
import essyNNLS from 'essy-nnls';
const a = new Float32Array(8);
a[0] = 0.0372; // m0, n0
a[1] = 0.6861; // m1, n0
a[2] = 0.6233; // m2, n0
a[3] = 0.6344; // m3, n0
a[4] = 0.2869; // m0, n1
a[5] = 0.7071; // m1, n1
a[6] = 0.6245; // m2, n1
a[7] = 0.6170; // m3, n1
const b = new Float32Array(4);
b[0] = 0.8587;
b[1] = 0.1781;
b[2] = 0.0747;
b[3] = 0.8405;
essyNNLS.NNLS(a, b, 4, 2, 0); // => [0, 0.629]