🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

ml-levenberg-marquardt

Package Overview
Dependencies
Maintainers
7
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ml-levenberg-marquardt - npm Package Compare versions

Comparing version

to
4.1.1

8

lib-esm/checkOptions.js

@@ -19,3 +19,6 @@ import { isAnyArray } from 'is-any-array';

}
let parameters = initialValues || new Array(parameterizedFunction.length).fill(1);
if (!(initialValues && initialValues.length > 0)) {
throw new Error('The initialValues option is mandatory and must be an array');
}
let parameters = initialValues;
let nbPoints = data.y.length;

@@ -28,5 +31,2 @@ let parLen = parameters.length;

}
if (!isAnyArray(parameters)) {
throw new Error('initialValues must be an array');
}
if (typeof gradientDifference === 'number') {

@@ -33,0 +33,0 @@ gradientDifference = new Array(parameters.length).fill(gradientDifference);

/**
* Curve fitting algorithm
* @param {{x:ArrayLike<number>, y:ArrayLike<number>}} data - Array of points to fit in the format [x1, x2, ... ], [y1, y2, ... ]
* @param {function} parameterizedFunction - The parameters and returns a function with the independent variable as a parameter
* @param {function} parameterizedFunction - Takes an array of parameters and returns a function with the independent variable as its sole argument
* @param {object} [options] - Options object

@@ -6,0 +6,0 @@ * @param {number|ArrayLike<number>} [options.weights = 1] - weighting vector, if the length does not match with the number of data points, the vector is reconstructed with first value.

@@ -7,3 +7,3 @@ import checkOptions from './checkOptions';

* @param {{x:ArrayLike<number>, y:ArrayLike<number>}} data - Array of points to fit in the format [x1, x2, ... ], [y1, y2, ... ]
* @param {function} parameterizedFunction - The parameters and returns a function with the independent variable as a parameter
* @param {function} parameterizedFunction - Takes an array of parameters and returns a function with the independent variable as its sole argument
* @param {object} [options] - Options object

@@ -10,0 +10,0 @@ * @param {number|ArrayLike<number>} [options.weights = 1] - weighting vector, if the length does not match with the number of data points, the vector is reconstructed with first value.

@@ -21,3 +21,6 @@ "use strict";

}
let parameters = initialValues || new Array(parameterizedFunction.length).fill(1);
if (!(initialValues && initialValues.length > 0)) {
throw new Error('The initialValues option is mandatory and must be an array');
}
let parameters = initialValues;
let nbPoints = data.y.length;

@@ -30,5 +33,2 @@ let parLen = parameters.length;

}
if (!(0, is_any_array_1.isAnyArray)(parameters)) {
throw new Error('initialValues must be an array');
}
if (typeof gradientDifference === 'number') {

@@ -35,0 +35,0 @@ gradientDifference = new Array(parameters.length).fill(gradientDifference);

/**
* Curve fitting algorithm
* @param {{x:ArrayLike<number>, y:ArrayLike<number>}} data - Array of points to fit in the format [x1, x2, ... ], [y1, y2, ... ]
* @param {function} parameterizedFunction - The parameters and returns a function with the independent variable as a parameter
* @param {function} parameterizedFunction - Takes an array of parameters and returns a function with the independent variable as its sole argument
* @param {object} [options] - Options object

@@ -6,0 +6,0 @@ * @param {number|ArrayLike<number>} [options.weights = 1] - weighting vector, if the length does not match with the number of data points, the vector is reconstructed with first value.

@@ -13,3 +13,3 @@ "use strict";

* @param {{x:ArrayLike<number>, y:ArrayLike<number>}} data - Array of points to fit in the format [x1, x2, ... ], [y1, y2, ... ]
* @param {function} parameterizedFunction - The parameters and returns a function with the independent variable as a parameter
* @param {function} parameterizedFunction - Takes an array of parameters and returns a function with the independent variable as its sole argument
* @param {object} [options] - Options object

@@ -16,0 +16,0 @@ * @param {number|ArrayLike<number>} [options.weights = 1] - weighting vector, if the length does not match with the number of data points, the vector is reconstructed with first value.

{
"name": "ml-levenberg-marquardt",
"version": "4.1.0",
"version": "4.1.1",
"description": "Curve fitting method in javascript",

@@ -22,5 +22,4 @@ "main": "./lib/index.js",

"prettier-write": "prettier --write src",
"test": "npm run test-coverage && npm run eslint && npm run prettier && npm run check-types",
"test-coverage": "jest --coverage",
"test-only": "jest",
"test": "npm run test-only && npm run eslint && npm run prettier && npm run check-types",
"test-only": "jest --coverage",
"tsc": "npm run clean && npm run tsc-cjs && npm run tsc-esm",

@@ -50,9 +49,9 @@ "tsc-cjs": "tsc --project tsconfig.cjs.json",

"devDependencies": {
"@types/jest": "^27.4.0",
"@types/jest": "^27.4.1",
"benchmark": "^2.1.4",
"cheminfo-build": "^1.1.11",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^8.7.0",
"eslint": "^8.10.0",
"eslint-config-cheminfo-typescript": "^10.3.0",
"jest": "^27.4.7",
"jest": "^27.5.1",
"jest-matcher-deep-close-to": "^3.0.2",

@@ -66,3 +65,3 @@ "prettier": "^2.5.1",

"is-any-array": "^2.0.0",
"ml-matrix": "^6.8.2"
"ml-matrix": "^6.9.0"
},

@@ -69,0 +68,0 @@ "config": {

@@ -55,3 +55,3 @@ # levenberg-marquardt

// array of initial parameter values
// array of initial parameter values (must be provided)
let initialValues = [

@@ -92,5 +92,5 @@ /* a, b, c, ... */

[codecov-url]: https://codecov.io/gh/mljs/levenberg-marquardt
[ci-image]: https://github.com/mljs/levenberg-marquardt/workflows/Node.js%20CI/badge.svg?branch=master
[ci-image]: https://github.com/mljs/levenberg-marquardt/workflows/Node.js%20CI/badge.svg?branch=main
[ci-url]: https://github.com/mljs/levenberg-marquardt/actions?query=workflow%3A%22Node.js+CI%22
[download-image]: https://img.shields.io/npm/dm/ml-levenberg-marquardt.svg
[download-url]: https://npmjs.org/package/ml-levenberg-marquardt

@@ -21,9 +21,18 @@ import { toBeDeepCloseTo } from 'jest-matcher-deep-close-to';

it('Should throw an error when initialValues is not an array', () => {
const expectedErrorMessage =
'The initialValues option is mandatory and must be an array';
const inputData = { x: [1, 2], y: [1, 2] };
expect(() =>
levenbergMarquardt({ x: [1, 2], y: [1, 2] }, sinFunction, {
levenbergMarquardt(inputData, sinFunction, {
damping: 0.1,
//initialValues: undefined,
}),
).toThrow(expectedErrorMessage);
expect(() =>
levenbergMarquardt(inputData, sinFunction, {
damping: 0.1,
// @ts-expect-error
initialValues: 2,
}),
).toThrow('initialValues must be an array');
).toThrow(expectedErrorMessage);
});

@@ -30,0 +39,0 @@

@@ -37,4 +37,8 @@ import { isAnyArray } from 'is-any-array';

let parameters =
initialValues || new Array(parameterizedFunction.length).fill(1);
if (!(initialValues && initialValues.length > 0)) {
throw new Error(
'The initialValues option is mandatory and must be an array',
);
}
let parameters = initialValues;

@@ -50,6 +54,2 @@ let nbPoints = data.y.length;

if (!isAnyArray(parameters)) {
throw new Error('initialValues must be an array');
}
if (typeof gradientDifference === 'number') {

@@ -56,0 +56,0 @@ gradientDifference = new Array(parameters.length).fill(gradientDifference);

@@ -8,3 +8,3 @@ import checkOptions from './checkOptions';

* @param {{x:ArrayLike<number>, y:ArrayLike<number>}} data - Array of points to fit in the format [x1, x2, ... ], [y1, y2, ... ]
* @param {function} parameterizedFunction - The parameters and returns a function with the independent variable as a parameter
* @param {function} parameterizedFunction - Takes an array of parameters and returns a function with the independent variable as its sole argument
* @param {object} [options] - Options object

@@ -11,0 +11,0 @@ * @param {number|ArrayLike<number>} [options.weights = 1] - weighting vector, if the length does not match with the number of data points, the vector is reconstructed with first value.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet