Skip to content

Commit ab9302b

Browse files
committed
Small fix for PLC but still not working properly
1 parent e309fb9 commit ab9302b

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/__tests__/matrix/positiveLinearCombination.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ describe('Non-negative Matrix Factorization', () => {
1515
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 100, 10],
1616
]);
1717
let vector = new Matrix([[0, 20, 100, 20, 0, 0, 0, 0, 0, 5, 100, 5, 0, 0, 0, 20, 200, 20]]);
18-
let solutions = Matrix.empty(1, base.columns);
19-
let expected = new Matrix([1, 0, 1, 0, 0, 2]);
18+
let solutions = Matrix.zeros(1, base.columns);
19+
let expected = new Matrix([[1, 0, 1, 0, 0, 2]]);
2020

2121
solutions = positiveLinearCombination(base, vector);
2222

src/positiveLinearCombination.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import AbstractMatrix from './abstractMatrix';
2+
13
import { Matrix, WrapperMatrix2D, NNMF } from './index';
24

35
function linearCombination(X, epsilon) {
@@ -38,7 +40,7 @@ export function positiveLinearCombination(base, vector, options = {}) {
3840
vector = WrapperMatrix2D.checkMatrix(vector);
3941
let m = base.rows + 1;
4042
let n = base.columns;
41-
let solutions = Matrix.empty(1, n);
43+
let solutions = Matrix.empty(1, m);
4244
let A = Matrix.empty(m, n);
4345

4446
if (vector.rows > 1) {
@@ -59,8 +61,8 @@ export function positiveLinearCombination(base, vector, options = {}) {
5961
for (let j = 0; j < n; j++) {
6062
A.set(m - 1, j, vector.get(0, j));
6163
}
62-
let nA = NNMF(A, 1, { maxIterations: NNMFmaxIterations, version: NNMFversion });
63-
solutions = linearCombination(nA.X, Matrix.min(nA.X) - Number.EPSILON);
64+
let nA = new NNMF(A, 1, { maxIterations: NNMFmaxIterations, version: NNMFversion });
65+
solutions = linearCombination(nA.X, nA.X.min() - Number.EPSILON);
6466
return (solutions);
6567
}
6668
}

0 commit comments

Comments
 (0)