feat:node-modules
This commit is contained in:
75
node_modules/mathjs/lib/cjs/function/probability/combinations.js
generated
vendored
Normal file
75
node_modules/mathjs/lib/cjs/function/probability/combinations.js
generated
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.createCombinations = void 0;
|
||||
var _factory = require("../../utils/factory.js");
|
||||
var _combinations = require("../../plain/number/combinations.js");
|
||||
const name = 'combinations';
|
||||
const dependencies = ['typed'];
|
||||
const createCombinations = exports.createCombinations = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
|
||||
let {
|
||||
typed
|
||||
} = _ref;
|
||||
/**
|
||||
* Compute the number of ways of picking `k` unordered outcomes from `n`
|
||||
* possibilities.
|
||||
*
|
||||
* Combinations only takes integer arguments.
|
||||
* The following condition must be enforced: k <= n.
|
||||
*
|
||||
* Syntax:
|
||||
*
|
||||
* math.combinations(n, k)
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* math.combinations(7, 5) // returns 21
|
||||
*
|
||||
* See also:
|
||||
*
|
||||
* combinationsWithRep, permutations, factorial
|
||||
*
|
||||
* @param {number | BigNumber} n Total number of objects in the set
|
||||
* @param {number | BigNumber} k Number of objects in the subset
|
||||
* @return {number | BigNumber} Number of possible combinations.
|
||||
*/
|
||||
return typed(name, {
|
||||
'number, number': _combinations.combinationsNumber,
|
||||
'BigNumber, BigNumber': function (n, k) {
|
||||
const BigNumber = n.constructor;
|
||||
let result, i;
|
||||
const nMinusk = n.minus(k);
|
||||
const one = new BigNumber(1);
|
||||
if (!isPositiveInteger(n) || !isPositiveInteger(k)) {
|
||||
throw new TypeError('Positive integer value expected in function combinations');
|
||||
}
|
||||
if (k.gt(n)) {
|
||||
throw new TypeError('k must be less than n in function combinations');
|
||||
}
|
||||
result = one;
|
||||
if (k.lt(nMinusk)) {
|
||||
for (i = one; i.lte(nMinusk); i = i.plus(one)) {
|
||||
result = result.times(k.plus(i)).dividedBy(i);
|
||||
}
|
||||
} else {
|
||||
for (i = one; i.lte(k); i = i.plus(one)) {
|
||||
result = result.times(nMinusk.plus(i)).dividedBy(i);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// TODO: implement support for collection in combinations
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Test whether BigNumber n is a positive integer
|
||||
* @param {BigNumber} n
|
||||
* @returns {boolean} isPositiveInteger
|
||||
*/
|
||||
function isPositiveInteger(n) {
|
||||
return n.isInteger() && n.gte(0);
|
||||
}
|
||||
90
node_modules/mathjs/lib/cjs/function/probability/combinationsWithRep.js
generated
vendored
Normal file
90
node_modules/mathjs/lib/cjs/function/probability/combinationsWithRep.js
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.createCombinationsWithRep = void 0;
|
||||
var _factory = require("../../utils/factory.js");
|
||||
var _number = require("../../utils/number.js");
|
||||
var _product = require("../../utils/product.js");
|
||||
const name = 'combinationsWithRep';
|
||||
const dependencies = ['typed'];
|
||||
const createCombinationsWithRep = exports.createCombinationsWithRep = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
|
||||
let {
|
||||
typed
|
||||
} = _ref;
|
||||
/**
|
||||
* Compute the number of ways of picking `k` unordered outcomes from `n`
|
||||
* possibilities, allowing individual outcomes to be repeated more than once.
|
||||
*
|
||||
* CombinationsWithRep only takes integer arguments.
|
||||
* The following condition must be enforced: k <= n + k -1.
|
||||
*
|
||||
* Syntax:
|
||||
*
|
||||
* math.combinationsWithRep(n, k)
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* math.combinationsWithRep(7, 5) // returns 462
|
||||
*
|
||||
* See also:
|
||||
*
|
||||
* combinations, permutations, factorial
|
||||
*
|
||||
* @param {number | BigNumber} n Total number of objects in the set
|
||||
* @param {number | BigNumber} k Number of objects in the subset
|
||||
* @return {number | BigNumber} Number of possible combinations with replacement.
|
||||
*/
|
||||
return typed(name, {
|
||||
'number, number': function (n, k) {
|
||||
if (!(0, _number.isInteger)(n) || n < 0) {
|
||||
throw new TypeError('Positive integer value expected in function combinationsWithRep');
|
||||
}
|
||||
if (!(0, _number.isInteger)(k) || k < 0) {
|
||||
throw new TypeError('Positive integer value expected in function combinationsWithRep');
|
||||
}
|
||||
if (n < 1) {
|
||||
throw new TypeError('k must be less than or equal to n + k - 1');
|
||||
}
|
||||
if (k < n - 1) {
|
||||
const prodrange = (0, _product.product)(n, n + k - 1);
|
||||
return prodrange / (0, _product.product)(1, k);
|
||||
}
|
||||
const prodrange = (0, _product.product)(k + 1, n + k - 1);
|
||||
return prodrange / (0, _product.product)(1, n - 1);
|
||||
},
|
||||
'BigNumber, BigNumber': function (n, k) {
|
||||
const BigNumber = n.constructor;
|
||||
let result, i;
|
||||
const one = new BigNumber(1);
|
||||
const nMinusOne = n.minus(one);
|
||||
if (!isPositiveInteger(n) || !isPositiveInteger(k)) {
|
||||
throw new TypeError('Positive integer value expected in function combinationsWithRep');
|
||||
}
|
||||
if (n.lt(one)) {
|
||||
throw new TypeError('k must be less than or equal to n + k - 1 in function combinationsWithRep');
|
||||
}
|
||||
result = one;
|
||||
if (k.lt(nMinusOne)) {
|
||||
for (i = one; i.lte(nMinusOne); i = i.plus(one)) {
|
||||
result = result.times(k.plus(i)).dividedBy(i);
|
||||
}
|
||||
} else {
|
||||
for (i = one; i.lte(k); i = i.plus(one)) {
|
||||
result = result.times(nMinusOne.plus(i)).dividedBy(i);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Test whether BigNumber n is a positive integer
|
||||
* @param {BigNumber} n
|
||||
* @returns {boolean} isPositiveInteger
|
||||
*/
|
||||
function isPositiveInteger(n) {
|
||||
return n.isInteger() && n.gte(0);
|
||||
}
|
||||
53
node_modules/mathjs/lib/cjs/function/probability/factorial.js
generated
vendored
Normal file
53
node_modules/mathjs/lib/cjs/function/probability/factorial.js
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.createFactorial = void 0;
|
||||
var _collection = require("../../utils/collection.js");
|
||||
var _factory = require("../../utils/factory.js");
|
||||
const name = 'factorial';
|
||||
const dependencies = ['typed', 'gamma'];
|
||||
const createFactorial = exports.createFactorial = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
|
||||
let {
|
||||
typed,
|
||||
gamma
|
||||
} = _ref;
|
||||
/**
|
||||
* Compute the factorial of a value
|
||||
*
|
||||
* Factorial only supports an integer value as argument.
|
||||
* For matrices, the function is evaluated element wise.
|
||||
*
|
||||
* Syntax:
|
||||
*
|
||||
* math.factorial(n)
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* math.factorial(5) // returns 120
|
||||
* math.factorial(3) // returns 6
|
||||
*
|
||||
* See also:
|
||||
*
|
||||
* combinations, combinationsWithRep, gamma, permutations
|
||||
*
|
||||
* @param {number | BigNumber | Array | Matrix} n An integer number
|
||||
* @return {number | BigNumber | Array | Matrix} The factorial of `n`
|
||||
*/
|
||||
return typed(name, {
|
||||
number: function (n) {
|
||||
if (n < 0) {
|
||||
throw new Error('Value must be non-negative');
|
||||
}
|
||||
return gamma(n + 1);
|
||||
},
|
||||
BigNumber: function (n) {
|
||||
if (n.isNegative()) {
|
||||
throw new Error('Value must be non-negative');
|
||||
}
|
||||
return gamma(n.plus(1));
|
||||
},
|
||||
'Array | Matrix': typed.referToSelf(self => n => (0, _collection.deepMap)(n, self))
|
||||
});
|
||||
});
|
||||
126
node_modules/mathjs/lib/cjs/function/probability/gamma.js
generated
vendored
Normal file
126
node_modules/mathjs/lib/cjs/function/probability/gamma.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
83
node_modules/mathjs/lib/cjs/function/probability/kldivergence.js
generated
vendored
Normal file
83
node_modules/mathjs/lib/cjs/function/probability/kldivergence.js
generated
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.createKldivergence = void 0;
|
||||
var _factory = require("../../utils/factory.js");
|
||||
const name = 'kldivergence';
|
||||
const dependencies = ['typed', 'matrix', 'divide', 'sum', 'multiply', 'map', 'dotDivide', 'log', 'isNumeric'];
|
||||
const createKldivergence = exports.createKldivergence = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
|
||||
let {
|
||||
typed,
|
||||
matrix,
|
||||
divide,
|
||||
sum,
|
||||
multiply,
|
||||
map,
|
||||
dotDivide,
|
||||
log,
|
||||
isNumeric
|
||||
} = _ref;
|
||||
/**
|
||||
* Calculate the Kullback-Leibler (KL) divergence between two distributions
|
||||
*
|
||||
* Syntax:
|
||||
*
|
||||
* math.kldivergence(x, y)
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* math.kldivergence([0.7,0.5,0.4], [0.2,0.9,0.5]) //returns 0.24376698773121153
|
||||
*
|
||||
*
|
||||
* @param {Array | Matrix} q First vector
|
||||
* @param {Array | Matrix} p Second vector
|
||||
* @return {number} Returns distance between q and p
|
||||
*/
|
||||
return typed(name, {
|
||||
'Array, Array': function (q, p) {
|
||||
return _kldiv(matrix(q), matrix(p));
|
||||
},
|
||||
'Matrix, Array': function (q, p) {
|
||||
return _kldiv(q, matrix(p));
|
||||
},
|
||||
'Array, Matrix': function (q, p) {
|
||||
return _kldiv(matrix(q), p);
|
||||
},
|
||||
'Matrix, Matrix': function (q, p) {
|
||||
return _kldiv(q, p);
|
||||
}
|
||||
});
|
||||
function _kldiv(q, p) {
|
||||
const plength = p.size().length;
|
||||
const qlength = q.size().length;
|
||||
if (plength > 1) {
|
||||
throw new Error('first object must be one dimensional');
|
||||
}
|
||||
if (qlength > 1) {
|
||||
throw new Error('second object must be one dimensional');
|
||||
}
|
||||
if (plength !== qlength) {
|
||||
throw new Error('Length of two vectors must be equal');
|
||||
}
|
||||
|
||||
// Before calculation, apply normalization
|
||||
const sumq = sum(q);
|
||||
if (sumq === 0) {
|
||||
throw new Error('Sum of elements in first object must be non zero');
|
||||
}
|
||||
const sump = sum(p);
|
||||
if (sump === 0) {
|
||||
throw new Error('Sum of elements in second object must be non zero');
|
||||
}
|
||||
const qnorm = divide(q, sum(q));
|
||||
const pnorm = divide(p, sum(p));
|
||||
const result = sum(multiply(qnorm, map(dotDivide(qnorm, pnorm), x => log(x))));
|
||||
if (isNumeric(result)) {
|
||||
return result;
|
||||
} else {
|
||||
return Number.NaN;
|
||||
}
|
||||
}
|
||||
});
|
||||
143
node_modules/mathjs/lib/cjs/function/probability/lgamma.js
generated
vendored
Normal file
143
node_modules/mathjs/lib/cjs/function/probability/lgamma.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
56
node_modules/mathjs/lib/cjs/function/probability/multinomial.js
generated
vendored
Normal file
56
node_modules/mathjs/lib/cjs/function/probability/multinomial.js
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.createMultinomial = void 0;
|
||||
var _collection = require("../../utils/collection.js");
|
||||
var _factory = require("../../utils/factory.js");
|
||||
const name = 'multinomial';
|
||||
const dependencies = ['typed', 'add', 'divide', 'multiply', 'factorial', 'isInteger', 'isPositive'];
|
||||
const createMultinomial = exports.createMultinomial = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
|
||||
let {
|
||||
typed,
|
||||
add,
|
||||
divide,
|
||||
multiply,
|
||||
factorial,
|
||||
isInteger,
|
||||
isPositive
|
||||
} = _ref;
|
||||
/**
|
||||
* Multinomial Coefficients compute the number of ways of picking a1, a2, ..., ai unordered outcomes from `n` possibilities.
|
||||
*
|
||||
* multinomial takes one array of integers as an argument.
|
||||
* The following condition must be enforced: every ai <= 0
|
||||
*
|
||||
* Syntax:
|
||||
*
|
||||
* math.multinomial(a) // a is an array type
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* math.multinomial([1,2,1]) // returns 12
|
||||
*
|
||||
* See also:
|
||||
*
|
||||
* combinations, factorial
|
||||
*
|
||||
* @param {number[] | BigNumber[]} a Integer numbers of objects in the subset
|
||||
* @return {Number | BigNumber} Multinomial coefficient.
|
||||
*/
|
||||
return typed(name, {
|
||||
'Array | Matrix': function (a) {
|
||||
let sum = 0;
|
||||
let denom = 1;
|
||||
(0, _collection.deepForEach)(a, function (ai) {
|
||||
if (!isInteger(ai) || !isPositive(ai)) {
|
||||
throw new TypeError('Positive integer value expected in function multinomial');
|
||||
}
|
||||
sum = add(sum, ai);
|
||||
denom = multiply(denom, factorial(ai));
|
||||
});
|
||||
return divide(factorial(sum), denom);
|
||||
}
|
||||
});
|
||||
});
|
||||
84
node_modules/mathjs/lib/cjs/function/probability/permutations.js
generated
vendored
Normal file
84
node_modules/mathjs/lib/cjs/function/probability/permutations.js
generated
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.createPermutations = void 0;
|
||||
var _number = require("../../utils/number.js");
|
||||
var _product = require("../../utils/product.js");
|
||||
var _factory = require("../../utils/factory.js");
|
||||
const name = 'permutations';
|
||||
const dependencies = ['typed', 'factorial'];
|
||||
const createPermutations = exports.createPermutations = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
|
||||
let {
|
||||
typed,
|
||||
factorial
|
||||
} = _ref;
|
||||
/**
|
||||
* Compute the number of ways of obtaining an ordered subset of `k` elements
|
||||
* from a set of `n` elements.
|
||||
*
|
||||
* Permutations only takes integer arguments.
|
||||
* The following condition must be enforced: k <= n.
|
||||
*
|
||||
* Syntax:
|
||||
*
|
||||
* math.permutations(n)
|
||||
* math.permutations(n, k)
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* math.permutations(5) // 120
|
||||
* math.permutations(5, 3) // 60
|
||||
*
|
||||
* See also:
|
||||
*
|
||||
* combinations, combinationsWithRep, factorial
|
||||
*
|
||||
* @param {number | BigNumber} n The number of objects in total
|
||||
* @param {number | BigNumber} [k] The number of objects in the subset
|
||||
* @return {number | BigNumber} The number of permutations
|
||||
*/
|
||||
return typed(name, {
|
||||
'number | BigNumber': factorial,
|
||||
'number, number': function (n, k) {
|
||||
if (!(0, _number.isInteger)(n) || n < 0) {
|
||||
throw new TypeError('Positive integer value expected in function permutations');
|
||||
}
|
||||
if (!(0, _number.isInteger)(k) || k < 0) {
|
||||
throw new TypeError('Positive integer value expected in function permutations');
|
||||
}
|
||||
if (k > n) {
|
||||
throw new TypeError('second argument k must be less than or equal to first argument n');
|
||||
}
|
||||
// Permute n objects, k at a time
|
||||
return (0, _product.product)(n - k + 1, n);
|
||||
},
|
||||
'BigNumber, BigNumber': function (n, k) {
|
||||
let result, i;
|
||||
if (!isPositiveInteger(n) || !isPositiveInteger(k)) {
|
||||
throw new TypeError('Positive integer value expected in function permutations');
|
||||
}
|
||||
if (k.gt(n)) {
|
||||
throw new TypeError('second argument k must be less than or equal to first argument n');
|
||||
}
|
||||
const one = n.mul(0).add(1);
|
||||
result = one;
|
||||
for (i = n.minus(k).plus(1); i.lte(n); i = i.plus(1)) {
|
||||
result = result.times(i);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// TODO: implement support for collection in permutations
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Test whether BigNumber n is a positive integer
|
||||
* @param {BigNumber} n
|
||||
* @returns {boolean} isPositiveInteger
|
||||
*/
|
||||
function isPositiveInteger(n) {
|
||||
return n.isInteger() && n.gte(0);
|
||||
}
|
||||
156
node_modules/mathjs/lib/cjs/function/probability/pickRandom.js
generated
vendored
Normal file
156
node_modules/mathjs/lib/cjs/function/probability/pickRandom.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
102
node_modules/mathjs/lib/cjs/function/probability/random.js
generated
vendored
Normal file
102
node_modules/mathjs/lib/cjs/function/probability/random.js
generated
vendored
Normal file
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
Reference in New Issue
Block a user