feat:node-modules

This commit is contained in:
houjunxiang
2025-11-24 10:26:18 +08:00
parent 753766893b
commit 8a3e48d856
8825 changed files with 567399 additions and 1 deletions

View File

@@ -0,0 +1,84 @@
import { factory } from '../../utils/factory.js';
var name = 'corr';
var dependencies = ['typed', 'matrix', 'mean', 'sqrt', 'sum', 'add', 'subtract', 'multiply', 'pow', 'divide'];
export var createCorr = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed,
matrix,
sqrt,
sum,
add,
subtract,
multiply,
pow,
divide
} = _ref;
/**
* Compute the correlation coefficient of a two list with values, For matrices, the matrix correlation coefficient is calculated.
*
* Syntax:
*
* math.corr(A, B)
*
* Examples:
*
* math.corr([1, 2, 3, 4, 5], [4, 5, 6, 7, 8]) // returns 1
* math.corr([1, 2.2, 3, 4.8, 5], [4, 5.3, 6.6, 7, 8]) //returns 0.9569941688503644
* math.corr([[1, 2.2, 3, 4.8, 5], [4, 5.3, 6.6, 7, 8]],[[1, 2.2, 3, 4.8, 5], [4, 5.3, 6.6, 7, 8]]) // returns [1,1]
*
* See also:
*
* median, mean, min, max, sum, prod, std, variance
*
* @param {Array | Matrix} A The first array or matrix to compute correlation coefficient
* @param {Array | Matrix} B The second array or matrix to compute correlation coefficient
* @return {*} The correlation coefficient
*/
return typed(name, {
'Array, Array': function Array_Array(A, B) {
return _corr(A, B);
},
'Matrix, Matrix': function Matrix_Matrix(A, B) {
var res = _corr(A.toArray(), B.toArray());
return Array.isArray(res) ? matrix(res) : res;
}
});
/**
* Calculate the correlation coefficient between two arrays or matrices.
* @param {Array | Matrix} A
* @param {Array | Matrix} B
* @return {*} correlation coefficient
* @private
*/
function _corr(A, B) {
var correlations = [];
if (Array.isArray(A[0]) && Array.isArray(B[0])) {
if (A.length !== B.length) {
throw new SyntaxError('Dimension mismatch. Array A and B must have the same length.');
}
for (var i = 0; i < A.length; i++) {
if (A[i].length !== B[i].length) {
throw new SyntaxError('Dimension mismatch. Array A and B must have the same number of elements.');
}
correlations.push(correlation(A[i], B[i]));
}
return correlations;
} else {
if (A.length !== B.length) {
throw new SyntaxError('Dimension mismatch. Array A and B must have the same number of elements.');
}
return correlation(A, B);
}
}
function correlation(A, B) {
var n = A.length;
var sumX = sum(A);
var sumY = sum(B);
var sumXY = A.reduce((acc, x, index) => add(acc, multiply(x, B[index])), 0);
var sumXSquare = sum(A.map(x => pow(x, 2)));
var sumYSquare = sum(B.map(y => pow(y, 2)));
var numerator = subtract(multiply(n, sumXY), multiply(sumX, sumY));
var denominator = sqrt(multiply(subtract(multiply(n, sumXSquare), pow(sumX, 2)), subtract(multiply(n, sumYSquare), pow(sumY, 2))));
return divide(numerator, denominator);
}
});

File diff suppressed because it is too large Load Diff

64
node_modules/mathjs/lib/esm/function/statistics/mad.js generated vendored Normal file
View File

@@ -0,0 +1,64 @@
import { flatten } from '../../utils/array.js';
import { factory } from '../../utils/factory.js';
import { improveErrorMessage } from './utils/improveErrorMessage.js';
var name = 'mad';
var dependencies = ['typed', 'abs', 'map', 'median', 'subtract'];
export var createMad = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed,
abs,
map,
median,
subtract
} = _ref;
/**
* Compute the median absolute deviation of a matrix or a list with values.
* The median absolute deviation is defined as the median of the absolute
* deviations from the median.
*
* Syntax:
*
* math.mad(a, b, c, ...)
* math.mad(A)
*
* Examples:
*
* math.mad(10, 20, 30) // returns 10
* math.mad([1, 2, 3]) // returns 1
* math.mad([[1, 2, 3], [4, 5, 6]]) // returns 1.5
*
* See also:
*
* median, mean, std, abs
*
* @param {Array | Matrix} array
* A single matrix or multiple scalar values.
* @return {*} The median absolute deviation.
*/
return typed(name, {
// mad([a, b, c, d, ...])
'Array | Matrix': _mad,
// mad(a, b, c, d, ...)
'...': function _(args) {
return _mad(args);
}
});
function _mad(array) {
array = flatten(array.valueOf());
if (array.length === 0) {
throw new Error('Cannot calculate median absolute deviation (mad) of an empty array');
}
try {
var med = median(array);
return median(map(array, function (value) {
return abs(subtract(value, med));
}));
} catch (err) {
if (err instanceof TypeError && err.message.includes('median')) {
throw new TypeError(err.message.replace('median', 'mad'));
} else {
throw improveErrorMessage(err, 'mad');
}
}
}
});

105
node_modules/mathjs/lib/esm/function/statistics/max.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,94 @@
import { containsCollections, deepForEach, reduce } from '../../utils/collection.js';
import { arraySize } from '../../utils/array.js';
import { factory } from '../../utils/factory.js';
import { improveErrorMessage } from './utils/improveErrorMessage.js';
var name = 'mean';
var dependencies = ['typed', 'add', 'divide'];
export var createMean = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed,
add,
divide
} = _ref;
/**
* Compute the mean value of matrix or a list with values.
* In case of a multidimensional array, the mean of the flattened array
* will be calculated. When `dim` is provided, the maximum over the selected
* dimension will be calculated. Parameter `dim` is zero-based.
*
* Syntax:
*
* math.mean(a, b, c, ...)
* math.mean(A)
* math.mean(A, dimension)
*
* Examples:
*
* math.mean(2, 1, 4, 3) // returns 2.5
* math.mean([1, 2.7, 3.2, 4]) // returns 2.725
*
* math.mean([[2, 5], [6, 3], [1, 7]], 0) // returns [3, 5]
* math.mean([[2, 5], [6, 3], [1, 7]], 1) // returns [3.5, 4.5, 4]
*
* See also:
*
* median, min, max, sum, prod, std, variance
*
* @param {... *} args A single matrix or or multiple scalar values
* @return {*} The mean of all values
*/
return typed(name, {
// mean([a, b, c, d, ...])
'Array | Matrix': _mean,
// mean([a, b, c, d, ...], dim)
'Array | Matrix, number | BigNumber': _nmeanDim,
// mean(a, b, c, d, ...)
'...': function _(args) {
if (containsCollections(args)) {
throw new TypeError('Scalar values expected in function mean');
}
return _mean(args);
}
});
/**
* Calculate the mean value in an n-dimensional array, returning a
* n-1 dimensional array
* @param {Array} array
* @param {number} dim
* @return {number} mean
* @private
*/
function _nmeanDim(array, dim) {
try {
var sum = reduce(array, dim, add);
var s = Array.isArray(array) ? arraySize(array) : array.size();
return divide(sum, s[dim]);
} catch (err) {
throw improveErrorMessage(err, 'mean');
}
}
/**
* Recursively calculate the mean value in an n-dimensional array
* @param {Array} array
* @return {number} mean
* @private
*/
function _mean(array) {
var sum;
var num = 0;
deepForEach(array, function (value) {
try {
sum = sum === undefined ? value : add(sum, value);
num++;
} catch (err) {
throw improveErrorMessage(err, 'mean', value);
}
});
if (num === 0) {
throw new Error('Cannot calculate the mean of an empty array');
}
return divide(sum, num);
}
});

File diff suppressed because it is too large Load Diff

105
node_modules/mathjs/lib/esm/function/statistics/min.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,76 @@
import { flatten } from '../../utils/array.js';
import { factory } from '../../utils/factory.js';
var name = 'mode';
var dependencies = ['typed', 'isNaN', 'isNumeric'];
export var createMode = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed,
isNaN,
isNumeric
} = _ref;
/**
* Computes the mode of a set of numbers or a list with values(numbers or characters).
* If there are multiple modes, it returns a list of those values.
*
* Syntax:
*
* math.mode(a, b, c, ...)
* math.mode(A)
*
* Examples:
*
* math.mode(2, 1, 4, 3, 1) // returns [1]
* math.mode([1, 2.7, 3.2, 4, 2.7]) // returns [2.7]
* math.mode(1, 4, 6, 1, 6) // returns [1, 6]
* math.mode('a','a','b','c') // returns ["a"]
* math.mode(1, 1.5, 'abc') // returns [1, 1.5, "abc"]
*
* See also:
*
* median,
* mean
*
* @param {... *} args A single matrix
* @return {*} The mode of all values
*/
return typed(name, {
'Array | Matrix': _mode,
'...': function _(args) {
return _mode(args);
}
});
/**
* Calculates the mode in an 1-dimensional array
* @param {Array} values
* @return {Array} mode
* @private
*/
function _mode(values) {
values = flatten(values.valueOf());
var num = values.length;
if (num === 0) {
throw new Error('Cannot calculate mode of an empty array');
}
var count = {};
var mode = [];
var max = 0;
for (var i = 0; i < values.length; i++) {
var value = values[i];
if (isNumeric(value) && isNaN(value)) {
throw new Error('Cannot calculate mode of an array containing NaN values');
}
if (!(value in count)) {
count[value] = 0;
}
count[value]++;
if (count[value] === max) {
mode.push(value);
} else if (count[value] > max) {
max = count[value];
mode = [value];
}
}
return mode;
}
});

View File

@@ -0,0 +1,79 @@
import { deepForEach } from '../../utils/collection.js';
import { factory } from '../../utils/factory.js';
import { safeNumberType } from '../../utils/number.js';
import { improveErrorMessage } from './utils/improveErrorMessage.js';
var name = 'prod';
var dependencies = ['typed', 'config', 'multiplyScalar', 'numeric'];
export var createProd = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed,
config,
multiplyScalar,
numeric
} = _ref;
/**
* Compute the product of a matrix or a list with values.
* In case of a multidimensional array or matrix, the sum of all
* elements will be calculated.
*
* Syntax:
*
* math.prod(a, b, c, ...)
* math.prod(A)
*
* Examples:
*
* math.multiply(2, 3) // returns 6
* math.prod(2, 3) // returns 6
* math.prod(2, 3, 4) // returns 24
* math.prod([2, 3, 4]) // returns 24
* math.prod([[2, 5], [4, 3]]) // returns 120
*
* See also:
*
* mean, median, min, max, sum, std, variance
*
* @param {... *} args A single matrix or or multiple scalar values
* @return {*} The product of all values
*/
return typed(name, {
// prod([a, b, c, d, ...])
'Array | Matrix': _prod,
// prod([a, b, c, d, ...], dim)
'Array | Matrix, number | BigNumber': function Array__Matrix_number__BigNumber(array, dim) {
// TODO: implement prod(A, dim)
throw new Error('prod(A, dim) is not yet supported');
// return reduce(arguments[0], arguments[1], math.prod)
},
// prod(a, b, c, d, ...)
'...': function _(args) {
return _prod(args);
}
});
/**
* Recursively calculate the product of an n-dimensional array
* @param {Array} array
* @return {number} prod
* @private
*/
function _prod(array) {
var prod;
deepForEach(array, function (value) {
try {
prod = prod === undefined ? value : multiplyScalar(prod, value);
} catch (err) {
throw improveErrorMessage(err, 'prod', value);
}
});
// make sure returning numeric value: parse a string into a numeric value
if (typeof prod === 'string') {
prod = numeric(prod, safeNumberType(prod, config));
}
if (prod === undefined) {
throw new Error('Cannot calculate prod of an empty array');
}
return prod;
}
});

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More