Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mljs/matrix
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 3b210a6f5883138dd8fb0dec248210c8558a7a24
Choose a base ref
..
head repository: mljs/matrix
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: f83557f27ed5cb679368f4e81e6707269f9d57cc
Choose a head ref
Showing with 8 additions and 5 deletions.
  1. +8 −5 src/positiveLinearCombination.js
13 changes: 8 additions & 5 deletions src/positiveLinearCombination.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { Matrix, WrapperMatrix2D, NNMF } from './index';

function linearCombination(X) {
function linearCombination(X, epsilon) {
if (X.rows > 1) {
X = X.transpose();
}
let solutions = Matrix.zeros(1, X.columns);
let notTheEnd = true;
let vecVal = X.get(0, X.columns - 1);
let tmp = 0;
while ((vecVal > 0) && notTheEnd) {
while (vecVal > epsilon && notTheEnd) {
notTheEnd = false;
for (let i = 0; i < X.columns - 1; i++) {
for (let i = 0; i < X.columns; i++) {
tmp = vecVal - X.get(0, i);
if (tmp >= 0 && X.get(0, i) > 0) {
if (tmp > epsilon) {
solutions.set(0, i, solutions.get(0, i) + 1);
vecVal = tmp;
notTheEnd = true;
@@ -63,14 +63,17 @@ export function positiveLinearCombination(base, vector, options = {}) {

let nA = new NNMF(A, 1, { maxIterations: NNMFmaxIterations, version: NNMFversion });

console.table(nA.X);

for (let i = 0; i < m; i++) {
if ((nA.X.get(m - 1, 0) / delta) > nA.X.get(i, 0)) {
nA.X.set(i, 0, 0);
}
}

solutions = linearCombination(nA.X, nA.X.min() + Number.EPSILON);
console.table(nA.X);

solutions = linearCombination(nA.X, nA.X.min() - Number.EPSILON);
return (solutions);
}
}