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,90 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createCorr = void 0;
var _factory = require("../../utils/factory.js");
const name = 'corr';
const dependencies = ['typed', 'matrix', 'mean', 'sqrt', 'sum', 'add', 'subtract', 'multiply', 'pow', 'divide'];
const createCorr = exports.createCorr = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
let {
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 (A, B) {
return _corr(A, B);
},
'Matrix, Matrix': function (A, B) {
const 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) {
const 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 (let 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) {
const n = A.length;
const sumX = sum(A);
const sumY = sum(B);
const sumXY = A.reduce((acc, x, index) => add(acc, multiply(x, B[index])), 0);
const sumXSquare = sum(A.map(x => pow(x, 2)));
const sumYSquare = sum(B.map(y => pow(y, 2)));
const numerator = subtract(multiply(n, sumXY), multiply(sumX, sumY));
const 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

70
node_modules/mathjs/lib/cjs/function/statistics/mad.js generated vendored Normal file
View File

@@ -0,0 +1,70 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createMad = void 0;
var _array = require("../../utils/array.js");
var _factory = require("../../utils/factory.js");
var _improveErrorMessage = require("./utils/improveErrorMessage.js");
const name = 'mad';
const dependencies = ['typed', 'abs', 'map', 'median', 'subtract'];
const createMad = exports.createMad = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
let {
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 = (0, _array.flatten)(array.valueOf());
if (array.length === 0) {
throw new Error('Cannot calculate median absolute deviation (mad) of an empty array');
}
try {
const 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 (0, _improveErrorMessage.improveErrorMessage)(err, 'mad');
}
}
}
});

111
node_modules/mathjs/lib/cjs/function/statistics/max.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

100
node_modules/mathjs/lib/cjs/function/statistics/mean.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

111
node_modules/mathjs/lib/cjs/function/statistics/min.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,82 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createMode = void 0;
var _array = require("../../utils/array.js");
var _factory = require("../../utils/factory.js");
const name = 'mode';
const dependencies = ['typed', 'isNaN', 'isNumeric'];
const createMode = exports.createMode = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
let {
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 = (0, _array.flatten)(values.valueOf());
const num = values.length;
if (num === 0) {
throw new Error('Cannot calculate mode of an empty array');
}
const count = {};
let mode = [];
let max = 0;
for (let i = 0; i < values.length; i++) {
const 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,85 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createProd = void 0;
var _collection = require("../../utils/collection.js");
var _factory = require("../../utils/factory.js");
var _number = require("../../utils/number.js");
var _improveErrorMessage = require("./utils/improveErrorMessage.js");
const name = 'prod';
const dependencies = ['typed', 'config', 'multiplyScalar', 'numeric'];
const createProd = exports.createProd = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
let {
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, 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) {
let prod;
(0, _collection.deepForEach)(array, function (value) {
try {
prod = prod === undefined ? value : multiplyScalar(prod, value);
} catch (err) {
throw (0, _improveErrorMessage.improveErrorMessage)(err, 'prod', value);
}
});
// make sure returning numeric value: parse a string into a numeric value
if (typeof prod === 'string') {
prod = numeric(prod, (0, _number.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