mathjs 11.10.0 → 11.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/HISTORY.md +20 -0
  2. package/lib/browser/math.js +1 -1
  3. package/lib/browser/math.js.LICENSE.txt +4 -4
  4. package/lib/browser/math.js.map +1 -1
  5. package/lib/cjs/entry/dependenciesAny/dependenciesCorr.generated.js +36 -0
  6. package/lib/cjs/entry/dependenciesAny.generated.js +7 -0
  7. package/lib/cjs/entry/dependenciesNumber/dependenciesCorr.generated.js +36 -0
  8. package/lib/cjs/entry/dependenciesNumber.generated.js +7 -0
  9. package/lib/cjs/entry/impureFunctionsAny.generated.js +25 -24
  10. package/lib/cjs/entry/impureFunctionsNumber.generated.js +4 -3
  11. package/lib/cjs/entry/pureFunctionsAny.generated.js +46 -33
  12. package/lib/cjs/entry/pureFunctionsNumber.generated.js +26 -13
  13. package/lib/cjs/expression/embeddedDocs/embeddedDocs.js +2 -0
  14. package/lib/cjs/expression/embeddedDocs/function/statistics/corr.js +15 -0
  15. package/lib/cjs/factoriesAny.js +7 -0
  16. package/lib/cjs/factoriesNumber.js +10 -4
  17. package/lib/cjs/function/special/erf.js +3 -0
  18. package/lib/cjs/function/special/zeta.js +2 -0
  19. package/lib/cjs/function/statistics/corr.js +85 -0
  20. package/lib/cjs/header.js +2 -2
  21. package/lib/cjs/type/unit/Unit.js +3 -2
  22. package/lib/cjs/utils/lruQueue.js +2 -2
  23. package/lib/cjs/version.js +1 -1
  24. package/lib/esm/entry/dependenciesAny/dependenciesCorr.generated.js +28 -0
  25. package/lib/esm/entry/dependenciesAny.generated.js +1 -0
  26. package/lib/esm/entry/dependenciesNumber/dependenciesCorr.generated.js +28 -0
  27. package/lib/esm/entry/dependenciesNumber.generated.js +1 -0
  28. package/lib/esm/entry/impureFunctionsAny.generated.js +26 -25
  29. package/lib/esm/entry/impureFunctionsNumber.generated.js +5 -4
  30. package/lib/esm/entry/pureFunctionsAny.generated.js +35 -23
  31. package/lib/esm/entry/pureFunctionsNumber.generated.js +21 -9
  32. package/lib/esm/expression/embeddedDocs/embeddedDocs.js +2 -0
  33. package/lib/esm/expression/embeddedDocs/function/statistics/corr.js +8 -0
  34. package/lib/esm/factoriesAny.js +1 -0
  35. package/lib/esm/factoriesNumber.js +1 -0
  36. package/lib/esm/function/special/erf.js +3 -0
  37. package/lib/esm/function/special/zeta.js +2 -0
  38. package/lib/esm/function/statistics/corr.js +74 -0
  39. package/lib/esm/type/unit/Unit.js +3 -2
  40. package/lib/esm/utils/lruQueue.js +2 -2
  41. package/lib/esm/version.js +1 -1
  42. package/package.json +2 -2
  43. package/types/index.d.ts +8 -0
@@ -30,6 +30,9 @@ export var createErf = /* #__PURE__ */factory(name, dependencies, _ref => {
30
30
  * math.erf(-0.5) // returns -0.5204998778130465
31
31
  * math.erf(4) // returns 0.9999999845827421
32
32
  *
33
+ * See also:
34
+ * zeta
35
+ *
33
36
  * @param {number | Array | Matrix} x A real number
34
37
  * @return {number | Array | Matrix} The erf of `x`
35
38
  */
@@ -41,6 +41,8 @@ export var createZeta = /* #__PURE__ */factory(name, dependencies, _ref => {
41
41
  * math.zeta(-0.5) // returns -0.2078862249773449
42
42
  * math.zeta(math.i) // returns 0.0033002236853253153 - 0.4181554491413212i
43
43
  *
44
+ * See also:
45
+ * erf
44
46
  *
45
47
  * @param {number | Complex | BigNumber} s A Real, Complex or BigNumber parameter to the Riemann Zeta Function
46
48
  * @return {number | Complex | BigNumber} The Riemann Zeta of `s`
@@ -0,0 +1,74 @@
1
+ import { factory } from '../../utils/factory.js';
2
+ var name = 'corr';
3
+ var dependencies = ['typed', 'matrix', 'mean', 'sqrt', 'sum', 'add', 'subtract', 'multiply', 'pow', 'divide'];
4
+ export var createCorr = /* #__PURE__ */factory(name, dependencies, _ref => {
5
+ var {
6
+ typed,
7
+ matrix,
8
+ sqrt,
9
+ sum,
10
+ add,
11
+ subtract,
12
+ multiply,
13
+ pow,
14
+ divide
15
+ } = _ref;
16
+ /**
17
+ * Compute the correlation coefficient of a two list with values, For matrices, the matrix correlation coefficient is calculated.
18
+ *
19
+ * Syntax:
20
+ *
21
+ * math.corr(A, B)
22
+ *
23
+ * Examples:
24
+ *
25
+ * math.corr([1, 2, 3, 4, 5], [4, 5, 6, 7, 8]) // returns 1
26
+ * math.corr([1, 2.2, 3, 4.8, 5], [4, 5.3, 6.6, 7, 8]) // returns 0.9569941688503644
27
+ * math.corr(math.matrix([[1, 2.2, 3, 4.8, 5], [1, 2, 3, 4, 5]]), math.matrix([[4, 5.3, 6.6, 7, 8], [1, 2, 3, 4, 5]])) // returns DenseMatrix [0.9569941688503644, 1]
28
+ *
29
+ * See also:
30
+ *
31
+ * median, mean, min, max, sum, prod, std, variance
32
+ *
33
+ * @param {Array | Matrix} A The first array or matrix to compute correlation coefficient
34
+ * @param {Array | Matrix} B The second array or matrix to compute correlation coefficient
35
+ * @return {*} The correlation coefficient
36
+ */
37
+ return typed(name, {
38
+ 'Array, Array': function ArrayArray(A, B) {
39
+ return _corr(A, B);
40
+ },
41
+ 'Matrix, Matrix': function MatrixMatrix(xMatrix, yMatrix) {
42
+ return matrix(_corr(xMatrix.toArray(), yMatrix.toArray()));
43
+ }
44
+ });
45
+ /**
46
+ * Calculate the correlation coefficient between two arrays or matrices.
47
+ * @param {Array | Matrix} A
48
+ * @param {Array | Matrix} B
49
+ * @return {*} correlation coefficient
50
+ * @private
51
+ */
52
+ function _corr(A, B) {
53
+ if (Array.isArray(A[0]) && Array.isArray(B[0])) {
54
+ var correlations = [];
55
+ for (var i = 0; i < A.length; i++) {
56
+ correlations.push(correlation(A[i], B[i]));
57
+ }
58
+ return correlations;
59
+ } else {
60
+ return correlation(A, B);
61
+ }
62
+ }
63
+ function correlation(A, B) {
64
+ var n = A.length;
65
+ var sumX = sum(A);
66
+ var sumY = sum(B);
67
+ var sumXY = A.reduce((acc, x, index) => add(acc, multiply(x, B[index])), 0);
68
+ var sumXSquare = sum(A.map(x => pow(x, 2)));
69
+ var sumYSquare = sum(B.map(y => pow(y, 2)));
70
+ var numerator = subtract(multiply(n, sumXY), multiply(sumX, sumY));
71
+ var denominator = sqrt(multiply(subtract(multiply(n, sumXSquare), pow(sumX, 2)), subtract(multiply(n, sumYSquare), pow(sumY, 2))));
72
+ return divide(numerator, denominator);
73
+ }
74
+ });
@@ -2894,14 +2894,15 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
2894
2894
  joule: {
2895
2895
  name: 'joule',
2896
2896
  base: BASE_UNITS.ENERGY,
2897
- prefixes: PREFIXES.SHORT,
2897
+ prefixes: PREFIXES.LONG,
2898
2898
  value: 1,
2899
2899
  offset: 0
2900
2900
  },
2901
2901
  erg: {
2902
2902
  name: 'erg',
2903
2903
  base: BASE_UNITS.ENERGY,
2904
- prefixes: PREFIXES.NONE,
2904
+ prefixes: PREFIXES.SHORTLONG,
2905
+ // Both kiloerg and kerg are acceptable
2905
2906
  value: 1e-7,
2906
2907
  offset: 0
2907
2908
  },
@@ -19,7 +19,7 @@ export function lruQueue(limit) {
19
19
  base = 1;
20
20
  return;
21
21
  }
22
- while (!hasOwnProperty.call(queue, ++base)) continue;
22
+ while (!Object.prototype.hasOwnProperty.call(queue, ++base)) {/* empty */}
23
23
  };
24
24
  limit = Math.abs(limit);
25
25
  return {
@@ -37,7 +37,7 @@ export function lruQueue(limit) {
37
37
  }
38
38
  delete queue[oldIndex];
39
39
  if (base !== oldIndex) return undefined;
40
- while (!hasOwnProperty.call(queue, ++base)) continue;
40
+ while (!Object.prototype.hasOwnProperty.call(queue, ++base)) {/* empty */}
41
41
  return undefined;
42
42
  },
43
43
  delete: del,
@@ -1,3 +1,3 @@
1
- export var version = '11.10.0';
1
+ export var version = '11.11.0';
2
2
  // Note: This file is automatically generated when building math.js.
3
3
  // Changes made in this file will be overwritten.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mathjs",
3
- "version": "11.10.0",
3
+ "version": "11.11.0",
4
4
  "description": "Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser with support for symbolic computation, comes with a large set of built-in functions and constants, and offers an integrated solution to work with different data types like numbers, big numbers, complex numbers, fractions, units, and matrices.",
5
5
  "author": "Jos de Jong <wjosdejong@gmail.com> (https://github.com/josdejong)",
6
6
  "homepage": "https://mathjs.org",
@@ -29,7 +29,7 @@
29
29
  "complex.js": "^2.1.1",
30
30
  "decimal.js": "^10.4.3",
31
31
  "escape-latex": "^1.2.0",
32
- "fraction.js": "^4.2.0",
32
+ "fraction.js": "4.3.4",
33
33
  "javascript-natural-sort": "^0.7.1",
34
34
  "seedrandom": "^3.0.5",
35
35
  "tiny-emitter": "^2.1.0",
package/types/index.d.ts CHANGED
@@ -2970,6 +2970,14 @@ declare namespace math {
2970
2970
  normalization: 'unbiased' | 'uncorrected' | 'biased'
2971
2971
  ): MathNumericType
2972
2972
 
2973
+ /**
2974
+ * Calculate the correlation coefficient between two matrix.
2975
+ * @param {Array | Matrix} x The first array or matrix to compute correlation coefficient
2976
+ * @param {Array | Matrix} y The second array or matrix to compute correlation coefficient
2977
+ * @returns correlation coefficient
2978
+ */
2979
+ corr(x: MathCollection, y: MathCollection): MathType
2980
+
2973
2981
  /*************************************************************************
2974
2982
  * String functions
2975
2983
  ************************************************************************/