Skip to content

Commit

Permalink
chore: update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
lpatiny committed Oct 14, 2024
1 parent 8bc5871 commit 81b5c5b
Show file tree
Hide file tree
Showing 14 changed files with 75 additions and 36 deletions.
1 change: 0 additions & 1 deletion .eslintrc.yml

This file was deleted.

14 changes: 14 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import cheminfo from 'eslint-config-cheminfo-typescript';
import globals from 'globals';

export default [
...cheminfo,
{
languageOptions: {
globals: {
...globals.node,
},
},
rules: {}
}
]
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@
},
"homepage": "https://github.com/mljs/fcnnls#readme",
"devDependencies": {
"@vitest/coverage-v8": "^0.34.5",
"eslint": "^8.50.0",
"eslint-config-cheminfo-typescript": "^12.0.4",
"prettier": "^3.0.3",
"rimraf": "^5.0.5",
"typescript": "^5.2.2",
"vitest": "^0.34.5"
"@vitest/coverage-v8": "^2.1.3",
"eslint": "^9.12.0",
"eslint-config-cheminfo-typescript": "^16.0.0",
"prettier": "^3.3.3",
"rimraf": "^6.0.1",
"typescript": "^5.6.3",
"vitest": "^2.1.3"
},
"dependencies": {
"ml-matrix": "^6.10.5"
"ml-matrix": "^6.11.1"
}
}
16 changes: 8 additions & 8 deletions src/__tests__/fcnnls.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readFileSync } from 'fs';
import { join } from 'path';
import { readFileSync } from 'node:fs';
import { join } from 'node:path';

import { Matrix } from 'ml-matrix';
import { it, describe, expect } from 'vitest';
Expand All @@ -8,31 +8,31 @@ import { fcnnls } from '../fcnnls';

import { assertResult } from './assertResult';

const concentration = readFileSync(join(__dirname, 'data/matrix.txt'), 'utf-8');
const concentration = readFileSync(join(__dirname, 'data/matrix.txt'), 'utf8');
const linesA = concentration.split(/[\r\n]+/);
const A: number[][] = [];
for (const line of linesA) {
A.push(line.split(',').map((value) => Number(value)));
A.push(line.split(',').map(Number));
}

let matrix = new Matrix(A);

matrix = matrix.transpose();

const proportion = readFileSync(join(__dirname, 'data/x_fcnnls.txt'), 'utf-8');
const proportion = readFileSync(join(__dirname, 'data/x_fcnnls.txt'), 'utf8');
const linesk = proportion.split(/[\r\n]+/);
const k: number[][] = [];
for (const line of linesk) {
k.push(line.split(',').map((value) => Number(value)));
k.push(line.split(',').map(Number));
}
k.splice(133, 1);
const answer = new Matrix(k);

const observation = readFileSync(join(__dirname, 'data/target.txt'), 'utf-8');
const observation = readFileSync(join(__dirname, 'data/target.txt'), 'utf8');
const lines = observation.split(/[\r\n]+/);
const b: number[][] = [];
for (const line of lines) {
b.push(line.split(',').map((value) => Number(value)));
b.push(line.split(',').map(Number));
}

let target = new Matrix(b);
Expand Down
7 changes: 6 additions & 1 deletion src/cssls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ import { sortCollectionSet } from './util/sortCollectionSet';
* Solves XtX*K = XtY for the variables in Pset
* if XtX (or XtX(vars,vars)) is singular, performs the svd and find pseudo-inverse, otherwise (even if ill-conditioned) finds inverse with LU decomposition and solves the set of equations
* it is consistent with matlab results for ill-conditioned matrices (at least consistent with test 'ill-conditioned square X rank 2, Y 3x1' in cssls.test)
* @param Cssls object, @see {@link Cssls}
* @param options - @see {@link Cssls}
* @param options.XtX

Check warning on line 16 in src/cssls.ts

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Missing JSDoc @param "options.XtX" description
* @param options.XtY

Check warning on line 17 in src/cssls.ts

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Missing JSDoc @param "options.XtY" description
* @param options.Pset

Check warning on line 18 in src/cssls.ts

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Missing JSDoc @param "options.Pset" description
* @param options.nColsX

Check warning on line 19 in src/cssls.ts

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Missing JSDoc @param "options.nColsX" description
* @param options.nColsY

Check warning on line 20 in src/cssls.ts

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Missing JSDoc @param "options.nColsY" description
*/
export function cssls({ XtX, XtY, Pset, nColsX, nColsY }: Cssls): Matrix {
let K = Matrix.zeros(nColsX, nColsY);
Expand Down
7 changes: 2 additions & 5 deletions src/fcnnls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface FcnnlsOptions<T extends boolean | undefined> {
* Fast Combinatorial Non-negative Least Squares with multiple Right Hand Side
* @param X - The data/input/predictors matrix
* @param Y - The response matrix
* @param options {@link FcnnlsOptions}
* @param options - {@link FcnnlsOptions}
* @returns By default, the object with the matrix of coefficients K. Please see {@link FcnnlsOutput} for more information.
*/
export function fcnnls(
Expand Down Expand Up @@ -175,10 +175,7 @@ export function fcnnls<T extends boolean | undefined>(
}

for (let j = 0; j < m; j++) {
Pset[Hset[j]].splice(
Pset[Hset[j]].findIndex((item) => item === minIdx[j]),
1,
);
Pset[Hset[j]].splice(Pset[Hset[j]].indexOf(minIdx[j]), 1);
}

L = cssls({
Expand Down
9 changes: 7 additions & 2 deletions src/initialisation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ interface Initialisation {
/**
* Solves OLS problem, overwriting the negative values of K with 0.
* It also pre-computes part of the pseudo-inverse used to solve Least Squares.
* @param XtX - input data matrix
* @param XtY - output data matrix
* @param options

Check warning on line 16 in src/initialisation.ts

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Missing JSDoc @param "options" description
* @param options.XtX - input data matrix
* @param options.XtY - output data matrix
* @param options.nRowsX
* @param options.nColsX
* @param options.nRowsY
* @param options.nColsY
* @returns initial values for the algorithm (including the solution K to least squares, overwriting of negative values with 0)
*/
export function initialisation({
Expand Down
17 changes: 15 additions & 2 deletions src/optimality.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,20 @@ import { setDifference } from './util/setDifference';

/**
* Checks whether the solution has converged
* @param see {@link OptimalityParams} for a description.
* {@link OptimalityParams} for a description.
* @param options
* @param options.iter
* @param options.maxIter
* @param options.XtX
* @param options.XtY
* @param options.Fset
* @param options.Pset
* @param options.W
* @param options.K
* @param options.l
* @param options.p
* @param options.D
* @param options.gradientTolerance
* @returns Pset, Fset, W
*/
export function optimality({
Expand Down Expand Up @@ -51,7 +64,7 @@ export function optimality({
Fset = setDifference(Fset, Jset);

// For non-optimal solutions, add the appropriate variables to Pset
if (Fset.length !== 0) {
if (Fset.length > 0) {
for (let j = 0; j < Fset.length; j++) {
for (let i = 0; i < l; i++) {
if (Pset[Fset[j]].includes(i)) W.set(i, Fset[j], -Infinity);
Expand Down
2 changes: 1 addition & 1 deletion src/util/diff.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Computes an array containing the difference of consecutive numbers
* @param Array v from which it computes the difference
* @param v - v from which it computes the difference
* @returns - Array of consecutive differences
*/
export function diff(v: number[]) {
Expand Down
6 changes: 5 additions & 1 deletion src/util/getRSE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { Matrix } from 'ml-matrix';

/**
* Return the root square error of the solution.
* @param object with X, K, Y, and error @see {@link GetRSEInput}
* @param object - with X, K, Y, and error @see {@link GetRSEInput}
* @param object.X
* @param object.K
* @param object.Y
* @param object.error
* @returns the root squared error array.
*/
export function getRSE({ X, K, Y, error }: GetRSEInput) {
Expand Down
3 changes: 2 additions & 1 deletion src/util/selection.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* Returns a new array based on extraction of specific indices of an array
* @param collection or array
* @param collection - or array
* @param vector
* @param indices
*/
export function selection<T extends number[] | number[][]>(
Expand Down
4 changes: 2 additions & 2 deletions src/util/setDifference.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Computes the set difference A\B
* @param set A as an array
* @param set B as an array
* @param A - First array of numbers
* @param B - Second array of numbers
* @returns Elements of A that are not in B
*/
export function setDifference(A: number[], B: number[]) {
Expand Down
2 changes: 1 addition & 1 deletion src/util/sortArray.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Sorts an array and returns an object with the sorted array and the corresponding indices.
* @param array
* @returns {values, indices}
* @returns
*/
export function sortArray(array: number[]) {
const v = array.map((value, index) => {
Expand Down
7 changes: 4 additions & 3 deletions src/util/sortCollectionSet.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* From an array of arrays it constructs a unique key for each array,
* given by its values, such that same arrays have same keys.
*
* @param collection - Array of arrays
* @returns - Array of objects with the original array, its index and its key
*/
Expand All @@ -10,7 +9,9 @@ function addUniqueKeyToColumns(collection: number[][]) {
//indices of positive values within the column. (Pset)
let key = BigInt(0);
// items will be the indexes of Pset, so it's always an integer.
positiveRows.forEach((item) => (key |= BigInt(1) << BigInt(item)));
for (const item of positiveRows) {
key |= BigInt(1) << BigInt(item);
}
return { positiveRows, columnIndexInK, key };
});
}
Expand Down Expand Up @@ -38,7 +39,7 @@ export function sortCollectionSet(collection: number[][]) {
indices.push([]);
sorted.push(set.positiveRows);
}
indices[indices.length - 1].push(set.columnIndexInK);
indices.at(-1).push(set.columnIndexInK);
}

const result = {
Expand Down

0 comments on commit 81b5c5b

Please sign in to comment.