@danielsimonjr/mathts-functions 0.4.0 → 0.6.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.
- package/dist/calculus-extra.d.ts +25 -0
- package/dist/calculus-extra.d.ts.map +1 -0
- package/dist/descriptive-stats.d.ts +51 -0
- package/dist/descriptive-stats.d.ts.map +1 -0
- package/dist/distribution-functions.d.ts +30 -0
- package/dist/distribution-functions.d.ts.map +1 -0
- package/dist/factories/evaluate.d.ts.map +1 -1
- package/dist/factories/index.d.ts +2 -1
- package/dist/factories/index.d.ts.map +1 -1
- package/dist/geometry-extra.d.ts +30 -0
- package/dist/geometry-extra.d.ts.map +1 -0
- package/dist/hypothesis-extra.d.ts +58 -0
- package/dist/hypothesis-extra.d.ts.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1767 -1039
- package/dist/linalg-extra.d.ts +58 -0
- package/dist/linalg-extra.d.ts.map +1 -0
- package/dist/matrix/native-accel.d.ts +17 -0
- package/dist/matrix/native-accel.d.ts.map +1 -1
- package/dist/numeric-extra.d.ts +28 -0
- package/dist/numeric-extra.d.ts.map +1 -0
- package/dist/regression-extra.d.ts +18 -0
- package/dist/regression-extra.d.ts.map +1 -0
- package/dist/timeseries-extra.d.ts +24 -0
- package/dist/timeseries-extra.d.ts.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
type Vec = readonly number[] | Float64Array;
|
|
2
|
+
/**
|
|
3
|
+
* Generalized eigenvalues of the pencil `A x = λ B x` (B nonsingular), via the
|
|
4
|
+
* eigendecomposition of `B⁻¹A` — reusing `inv`, `multiply`, and the corrected
|
|
5
|
+
* `eigs`. Eigenvalues match `scipy.linalg.eig(A, B)`. For ill-conditioned `B`
|
|
6
|
+
* prefer a QZ solver (not yet available).
|
|
7
|
+
*/
|
|
8
|
+
export declare function generalizedEig(A: readonly number[][], B: readonly number[][]): {
|
|
9
|
+
values: Array<number | {
|
|
10
|
+
re: number;
|
|
11
|
+
im: number;
|
|
12
|
+
}>;
|
|
13
|
+
eigenvectors?: unknown;
|
|
14
|
+
};
|
|
15
|
+
/** Lower-triangular part of `A`, zeroing entries above the `k`-th diagonal. */
|
|
16
|
+
export declare function tril(A: readonly number[][], k?: number): number[][];
|
|
17
|
+
/** Upper-triangular part of `A`, zeroing entries below the `k`-th diagonal. */
|
|
18
|
+
export declare function triu(A: readonly number[][], k?: number): number[][];
|
|
19
|
+
/**
|
|
20
|
+
* Vandermonde matrix of `x`: column `j` is `xᵢ` to a power. With `increasing`
|
|
21
|
+
* false (default, NumPy convention) column `j` is `xᵢ^(N-1-j)`; `N` defaults to
|
|
22
|
+
* `x.length`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function vander(x: Vec, n?: number, increasing?: boolean): number[][];
|
|
25
|
+
/**
|
|
26
|
+
* Toeplitz matrix: first column `c`, first row `r` (defaults to `c`). Constant
|
|
27
|
+
* along each diagonal. `T[i][j] = c[i-j]` for `i ≥ j`, else `r[j-i]`.
|
|
28
|
+
*/
|
|
29
|
+
export declare function toeplitz(c: Vec, r?: Vec): number[][];
|
|
30
|
+
/** Circulant matrix: each row is the previous one rotated right by one. */
|
|
31
|
+
export declare function circulant(c: Vec): number[][];
|
|
32
|
+
/**
|
|
33
|
+
* Companion matrix of a monic-normalized polynomial given by coefficients
|
|
34
|
+
* `[a₀, a₁, …, a_n]` (highest degree first, NumPy `np.companion` convention).
|
|
35
|
+
* Its eigenvalues are the polynomial's roots.
|
|
36
|
+
*/
|
|
37
|
+
export declare function companion(coeffs: Vec): number[][];
|
|
38
|
+
/**
|
|
39
|
+
* Graph Laplacian of an adjacency matrix (bridge graph ↔ linear algebra — spectral
|
|
40
|
+
* graph theory). Combinatorial `L = D − A` by default (D = diagonal degree matrix);
|
|
41
|
+
* with `{ normalized: true }`, the symmetric normalized Laplacian
|
|
42
|
+
* `L_sym = I − D^(−1/2) A D^(−1/2)`. Eigen-analysis of `L` (via `eigs`) gives the
|
|
43
|
+
* Fiedler vector / spectral clustering.
|
|
44
|
+
*/
|
|
45
|
+
export declare function laplacianMatrix(adjacency: readonly number[][], opts?: {
|
|
46
|
+
normalized?: boolean;
|
|
47
|
+
}): number[][];
|
|
48
|
+
/**
|
|
49
|
+
* Natural log of the absolute determinant via LU (the `logabsdet` component of
|
|
50
|
+
* `numpy.linalg.slogdet`), stable where `log(det(A))` would overflow. Returns
|
|
51
|
+
* `{ sign, value }` with `det = sign · exp(value)`.
|
|
52
|
+
*/
|
|
53
|
+
export declare function logdet(A: readonly number[][]): {
|
|
54
|
+
sign: number;
|
|
55
|
+
value: number;
|
|
56
|
+
};
|
|
57
|
+
export {};
|
|
58
|
+
//# sourceMappingURL=linalg-extra.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"linalg-extra.d.ts","sourceRoot":"","sources":["../src/linalg-extra.ts"],"names":[],"mappings":"AAoBA,KAAK,GAAG,GAAG,SAAS,MAAM,EAAE,GAAG,YAAY,CAAC;AAG5C;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,CAAC,EAAE,SAAS,MAAM,EAAE,EAAE,EACtB,CAAC,EAAE,SAAS,MAAM,EAAE,EAAE,GACrB;IAAE,MAAM,EAAE,KAAK,CAAC,MAAM,GAAG;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAAC,YAAY,CAAC,EAAE,OAAO,CAAA;CAAE,CAIhF;AAED,+EAA+E;AAC/E,wBAAgB,IAAI,CAAC,CAAC,EAAE,SAAS,MAAM,EAAE,EAAE,EAAE,CAAC,SAAI,GAAG,MAAM,EAAE,EAAE,CAE9D;AAED,+EAA+E;AAC/E,wBAAgB,IAAI,CAAC,CAAC,EAAE,SAAS,MAAM,EAAE,EAAE,EAAE,CAAC,SAAI,GAAG,MAAM,EAAE,EAAE,CAE9D;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,UAAQ,GAAG,MAAM,EAAE,EAAE,CAMzE;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,GAAG,MAAM,EAAE,EAAE,CAQpD;AAED,2EAA2E;AAC3E,wBAAgB,SAAS,CAAC,CAAC,EAAE,GAAG,GAAG,MAAM,EAAE,EAAE,CAM5C;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,GAAG,GAAG,MAAM,EAAE,EAAE,CAQjD;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,SAAS,EAAE,SAAS,MAAM,EAAE,EAAE,EAC9B,IAAI,GAAE;IAAE,UAAU,CAAC,EAAE,OAAO,CAAA;CAAO,GAClC,MAAM,EAAE,EAAE,CAYZ;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,SAAS,MAAM,EAAE,EAAE,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CA2B9E"}
|
|
@@ -18,4 +18,21 @@ export declare function acceleratedDet<T>(a: unknown, factoryDet: (m: unknown) =
|
|
|
18
18
|
* Verified against numpy: max|inv−numpy| and max|A·inv−I| ~1e-15.
|
|
19
19
|
*/
|
|
20
20
|
export declare function acceleratedInv<T>(a: unknown, factoryInv: (m: unknown) => T): T;
|
|
21
|
+
/** True for a square `number[][]` of any size ≥ 1. */
|
|
22
|
+
export declare function isNumericSquare(a: unknown): a is number[][];
|
|
23
|
+
/**
|
|
24
|
+
* Correct eigendecomposition for the public `eigs`.
|
|
25
|
+
*
|
|
26
|
+
* The activated mathjs factory `eigs` returns WRONG eigenvalues for *every*
|
|
27
|
+
* non-symmetric matrix — even trivial upper-triangular ones, whose eigenvalues
|
|
28
|
+
* are just the diagonal (e.g. [[2,1,0],[0,3,1],[0,0,4]] → [1.27, 3, 4.73]). The
|
|
29
|
+
* native `@danielsimonjr/mathts-matrix` `eig` (JAMA orthes/hqr2) is correct for
|
|
30
|
+
* symmetric, non-symmetric, and complex spectra (verified vs numpy), so route all
|
|
31
|
+
* numeric square matrices through it and emit the factory's `{ values,
|
|
32
|
+
* eigenvectors }` shape. Non-(numeric square) inputs and any native error fall
|
|
33
|
+
* back to the factory.
|
|
34
|
+
*/
|
|
35
|
+
export declare function correctEigs(a: unknown, options: {
|
|
36
|
+
eigenvectors?: boolean;
|
|
37
|
+
} | undefined, factoryEigs: (m: unknown, o?: unknown) => unknown): unknown;
|
|
21
38
|
//# sourceMappingURL=native-accel.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native-accel.d.ts","sourceRoot":"","sources":["../../src/matrix/native-accel.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"native-accel.d.ts","sourceRoot":"","sources":["../../src/matrix/native-accel.ts"],"names":[],"mappings":"AAqBA;gFACgF;AAChF,eAAO,MAAM,uBAAuB,IAAI,CAAC;AAEzC,wEAAwE;AACxE,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,MAAM,EAAE,EAAE,CAQhE;AAsBD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,CAAC,GAAG,CAAC,CAY9E;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,CAAC,GAAG,CAAC,CAoC9E;AAID,sDAAsD;AACtD,wBAAgB,eAAe,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,MAAM,EAAE,EAAE,CAQ3D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CACzB,CAAC,EAAE,OAAO,EACV,OAAO,EAAE;IAAE,YAAY,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,SAAS,EAC/C,WAAW,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,OAAO,GAChD,OAAO,CAqBT"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
type Vec = readonly number[] | Float64Array;
|
|
2
|
+
/** Clamp a number — or each element of an array — to `[lo, hi]`. */
|
|
3
|
+
export declare function clamp(x: number, lo: number, hi: number): number;
|
|
4
|
+
export declare function clamp(x: readonly number[], lo: number, hi: number): number[];
|
|
5
|
+
/** Logistic sigmoid `1/(1+e^-x)`, computed in the numerically stable branch. */
|
|
6
|
+
export declare function sigmoid(x: number): number;
|
|
7
|
+
export declare function sigmoid(x: readonly number[]): number[];
|
|
8
|
+
/**
|
|
9
|
+
* Log-sum-exp: `log(Σ exp(xᵢ))`, shifted by the max for numerical stability.
|
|
10
|
+
* Reuses `max`/`sum`. The backbone of log-probability arithmetic.
|
|
11
|
+
*/
|
|
12
|
+
export declare function logsumexp(x: Vec): number;
|
|
13
|
+
/** Softmax: `exp(xᵢ − max) / Σ exp(x − max)`. Returns a probability vector. */
|
|
14
|
+
export declare function softmax(x: Vec): number[];
|
|
15
|
+
/** Cumulative product (running ∏). Output has the same length as the input. */
|
|
16
|
+
export declare function cumprod(x: Vec): number[];
|
|
17
|
+
/** Cumulative maximum (running max). */
|
|
18
|
+
export declare function cummax(x: Vec): number[];
|
|
19
|
+
/** Cumulative minimum (running min). */
|
|
20
|
+
export declare function cummin(x: Vec): number[];
|
|
21
|
+
/**
|
|
22
|
+
* Cumulative trapezoidal integral of samples `y` (optionally over abscissae
|
|
23
|
+
* `x`, else unit spacing or a scalar `dx`). Output has the same length as `y`
|
|
24
|
+
* with a leading 0 (the MATLAB `cumtrapz` convention).
|
|
25
|
+
*/
|
|
26
|
+
export declare function cumtrapz(y: Vec, x?: Vec | number): number[];
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=numeric-extra.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"numeric-extra.d.ts","sourceRoot":"","sources":["../src/numeric-extra.ts"],"names":[],"mappings":"AAUA,KAAK,GAAG,GAAG,SAAS,MAAM,EAAE,GAAG,YAAY,CAAC;AAG5C,oEAAoE;AACpE,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;AACjE,wBAAgB,KAAK,CAAC,CAAC,EAAE,SAAS,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;AAM9E,gFAAgF;AAChF,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;AAC3C,wBAAgB,OAAO,CAAC,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC;AAMxD;;;GAGG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,GAAG,GAAG,MAAM,CAQxC;AAED,+EAA+E;AAC/E,wBAAgB,OAAO,CAAC,CAAC,EAAE,GAAG,GAAG,MAAM,EAAE,CAOxC;AAED,+EAA+E;AAC/E,wBAAgB,OAAO,CAAC,CAAC,EAAE,GAAG,GAAG,MAAM,EAAE,CASxC;AAED,wCAAwC;AACxC,wBAAgB,MAAM,CAAC,CAAC,EAAE,GAAG,GAAG,MAAM,EAAE,CASvC;AAED,wCAAwC;AACxC,wBAAgB,MAAM,CAAC,CAAC,EAAE,GAAG,GAAG,MAAM,EAAE,CASvC;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,GAAG,MAAM,GAAG,MAAM,EAAE,CAe3D"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
type Vec = readonly number[] | Float64Array;
|
|
2
|
+
export interface LinregressResult {
|
|
3
|
+
slope: number;
|
|
4
|
+
intercept: number;
|
|
5
|
+
rValue: number;
|
|
6
|
+
rSquared: number;
|
|
7
|
+
pValue: number;
|
|
8
|
+
stdErr: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Simple linear regression `y ≈ slope·x + intercept` by ordinary least squares.
|
|
12
|
+
* `rValue` is Pearson's r; `pValue` is the two-sided test of slope = 0 (t with
|
|
13
|
+
* n−2 df); `stdErr` is the standard error of the slope. Mirrors
|
|
14
|
+
* `scipy.stats.linregress`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function linearRegression(x: Vec, y: Vec): LinregressResult;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=regression-extra.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"regression-extra.d.ts","sourceRoot":"","sources":["../src/regression-extra.ts"],"names":[],"mappings":"AAQA,KAAK,GAAG,GAAG,SAAS,MAAM,EAAE,GAAG,YAAY,CAAC;AAI5C,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,GAAG,gBAAgB,CA0BjE"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
type Vec = readonly number[] | Float64Array;
|
|
2
|
+
/**
|
|
3
|
+
* Simple moving average over a trailing window of size `w`. Returns an array of
|
|
4
|
+
* length `n − w + 1` (the "valid" convolution, like `numpy.convolve(..., 'valid')`).
|
|
5
|
+
*/
|
|
6
|
+
export declare function movingAverage(x: Vec, w: number): number[];
|
|
7
|
+
/**
|
|
8
|
+
* Exponentially-weighted moving average with smoothing factor `alpha ∈ (0,1]`
|
|
9
|
+
* (`yₜ = α·xₜ + (1−α)·yₜ₋₁`, seeded with `x₀`). Matches `pandas.ewm(alpha=…,
|
|
10
|
+
* adjust=False).mean()`. Output has the same length as the input.
|
|
11
|
+
*/
|
|
12
|
+
export declare function ewma(x: Vec, alpha: number): number[];
|
|
13
|
+
/**
|
|
14
|
+
* Remove a trend from `x`. `'linear'` (default) subtracts the least-squares line;
|
|
15
|
+
* `'constant'` subtracts the mean. Matches `scipy.signal.detrend`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function detrend(x: Vec, type?: 'linear' | 'constant'): number[];
|
|
18
|
+
/**
|
|
19
|
+
* Autocorrelation function up to `nlags` (inclusive), biased estimator
|
|
20
|
+
* (÷n, like `statsmodels.tsa.stattools.acf`). `acf[0] = 1`.
|
|
21
|
+
*/
|
|
22
|
+
export declare function acf(x: Vec, nlags: number): number[];
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=timeseries-extra.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeseries-extra.d.ts","sourceRoot":"","sources":["../src/timeseries-extra.ts"],"names":[],"mappings":"AAQA,KAAK,GAAG,GAAG,SAAS,MAAM,EAAE,GAAG,YAAY,CAAC;AAI5C;;;GAGG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAWzD;AAED;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAWpD;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,IAAI,GAAE,QAAQ,GAAG,UAAqB,GAAG,MAAM,EAAE,CAoBhF;AAED;;;GAGG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAcnD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@danielsimonjr/mathts-functions",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Mathematical functions for MathTS - arithmetic, algebra, trigonometry, statistics, and more",
|
|
5
5
|
"author": "Daniel Simon Jr.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
"build:prod": "tsup src/index.ts --format esm --clean --minify --treeshake"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@danielsimonjr/mathts-core": "^0.
|
|
37
|
-
"@danielsimonjr/mathts-expression": "^0.4.
|
|
38
|
-
"@danielsimonjr/mathts-matrix": "^0.1.
|
|
36
|
+
"@danielsimonjr/mathts-core": "^0.3.0",
|
|
37
|
+
"@danielsimonjr/mathts-expression": "^0.4.2",
|
|
38
|
+
"@danielsimonjr/mathts-matrix": "^0.1.12",
|
|
39
39
|
"@danielsimonjr/mathts-parallel": "^0.3.0",
|
|
40
40
|
"bignumber.js": "^9.1.2",
|
|
41
41
|
"complex.js": "^2.2.5",
|