Skip to content

Commit 7d1b4a1

Browse files
committed
Fix : NOW WORKING for the example
1 parent f83557f commit 7d1b4a1

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/positiveLinearCombination.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import { Matrix, WrapperMatrix2D, NNMF } from './index';
22

3-
function linearCombination(X, epsilon) {
3+
function linearCombination(X) {
44
if (X.rows > 1) {
55
X = X.transpose();
66
}
77
let solutions = Matrix.zeros(1, X.columns);
88
let notTheEnd = true;
99
let vecVal = X.get(0, X.columns - 1);
1010
let tmp = 0;
11-
while (vecVal > epsilon && notTheEnd) {
11+
while ((vecVal > 0) && notTheEnd) {
1212
notTheEnd = false;
13-
for (let i = 0; i < X.columns; i++) {
13+
for (let i = 0; i < X.columns - 1; i++) {
1414
tmp = vecVal - X.get(0, i);
15-
if (tmp > epsilon) {
15+
if (tmp >= 0 && X.get(0, i) > 0) {
16+
console.table(solutions);
1617
solutions.set(0, i, solutions.get(0, i) + 1);
1718
vecVal = tmp;
1819
notTheEnd = true;
@@ -73,7 +74,19 @@ export function positiveLinearCombination(base, vector, options = {}) {
7374

7475
console.table(nA.X);
7576

76-
solutions = linearCombination(nA.X, nA.X.min() - Number.EPSILON);
77+
solutions = linearCombination(nA.X, nA.X.min() + Number.EPSILON);
7778
return (solutions);
7879
}
7980
}
81+
let base = new Matrix([
82+
[0, 20, 100, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
83+
[0, 0, 0, 0, 0, 30, 100, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
84+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 100, 5, 0, 0, 0, 0, 0, 0],
85+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 100, 15, 0, 0, 0],
86+
[0, 0, 0, 0, 0, 0, 0, 10, 100, 10, 0, 0, 0, 0, 0, 0, 0, 0],
87+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 100, 10],
88+
]);
89+
let vector = new Matrix([[0, 20, 100, 20, 0, 0, 0, 0, 0, 5, 100, 5, 0, 0, 0, 20, 200, 20]]);
90+
let solutions = Matrix.zeros(1, base.columns);
91+
92+
solutions = positiveLinearCombination(base, vector);

0 commit comments

Comments
 (0)