Skip to content

Commit 81b5c5b

Browse files
committed
chore: update dependencies
1 parent 8bc5871 commit 81b5c5b

14 files changed

+75
-36
lines changed

.eslintrc.yml

-1
This file was deleted.

eslint.config.mjs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import cheminfo from 'eslint-config-cheminfo-typescript';
2+
import globals from 'globals';
3+
4+
export default [
5+
...cheminfo,
6+
{
7+
languageOptions: {
8+
globals: {
9+
...globals.node,
10+
},
11+
},
12+
rules: {}
13+
}
14+
]

package.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@
4242
},
4343
"homepage": "https://github.com/mljs/fcnnls#readme",
4444
"devDependencies": {
45-
"@vitest/coverage-v8": "^0.34.5",
46-
"eslint": "^8.50.0",
47-
"eslint-config-cheminfo-typescript": "^12.0.4",
48-
"prettier": "^3.0.3",
49-
"rimraf": "^5.0.5",
50-
"typescript": "^5.2.2",
51-
"vitest": "^0.34.5"
45+
"@vitest/coverage-v8": "^2.1.3",
46+
"eslint": "^9.12.0",
47+
"eslint-config-cheminfo-typescript": "^16.0.0",
48+
"prettier": "^3.3.3",
49+
"rimraf": "^6.0.1",
50+
"typescript": "^5.6.3",
51+
"vitest": "^2.1.3"
5252
},
5353
"dependencies": {
54-
"ml-matrix": "^6.10.5"
54+
"ml-matrix": "^6.11.1"
5555
}
5656
}

src/__tests__/fcnnls.test.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { readFileSync } from 'fs';
2-
import { join } from 'path';
1+
import { readFileSync } from 'node:fs';
2+
import { join } from 'node:path';
33

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

99
import { assertResult } from './assertResult';
1010

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

1818
let matrix = new Matrix(A);
1919

2020
matrix = matrix.transpose();
2121

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

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

3838
let target = new Matrix(b);

src/cssls.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ import { sortCollectionSet } from './util/sortCollectionSet';
1212
* Solves XtX*K = XtY for the variables in Pset
1313
* 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
1414
* 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)
15-
* @param Cssls object, @see {@link Cssls}
15+
* @param options - @see {@link Cssls}
16+
* @param options.XtX
17+
* @param options.XtY
18+
* @param options.Pset
19+
* @param options.nColsX
20+
* @param options.nColsY
1621
*/
1722
export function cssls({ XtX, XtY, Pset, nColsX, nColsY }: Cssls): Matrix {
1823
let K = Matrix.zeros(nColsX, nColsY);

src/fcnnls.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export interface FcnnlsOptions<T extends boolean | undefined> {
3131
* Fast Combinatorial Non-negative Least Squares with multiple Right Hand Side
3232
* @param X - The data/input/predictors matrix
3333
* @param Y - The response matrix
34-
* @param options {@link FcnnlsOptions}
34+
* @param options - {@link FcnnlsOptions}
3535
* @returns By default, the object with the matrix of coefficients K. Please see {@link FcnnlsOutput} for more information.
3636
*/
3737
export function fcnnls(
@@ -175,10 +175,7 @@ export function fcnnls<T extends boolean | undefined>(
175175
}
176176

177177
for (let j = 0; j < m; j++) {
178-
Pset[Hset[j]].splice(
179-
Pset[Hset[j]].findIndex((item) => item === minIdx[j]),
180-
1,
181-
);
178+
Pset[Hset[j]].splice(Pset[Hset[j]].indexOf(minIdx[j]), 1);
182179
}
183180

184181
L = cssls({

src/initialisation.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,13 @@ interface Initialisation {
1313
/**
1414
* Solves OLS problem, overwriting the negative values of K with 0.
1515
* It also pre-computes part of the pseudo-inverse used to solve Least Squares.
16-
* @param XtX - input data matrix
17-
* @param XtY - output data matrix
16+
* @param options
17+
* @param options.XtX - input data matrix
18+
* @param options.XtY - output data matrix
19+
* @param options.nRowsX
20+
* @param options.nColsX
21+
* @param options.nRowsY
22+
* @param options.nColsY
1823
* @returns initial values for the algorithm (including the solution K to least squares, overwriting of negative values with 0)
1924
*/
2025
export function initialisation({

src/optimality.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,20 @@ import { setDifference } from './util/setDifference';
44

55
/**
66
* Checks whether the solution has converged
7-
* @param see {@link OptimalityParams} for a description.
7+
* {@link OptimalityParams} for a description.
8+
* @param options
9+
* @param options.iter
10+
* @param options.maxIter
11+
* @param options.XtX
12+
* @param options.XtY
13+
* @param options.Fset
14+
* @param options.Pset
15+
* @param options.W
16+
* @param options.K
17+
* @param options.l
18+
* @param options.p
19+
* @param options.D
20+
* @param options.gradientTolerance
821
* @returns Pset, Fset, W
922
*/
1023
export function optimality({
@@ -51,7 +64,7 @@ export function optimality({
5164
Fset = setDifference(Fset, Jset);
5265

5366
// For non-optimal solutions, add the appropriate variables to Pset
54-
if (Fset.length !== 0) {
67+
if (Fset.length > 0) {
5568
for (let j = 0; j < Fset.length; j++) {
5669
for (let i = 0; i < l; i++) {
5770
if (Pset[Fset[j]].includes(i)) W.set(i, Fset[j], -Infinity);

src/util/diff.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* Computes an array containing the difference of consecutive numbers
3-
* @param Array v from which it computes the difference
3+
* @param v - v from which it computes the difference
44
* @returns - Array of consecutive differences
55
*/
66
export function diff(v: number[]) {

src/util/getRSE.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import { Matrix } from 'ml-matrix';
22

33
/**
44
* Return the root square error of the solution.
5-
* @param object with X, K, Y, and error @see {@link GetRSEInput}
5+
* @param object - with X, K, Y, and error @see {@link GetRSEInput}
6+
* @param object.X
7+
* @param object.K
8+
* @param object.Y
9+
* @param object.error
610
* @returns the root squared error array.
711
*/
812
export function getRSE({ X, K, Y, error }: GetRSEInput) {

src/util/selection.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/**
22
* Returns a new array based on extraction of specific indices of an array
3-
* @param collection or array
3+
* @param collection - or array
4+
* @param vector
45
* @param indices
56
*/
67
export function selection<T extends number[] | number[][]>(

src/util/setDifference.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Computes the set difference A\B
3-
* @param set A as an array
4-
* @param set B as an array
3+
* @param A - First array of numbers
4+
* @param B - Second array of numbers
55
* @returns Elements of A that are not in B
66
*/
77
export function setDifference(A: number[], B: number[]) {

src/util/sortArray.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Sorts an array and returns an object with the sorted array and the corresponding indices.
33
* @param array
4-
* @returns {values, indices}
4+
* @returns
55
*/
66
export function sortArray(array: number[]) {
77
const v = array.map((value, index) => {

src/util/sortCollectionSet.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/**
22
* From an array of arrays it constructs a unique key for each array,
33
* given by its values, such that same arrays have same keys.
4-
*
54
* @param collection - Array of arrays
65
* @returns - Array of objects with the original array, its index and its key
76
*/
@@ -10,7 +9,9 @@ function addUniqueKeyToColumns(collection: number[][]) {
109
//indices of positive values within the column. (Pset)
1110
let key = BigInt(0);
1211
// items will be the indexes of Pset, so it's always an integer.
13-
positiveRows.forEach((item) => (key |= BigInt(1) << BigInt(item)));
12+
for (const item of positiveRows) {
13+
key |= BigInt(1) << BigInt(item);
14+
}
1415
return { positiveRows, columnIndexInK, key };
1516
});
1617
}
@@ -38,7 +39,7 @@ export function sortCollectionSet(collection: number[][]) {
3839
indices.push([]);
3940
sorted.push(set.positiveRows);
4041
}
41-
indices[indices.length - 1].push(set.columnIndexInK);
42+
indices.at(-1).push(set.columnIndexInK);
4243
}
4344

4445
const result = {

0 commit comments

Comments
 (0)