@danielsimonjr/mathts-functions 0.31.0 → 0.33.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/descriptive-stats.d.ts +16 -0
- package/dist/descriptive-stats.d.ts.map +1 -1
- package/dist/index.d.ts +14 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1383 -485
- package/dist/numbertheory/extra.d.ts +142 -0
- package/dist/numbertheory/extra.d.ts.map +1 -0
- package/dist/numeric/gauss-nodes.d.ts +35 -0
- package/dist/numeric/gauss-nodes.d.ts.map +1 -0
- package/dist/special/hypergeometric.d.ts +91 -0
- package/dist/special/hypergeometric.d.ts.map +1 -0
- package/dist/special/jacobi-elliptic.d.ts +60 -0
- package/dist/special/jacobi-elliptic.d.ts.map +1 -0
- package/dist/special/polygamma-orthopoly.d.ts +79 -0
- package/dist/special/polygamma-orthopoly.d.ts.map +1 -0
- package/dist/stats/fit-distribution.d.ts +44 -0
- package/dist/stats/fit-distribution.d.ts.map +1 -0
- package/dist/stats/inference-extra2.d.ts +127 -0
- package/dist/stats/inference-extra2.d.ts.map +1 -0
- package/dist/stats/timeseries.d.ts +50 -0
- package/dist/stats/timeseries.d.ts.map +1 -0
- package/dist/typed/hypothesis.d.ts +24 -6
- package/dist/typed/hypothesis.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Number-theory fills — closes gaps left by the existing combinatorics/number-theory
|
|
3
|
+
* surface (`typed/combinatorics.ts`): continued fractions, Euler numbers, the signed
|
|
4
|
+
* Stirling numbers of the first kind, discrete logarithm (BSGS), primitive roots,
|
|
5
|
+
* multiplicative order, the Kronecker symbol, and lexicographic
|
|
6
|
+
* permutation/combination *enumerators* (the existing `permutations`/`combinations`
|
|
7
|
+
* only return counts, not the tuples themselves).
|
|
8
|
+
*
|
|
9
|
+
* Plain exported functions (not `mathTyped` dispatch) — all take/return `number`
|
|
10
|
+
* or generic arrays, matching the style of `descriptive-stats.ts`.
|
|
11
|
+
*
|
|
12
|
+
* @packageDocumentation
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Simple continued fraction expansion `[a0, a1, a2, ...]` of `x`, where
|
|
16
|
+
* `a_i = floor(r)` and `r <- 1 / (r - a_i)`.
|
|
17
|
+
*
|
|
18
|
+
* Stops after `maxTerms` (default 20) or once the fractional part is smaller
|
|
19
|
+
* than `1e-12` (the remaining value is effectively an integer).
|
|
20
|
+
*
|
|
21
|
+
* @param x - The number to expand
|
|
22
|
+
* @param maxTerms - Maximum number of terms to compute (default 20)
|
|
23
|
+
* @returns The sequence of partial-quotient terms
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* continuedFraction(3.245, 5) // => [3, 4, 12, 4, ...]
|
|
27
|
+
*/
|
|
28
|
+
export declare function continuedFraction(x: number, maxTerms?: number): number[];
|
|
29
|
+
/**
|
|
30
|
+
* Euler numbers `E_0..E_n` (the coefficients in the secant Maclaurin series).
|
|
31
|
+
*
|
|
32
|
+
* `E_0 = 1`; all odd-index Euler numbers are 0; for even `m > 0`:
|
|
33
|
+
* `E_m = -sum_{k=0}^{m/2-1} C(m, 2k) * E_{2k}`.
|
|
34
|
+
*
|
|
35
|
+
* @param n - Non-negative integer: compute E_0 through E_n
|
|
36
|
+
* @returns Array of length `n + 1`: `[E_0, E_1, ..., E_n]`
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* eulerNumbers(6) // => [1, 0, -1, 0, 5, 0, -61]
|
|
40
|
+
*/
|
|
41
|
+
export declare function eulerNumbers(n: number): number[];
|
|
42
|
+
/**
|
|
43
|
+
* Signed Stirling number of the first kind `s(n, k)`.
|
|
44
|
+
*
|
|
45
|
+
* Recurrence: `s(n, k) = s(n-1, k-1) - (n-1)*s(n-1, k)`, with `s(0, 0) = 1`
|
|
46
|
+
* and `s(n, 0) = 0` for `n > 0`.
|
|
47
|
+
*
|
|
48
|
+
* @param n - Non-negative integer
|
|
49
|
+
* @param k - Non-negative integer, `0 <= k <= n`
|
|
50
|
+
* @returns The signed Stirling number `s(n, k)`
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* stirlingS1(5, 2) // => -50
|
|
54
|
+
*/
|
|
55
|
+
export declare function stirlingS1(n: number, k: number): number;
|
|
56
|
+
/**
|
|
57
|
+
* Discrete logarithm via baby-step giant-step: the smallest `x >= 0` such
|
|
58
|
+
* that `g^x === h (mod p)`, or `-1` if none exists within `[0, p-1]`.
|
|
59
|
+
*
|
|
60
|
+
* Uses `BigInt` internally for modular exponentiation/inversion to avoid
|
|
61
|
+
* overflow. `m = ceil(sqrt(p-1))` baby steps are stored in a map; the giant
|
|
62
|
+
* steps multiply by `g^(-m) mod p` each round.
|
|
63
|
+
*
|
|
64
|
+
* @param g - Base
|
|
65
|
+
* @param h - Target
|
|
66
|
+
* @param p - Prime modulus
|
|
67
|
+
* @returns The smallest non-negative `x` with `g^x === h (mod p)`, or `-1`
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* discreteLog(2, 3, 5) // => 3 (2^3 = 8 === 3 mod 5)
|
|
71
|
+
*/
|
|
72
|
+
export declare function discreteLog(g: number, h: number, p: number): number;
|
|
73
|
+
/**
|
|
74
|
+
* Smallest primitive root modulo a prime `p`.
|
|
75
|
+
*
|
|
76
|
+
* For each candidate `g = 2, 3, ...`, `g` is a primitive root iff
|
|
77
|
+
* `g^((p-1)/q) !== 1 (mod p)` for every prime factor `q` of `p - 1`.
|
|
78
|
+
*
|
|
79
|
+
* @param p - An odd prime (p = 2 returns 1 trivially)
|
|
80
|
+
* @returns The smallest primitive root modulo p
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* primitiveRoot(7) // => 3
|
|
84
|
+
*/
|
|
85
|
+
export declare function primitiveRoot(p: number): number;
|
|
86
|
+
/**
|
|
87
|
+
* Multiplicative order of `a` modulo `n`: the smallest `k > 0` with
|
|
88
|
+
* `a^k === 1 (mod n)`. Returns `-1` if `gcd(a, n) !== 1` (no order exists).
|
|
89
|
+
*
|
|
90
|
+
* @param a - Integer
|
|
91
|
+
* @param n - Positive integer modulus
|
|
92
|
+
* @returns The multiplicative order, or -1 if undefined
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* multiplicativeOrder(2, 7) // => 3
|
|
96
|
+
*/
|
|
97
|
+
export declare function multiplicativeOrder(a: number, n: number): number;
|
|
98
|
+
/**
|
|
99
|
+
* Kronecker symbol `(a|n)`, generalizing the Jacobi symbol `(a|n)` (odd
|
|
100
|
+
* positive `n`) to all integers `n`.
|
|
101
|
+
*
|
|
102
|
+
* - `(a|0) = 1` if `|a| = 1`, else `0`.
|
|
103
|
+
* - Sign of `n` is extracted first: `(a|-1) = -1` if `a < 0`, else `1`.
|
|
104
|
+
* - Factors of 2 are extracted from `n` using `(a|2)`: `0` if `a` even,
|
|
105
|
+
* `1` if `a === ±1 (mod 8)`, `-1` if `a === ±3 (mod 8)`.
|
|
106
|
+
* - The remaining odd part is evaluated via the standard Jacobi reciprocity
|
|
107
|
+
* recursion.
|
|
108
|
+
*
|
|
109
|
+
* @param a - Integer
|
|
110
|
+
* @param n - Integer
|
|
111
|
+
* @returns -1, 0, or 1
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* kroneckerSymbol(2, 3) // => -1
|
|
115
|
+
*/
|
|
116
|
+
export declare function kroneckerSymbol(a: number, n: number): number;
|
|
117
|
+
/**
|
|
118
|
+
* Enumerate all length-`k` combinations of `arr` (index-order subsequences,
|
|
119
|
+
* i.e. lexicographic order for a sorted input) as an array of tuples.
|
|
120
|
+
*
|
|
121
|
+
* @param arr - Source array
|
|
122
|
+
* @param k - Combination length
|
|
123
|
+
* @returns All `C(arr.length, k)` combinations, in lexicographic order
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* combinationsGen([1, 2, 3], 2) // => [[1,2],[1,3],[2,3]]
|
|
127
|
+
*/
|
|
128
|
+
export declare function combinationsGen<T>(arr: readonly T[], k: number): T[][];
|
|
129
|
+
/**
|
|
130
|
+
* Enumerate all length-`k` permutations (ordered arrangements) of `arr`
|
|
131
|
+
* as an array of tuples, in lexicographic order of index selection.
|
|
132
|
+
* `k` defaults to `arr.length` (full permutations).
|
|
133
|
+
*
|
|
134
|
+
* @param arr - Source array
|
|
135
|
+
* @param k - Permutation length (default: `arr.length`)
|
|
136
|
+
* @returns All `n! / (n-k)!` permutations, in lexicographic order
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* permutationsGen([1, 2, 3], 2) // => 6 tuples: [1,2],[1,3],[2,1],[2,3],[3,1],[3,2]
|
|
140
|
+
*/
|
|
141
|
+
export declare function permutationsGen<T>(arr: readonly T[], k?: number): T[][];
|
|
142
|
+
//# sourceMappingURL=extra.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extra.d.ts","sourceRoot":"","sources":["../../src/numbertheory/extra.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAMH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,SAAK,GAAG,MAAM,EAAE,CAcpE;AAiBD;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAkBhD;AAMD;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAevD;AAqCD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CA+BnE;AAoBD;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAmB/C;AAeD;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAehE;AAaD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CA0C5D;AAMD;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,GAAG,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,EAAE,CAoBtE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,GAAG,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,GAAE,MAAmB,GAAG,CAAC,EAAE,EAAE,CAwBnF"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gauss-Legendre quadrature nodes and weights.
|
|
3
|
+
*
|
|
4
|
+
* `rootsLegendre(n)` finds the n roots of the degree-n Legendre polynomial
|
|
5
|
+
* P_n via Newton's method (initial guess from the standard asymptotic
|
|
6
|
+
* approximation), then derives the corresponding quadrature weights. This is
|
|
7
|
+
* the classical fixed-node table underlying Gauss-Legendre quadrature on
|
|
8
|
+
* [-1, 1]; callers needing a custom node count (rather than the library's
|
|
9
|
+
* built-in fixed-order `integrate`/`gaussLegendre` routines) use this
|
|
10
|
+
* directly.
|
|
11
|
+
*
|
|
12
|
+
* @packageDocumentation
|
|
13
|
+
*/
|
|
14
|
+
/** Result of {@link rootsLegendre}: nodes ascending on [-1, 1] with matching weights. */
|
|
15
|
+
export interface RootsLegendreResult {
|
|
16
|
+
nodes: number[];
|
|
17
|
+
weights: number[];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* n-point Gauss-Legendre quadrature nodes and weights on [-1, 1].
|
|
21
|
+
*
|
|
22
|
+
* Nodes are the roots of the degree-n Legendre polynomial P_n, refined by
|
|
23
|
+
* Newton's method from the standard asymptotic initial guess
|
|
24
|
+
* `cos(pi*(i+0.75)/(n+0.5))`. Weights are `2 / ((1-x_i^2) * P'_n(x_i)^2)`.
|
|
25
|
+
*
|
|
26
|
+
* @param n - Number of quadrature points (positive integer)
|
|
27
|
+
* @returns Nodes (ascending) and matching weights
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* rootsLegendre(3)
|
|
31
|
+
* // { nodes: [-0.7745966692, 0, 0.7745966692],
|
|
32
|
+
* // weights: [0.5555555556, 0.8888888889, 0.5555555556] }
|
|
33
|
+
*/
|
|
34
|
+
export declare function rootsLegendre(n: number): RootsLegendreResult;
|
|
35
|
+
//# sourceMappingURL=gauss-nodes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gauss-nodes.d.ts","sourceRoot":"","sources":["../../src/numeric/gauss-nodes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH,yFAAyF;AACzF,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAuBD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,mBAAmB,CA+B5D"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hypergeometric functions.
|
|
3
|
+
*
|
|
4
|
+
* Implements the generalized hypergeometric series pFq via the ascending
|
|
5
|
+
* Pochhammer-ratio method: each term is generated from the previous one by
|
|
6
|
+
* multiplying by the ratio of rising factorials,
|
|
7
|
+
*
|
|
8
|
+
* term_{n+1} / term_n = ( prod_i (a_i + n) / prod_j (b_j + n) ) * z / (n + 1)
|
|
9
|
+
*
|
|
10
|
+
* accumulating until the term becomes negligible relative to the running sum
|
|
11
|
+
* (|term| < 1e-16 * |sum|) or a hard iteration cap is hit. This incremental
|
|
12
|
+
* form avoids recomputing factorials/Pochhammer symbols from scratch at each
|
|
13
|
+
* order and is numerically well-behaved for the convergent regimes documented
|
|
14
|
+
* per function below.
|
|
15
|
+
*
|
|
16
|
+
* @packageDocumentation
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Generalized hypergeometric function pFq(a; b; z), computed via the
|
|
20
|
+
* ascending Pochhammer-ratio series:
|
|
21
|
+
*
|
|
22
|
+
* pFq(a_1..a_p; b_1..b_q; z) = sum_{n=0}^inf
|
|
23
|
+
* ( prod_i (a_i)_n / prod_j (b_j)_n ) * z^n / n!
|
|
24
|
+
*
|
|
25
|
+
* This is the generic engine that hyp0f1/hyp1f1/hyp2f1 delegate to. No
|
|
26
|
+
* convergence-region check is performed here (that is the caller's
|
|
27
|
+
* responsibility, see hyp2f1's |z| < 1 guard) — the series is simply summed
|
|
28
|
+
* until it converges to machine precision or MAX_TERMS is reached.
|
|
29
|
+
*
|
|
30
|
+
* @param a - Upper (numerator) parameters
|
|
31
|
+
* @param b - Lower (denominator) parameters
|
|
32
|
+
* @param z - Argument
|
|
33
|
+
* @returns pFq(a; b; z)
|
|
34
|
+
*/
|
|
35
|
+
export declare function pFq(a: number[], b: number[], z: number): number;
|
|
36
|
+
/**
|
|
37
|
+
* Confluent hypergeometric limit function 0F1(; b; z):
|
|
38
|
+
*
|
|
39
|
+
* hyp0f1(b, z) = sum_{n=0}^inf z^n / ((b)_n n!)
|
|
40
|
+
*
|
|
41
|
+
* Entire in z (converges for all finite z, real or otherwise real-valued
|
|
42
|
+
* here); related to the Bessel functions.
|
|
43
|
+
*
|
|
44
|
+
* @param b - Parameter
|
|
45
|
+
* @param z - Argument
|
|
46
|
+
* @returns 0F1(; b; z)
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* hyp0f1(2, 0.5) // ~1.2717234563
|
|
50
|
+
*/
|
|
51
|
+
export declare function hyp0f1(b: number, z: number): number;
|
|
52
|
+
/**
|
|
53
|
+
* Kummer's confluent hypergeometric function 1F1(a; b; z) (Kummer's M):
|
|
54
|
+
*
|
|
55
|
+
* hyp1f1(a, b, z) = sum_{n=0}^inf ( (a)_n / (b)_n ) * z^n / n!
|
|
56
|
+
*
|
|
57
|
+
* Entire in z. The direct ascending series targets moderate |z| — for large
|
|
58
|
+
* |z| the series requires many terms and loses accuracy to cancellation
|
|
59
|
+
* (particularly when a and b have opposite signs); an asymptotic expansion
|
|
60
|
+
* would be needed for large |z| but is not implemented here.
|
|
61
|
+
*
|
|
62
|
+
* @param a - Numerator parameter
|
|
63
|
+
* @param b - Denominator parameter
|
|
64
|
+
* @param z - Argument
|
|
65
|
+
* @returns 1F1(a; b; z)
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* hyp1f1(1, 2, 0.5) // ~1.2974425414
|
|
69
|
+
*/
|
|
70
|
+
export declare function hyp1f1(a: number, b: number, z: number): number;
|
|
71
|
+
/**
|
|
72
|
+
* Gauss's hypergeometric function 2F1(a, b; c; z):
|
|
73
|
+
*
|
|
74
|
+
* hyp2f1(a, b, c, z) = sum_{n=0}^inf ( (a)_n (b)_n / (c)_n ) * z^n / n!
|
|
75
|
+
*
|
|
76
|
+
* The ascending series converges only for |z| < 1. Analytic continuation
|
|
77
|
+
* beyond the unit disk (e.g. via connection formulas or a transformation to
|
|
78
|
+
* 1-z) is not yet implemented.
|
|
79
|
+
*
|
|
80
|
+
* @param a - First numerator parameter
|
|
81
|
+
* @param b - Second numerator parameter
|
|
82
|
+
* @param c - Denominator parameter
|
|
83
|
+
* @param z - Argument, must satisfy |z| < 1
|
|
84
|
+
* @returns 2F1(a, b; c; z)
|
|
85
|
+
* @throws {Error} If |z| >= 1
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* hyp2f1(1, 2, 3, 0.5) // ~1.5451774445
|
|
89
|
+
*/
|
|
90
|
+
export declare function hyp2f1(a: number, b: number, c: number, z: number): number;
|
|
91
|
+
//# sourceMappingURL=hypergeometric.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hypergeometric.d.ts","sourceRoot":"","sources":["../../src/special/hypergeometric.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAQH;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAgB/D;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAE9D;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAKzE"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Jacobi elliptic functions sn, cn, dn.
|
|
3
|
+
*
|
|
4
|
+
* Uses the parameter convention `m = k^2` (matching scipy's
|
|
5
|
+
* `scipy.special.ellipj(u, m)` and mpmath's `ellipfun(..., u, m)`), not the
|
|
6
|
+
* modulus-angle convention some texts use.
|
|
7
|
+
*
|
|
8
|
+
* Computed via the descending Landen transformation / arithmetic-geometric
|
|
9
|
+
* mean (AGM) method (Abramowitz & Stegun 16.4, the Bulirsch algorithm):
|
|
10
|
+
* build the AGM sequences
|
|
11
|
+
*
|
|
12
|
+
* a_0 = 1, b_0 = sqrt(1 - m), c_0 = sqrt(m)
|
|
13
|
+
* a_{i+1} = (a_i + b_i) / 2
|
|
14
|
+
* b_{i+1} = sqrt(a_i * b_i)
|
|
15
|
+
* c_{i+1} = (a_i - b_i) / 2
|
|
16
|
+
*
|
|
17
|
+
* until c_N is negligible, then descend the amplitude
|
|
18
|
+
*
|
|
19
|
+
* phi_N = 2^N * a_N * u
|
|
20
|
+
* phi_{i-1} = (phi_i + asin((c_i / a_i) * sin(phi_i))) / 2 for i = N..1
|
|
21
|
+
*
|
|
22
|
+
* so that sn(u,m) = sin(phi_0), cn(u,m) = cos(phi_0),
|
|
23
|
+
* dn(u,m) = sqrt(1 - m * sn^2(u,m)).
|
|
24
|
+
*
|
|
25
|
+
* @packageDocumentation
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* Jacobi elliptic function sn(u, m), parameter convention m = k^2.
|
|
29
|
+
*
|
|
30
|
+
* @param u - Argument
|
|
31
|
+
* @param m - Parameter m = k^2, must be in [0, 1]
|
|
32
|
+
* @returns sn(u, m)
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* jacobiSN(0.5, 0.3) // ~0.4742156227
|
|
36
|
+
*/
|
|
37
|
+
export declare function jacobiSN(u: number, m: number): number;
|
|
38
|
+
/**
|
|
39
|
+
* Jacobi elliptic function cn(u, m), parameter convention m = k^2.
|
|
40
|
+
*
|
|
41
|
+
* @param u - Argument
|
|
42
|
+
* @param m - Parameter m = k^2, must be in [0, 1]
|
|
43
|
+
* @returns cn(u, m)
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* jacobiCN(0.5, 0.3) // ~0.8804087364
|
|
47
|
+
*/
|
|
48
|
+
export declare function jacobiCN(u: number, m: number): number;
|
|
49
|
+
/**
|
|
50
|
+
* Jacobi elliptic function dn(u, m), parameter convention m = k^2.
|
|
51
|
+
*
|
|
52
|
+
* @param u - Argument
|
|
53
|
+
* @param m - Parameter m = k^2, must be in [0, 1]
|
|
54
|
+
* @returns dn(u, m)
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* jacobiDN(0.5, 0.3) // ~0.9656789647
|
|
58
|
+
*/
|
|
59
|
+
export declare function jacobiDN(u: number, m: number): number;
|
|
60
|
+
//# sourceMappingURL=jacobi-elliptic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jacobi-elliptic.d.ts","sourceRoot":"","sources":["../../src/special/jacobi-elliptic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAwDH;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAErD;AAED;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAErD;AAED;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAErD"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Polygamma functions and classical orthogonal polynomials.
|
|
3
|
+
*
|
|
4
|
+
* `polygamma(n, x)` is the n-th derivative of the digamma function,
|
|
5
|
+
* ψ^(n)(x) = d^n/dx^n ψ(x). It is computed by shifting the argument up via
|
|
6
|
+
* the standard recurrence
|
|
7
|
+
*
|
|
8
|
+
* ψ^(n)(x) = ψ^(n)(x + m) + (-1)^(n+1) n! * sum_{k=0}^{m-1} 1/(x+k)^(n+1)
|
|
9
|
+
*
|
|
10
|
+
* until x + m is large enough (>= SHIFT_THRESHOLD) for the asymptotic
|
|
11
|
+
* (Bernoulli) expansion (DLMF 5.15.8) to converge to machine precision:
|
|
12
|
+
*
|
|
13
|
+
* psi^(n)(X) ~ (-1)^(n-1) * [ (n-1)!/X^n + n!/(2 X^(n+1))
|
|
14
|
+
* + sum_j B_{2j} * (2j+n-1)! / ((2j)! * X^(2j+n)) ]
|
|
15
|
+
*
|
|
16
|
+
* Since (-1)^(n+1) = (-1)^(n-1), both pieces share the same overall sign.
|
|
17
|
+
*
|
|
18
|
+
* `jacobiP` and `gegenbauerC` are evaluated with their standard stable
|
|
19
|
+
* three-term recurrences (DLMF 18.9.2 and 18.9.1 respectively), matching the
|
|
20
|
+
* pattern already used for `chebyshevT` / `hermiteH` / `laguerreL` /
|
|
21
|
+
* `legendreP`.
|
|
22
|
+
*
|
|
23
|
+
* @packageDocumentation
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* Polygamma function ψ^(n)(x): the n-th derivative of the digamma function.
|
|
27
|
+
*
|
|
28
|
+
* `polygamma(0, x)` delegates to `digamma(x)`. For `n >= 1`, x is shifted up
|
|
29
|
+
* via the standard recurrence until it is large enough for the Bernoulli
|
|
30
|
+
* asymptotic expansion to converge.
|
|
31
|
+
*
|
|
32
|
+
* @param n - Derivative order (nonnegative integer)
|
|
33
|
+
* @param x - Argument (must not be a nonpositive integer, where ψ^(n) has poles)
|
|
34
|
+
* @returns ψ^(n)(x)
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* polygamma(1, 2) // ~0.6449340668 (trigamma(2))
|
|
38
|
+
* polygamma(2, 1) // ~-2.4041138063
|
|
39
|
+
*/
|
|
40
|
+
export declare function polygamma(n: number, x: number): number;
|
|
41
|
+
/**
|
|
42
|
+
* Trigamma function ψ'(x) = ψ^(1)(x): the first derivative of the digamma
|
|
43
|
+
* function. Equivalent to `polygamma(1, x)`.
|
|
44
|
+
*
|
|
45
|
+
* @param x - Argument
|
|
46
|
+
* @returns ψ'(x)
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* trigamma(2) // ~0.6449340668 (= zeta(2) - 1 = pi^2/6 - 1)
|
|
50
|
+
*/
|
|
51
|
+
export declare function trigamma(x: number): number;
|
|
52
|
+
/**
|
|
53
|
+
* Jacobi polynomial P_n^(alpha,beta)(x), evaluated via the standard
|
|
54
|
+
* three-term recurrence (DLMF 18.9.2).
|
|
55
|
+
*
|
|
56
|
+
* @param n - Degree (nonnegative integer)
|
|
57
|
+
* @param alpha - Parameter alpha (> -1)
|
|
58
|
+
* @param beta - Parameter beta (> -1)
|
|
59
|
+
* @param x - Evaluation point
|
|
60
|
+
* @returns P_n^(alpha,beta)(x)
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* jacobiP(2, 1, 1, 0.5) // 0.1875
|
|
64
|
+
*/
|
|
65
|
+
export declare function jacobiP(n: number, alpha: number, beta: number, x: number): number;
|
|
66
|
+
/**
|
|
67
|
+
* Gegenbauer (ultraspherical) polynomial C_n^(alpha)(x), evaluated via the
|
|
68
|
+
* standard three-term recurrence (DLMF 18.9.1).
|
|
69
|
+
*
|
|
70
|
+
* @param n - Degree (nonnegative integer)
|
|
71
|
+
* @param alpha - Parameter alpha (> -1/2, alpha != 0)
|
|
72
|
+
* @param x - Evaluation point
|
|
73
|
+
* @returns C_n^(alpha)(x)
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* gegenbauerC(2, 1, 1) // 3 (C_2^(1)(x) = 4x^2 - 1)
|
|
77
|
+
*/
|
|
78
|
+
export declare function gegenbauerC(n: number, alpha: number, x: number): number;
|
|
79
|
+
//# sourceMappingURL=polygamma-orthopoly.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"polygamma-orthopoly.d.ts","sourceRoot":"","sources":["../../src/special/polygamma-orthopoly.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAiBH;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAkCtD;AAED;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE1C;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAqBjF;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAgBvE"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maximum-likelihood distribution fitting (Phase 4 Task 1).
|
|
3
|
+
*
|
|
4
|
+
* `fitDistribution(name, data)` fits one of five common distributions to a
|
|
5
|
+
* sample by maximum likelihood and reports the fitted parameters plus the
|
|
6
|
+
* achieved log-likelihood.
|
|
7
|
+
*
|
|
8
|
+
* - `normal` — closed form: mu = mean, sigma = population std (ddof=0).
|
|
9
|
+
* - `exponential` — closed form: lambda = 1 / mean.
|
|
10
|
+
* - `lognormal` — fit a normal to ln(data) (requires all data > 0).
|
|
11
|
+
* - `poisson` — closed form: lambda = mean.
|
|
12
|
+
* - `gamma` — no closed form for the shape parameter. Given shape k,
|
|
13
|
+
* the MLE scale is theta = xbar / k; substituting back yields the
|
|
14
|
+
* 1-D shape equation `ln(k) - psi(k) = ln(xbar) - mean(ln x)`
|
|
15
|
+
* (psi = digamma), solved here with the secant method starting from the
|
|
16
|
+
* Choi & Wette (1969) initial guess.
|
|
17
|
+
*
|
|
18
|
+
* @packageDocumentation
|
|
19
|
+
*/
|
|
20
|
+
/** Supported distribution families for {@link fitDistribution}. */
|
|
21
|
+
export type DistributionName = 'normal' | 'exponential' | 'lognormal' | 'poisson' | 'gamma';
|
|
22
|
+
/** Result of {@link fitDistribution}: fitted parameters + achieved log-likelihood. */
|
|
23
|
+
export interface FitDistributionResult {
|
|
24
|
+
/** Fitted parameters, named per distribution (see {@link fitDistribution}). */
|
|
25
|
+
params: Record<string, number>;
|
|
26
|
+
/** Log-likelihood of `data` under the fitted parameters. */
|
|
27
|
+
logLikelihood: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Fit a distribution to `data` by maximum likelihood.
|
|
31
|
+
*
|
|
32
|
+
* @param name - Distribution family: 'normal' | 'exponential' | 'lognormal' | 'poisson' | 'gamma'
|
|
33
|
+
* @param data - Sample data
|
|
34
|
+
* @returns Fitted parameters and the log-likelihood achieved under them
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* fitDistribution('normal', [2, 4, 4, 4, 5, 5, 7, 9]);
|
|
38
|
+
* // { params: { mean: 5, std: 2 }, logLikelihood: ... }
|
|
39
|
+
*
|
|
40
|
+
* fitDistribution('exponential', [1, 2, 3, 2]);
|
|
41
|
+
* // { params: { lambda: 0.5 }, logLikelihood: ... }
|
|
42
|
+
*/
|
|
43
|
+
export declare function fitDistribution(name: DistributionName, data: readonly number[]): FitDistributionResult;
|
|
44
|
+
//# sourceMappingURL=fit-distribution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fit-distribution.d.ts","sourceRoot":"","sources":["../../src/stats/fit-distribution.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAMH,mEAAmE;AACnE,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG,aAAa,GAAG,WAAW,GAAG,SAAS,GAAG,OAAO,CAAC;AAE5F,sFAAsF;AACtF,MAAM,WAAW,qBAAqB;IACpC,+EAA+E;IAC/E,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,4DAA4D;IAC5D,aAAa,EAAE,MAAM,CAAC;CACvB;AA8FD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,gBAAgB,EACtB,IAAI,EAAE,SAAS,MAAM,EAAE,GACtB,qBAAqB,CAoBvB"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Noncentral chi-squared CDF via the Poisson-mixture representation:
|
|
3
|
+
*
|
|
4
|
+
* F(x; k, λ) = Σ_{j=0}^∞ Pois(j; λ/2) · chiSquaredCDF(x, k + 2j)
|
|
5
|
+
*
|
|
6
|
+
* Truncated once the cumulative Poisson mass covers `1 − 1e-12` of the total
|
|
7
|
+
* (past the Poisson mode, so truncation never fires during the rising phase).
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* noncentralChi2CDF(10, 3, 2); // ~0.89856 (scipy ncx2.cdf)
|
|
11
|
+
*/
|
|
12
|
+
export declare function noncentralChi2CDF(x: number, df: number, nc: number): number;
|
|
13
|
+
/**
|
|
14
|
+
* Noncentral F CDF via the Poisson-mixture representation over the numerator
|
|
15
|
+
* degrees of freedom:
|
|
16
|
+
*
|
|
17
|
+
* F(x; d1, d2, λ) = Σ_{j=0}^∞ Pois(j; λ/2) · fCDF(x·d1/(d1+2j), d1+2j, d2)
|
|
18
|
+
*
|
|
19
|
+
* Truncated the same way as {@link noncentralChi2CDF}.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* noncentralFCDF(2, 3, 10, 4); // ~0.46636 (scipy ncf.cdf)
|
|
23
|
+
*/
|
|
24
|
+
export declare function noncentralFCDF(x: number, dfn: number, dfd: number, nc: number): number;
|
|
25
|
+
/**
|
|
26
|
+
* Noncentral Student-t CDF via the mixture representation
|
|
27
|
+
* `T = (Z + δ) / sqrt(V/ν)`, `Z ~ N(0,1)`, `V ~ χ²_ν` independent:
|
|
28
|
+
*
|
|
29
|
+
* F(t; ν, δ) = E_V[ Φ(t·sqrt(V/ν) − δ) ] = ∫₀^∞ Φ(t·sqrt(v/ν) − δ) · χ²_ν(v) dv
|
|
30
|
+
*
|
|
31
|
+
* Evaluated by composite Simpson's rule over `v` (central-χ² density; `δ`
|
|
32
|
+
* only enters the normal-CDF term). The upper integration bound is set
|
|
33
|
+
* generously past the χ²_ν tail so the truncation error is negligible
|
|
34
|
+
* relative to the ~1e-4 Simpson discretization error at the panel count used.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* noncentralTCDF(1.5, 10, 2); // ~0.30479 (scipy nct.cdf)
|
|
38
|
+
*/
|
|
39
|
+
export declare function noncentralTCDF(t: number, df: number, nc: number): number;
|
|
40
|
+
/** Options shared by the circular-statistics functions. */
|
|
41
|
+
export interface CircularOptions {
|
|
42
|
+
/** Upper bound of the angular range. Default `2π`. */
|
|
43
|
+
high?: number;
|
|
44
|
+
/** Lower bound of the angular range. Default `0`. */
|
|
45
|
+
low?: number;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Circular (angular) mean, mapped back into `[low, high)`.
|
|
49
|
+
*
|
|
50
|
+
* `mean = atan2(Σsinθ, Σcosθ)`, where `θ` is `angles` rescaled into
|
|
51
|
+
* `[0, 2π)` when a non-default `[low, high)` range is given (matching
|
|
52
|
+
* `scipy.stats.circmean`).
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* circmean([0.1, 0.2, 6.2]); // ~0.07236 (scipy circmean; wraps near 0)
|
|
56
|
+
*/
|
|
57
|
+
export declare function circmean(angles: readonly number[], opts?: CircularOptions): number;
|
|
58
|
+
/**
|
|
59
|
+
* Circular variance `1 − R`, where `R = |Σcosθ + iΣsinθ| / n` is the mean
|
|
60
|
+
* resultant length. `R ∈ [0, 1]`, so `circvar ∈ [0, 1]`.
|
|
61
|
+
*/
|
|
62
|
+
export declare function circvar(angles: readonly number[], opts?: CircularOptions): number;
|
|
63
|
+
/**
|
|
64
|
+
* Circular standard deviation `sqrt(−2·ln(R))` (matches `scipy.stats.circstd`
|
|
65
|
+
* with the default `normalize=False` low/high dispersion measure).
|
|
66
|
+
*/
|
|
67
|
+
export declare function circstd(angles: readonly number[], opts?: CircularOptions): number;
|
|
68
|
+
/**
|
|
69
|
+
* Von Mises probability density function (the circular analogue of the
|
|
70
|
+
* normal distribution).
|
|
71
|
+
*
|
|
72
|
+
* f(θ; μ, κ) = exp(κ·cos(θ − μ)) / (2π·I₀(κ))
|
|
73
|
+
*
|
|
74
|
+
* `I₀` is the modified Bessel function of the first kind, order 0
|
|
75
|
+
* (`besselIScalar` — the shared special-function scalar backing the public
|
|
76
|
+
* `besselI`).
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* vonMisesPDF(0, 0, 2); // ~0.51589 (scipy vonmises.pdf(0, 2))
|
|
80
|
+
*/
|
|
81
|
+
export declare function vonMisesPDF(theta: number, mu: number, kappa: number): number;
|
|
82
|
+
/** Options for {@link mcnemar}. */
|
|
83
|
+
export interface McNemarOptions {
|
|
84
|
+
/** Apply the continuity correction (`|b−c| − 1`). Default `true`. */
|
|
85
|
+
correction?: boolean;
|
|
86
|
+
}
|
|
87
|
+
/** Result of {@link mcnemar}. */
|
|
88
|
+
export interface McNemarResult {
|
|
89
|
+
chi2: number;
|
|
90
|
+
pValue: number;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* McNemar's test for paired nominal data on a 2x2 table
|
|
94
|
+
* `[[a, b], [c, d]]` (only the discordant pairs `b`, `c` matter):
|
|
95
|
+
*
|
|
96
|
+
* chi2 = (|b − c| − correction)² / (b + c)
|
|
97
|
+
*
|
|
98
|
+
* with the continuity correction (`1`) applied by default, matching
|
|
99
|
+
* `statsmodels.stats.contingency_tables.mcnemar`. `pValue = 1 −
|
|
100
|
+
* chiSquaredCDF(chi2, 1)`.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* mcnemar([[10, 5], [3, 12]], { correction: false }); // { chi2: 0.5, pValue: ... }
|
|
104
|
+
*/
|
|
105
|
+
export declare function mcnemar(table: readonly (readonly number[])[], opts?: McNemarOptions): McNemarResult;
|
|
106
|
+
/** Result of {@link cochranQ}. */
|
|
107
|
+
export interface CochranQResult {
|
|
108
|
+
Q: number;
|
|
109
|
+
pValue: number;
|
|
110
|
+
dof: number;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Cochran's Q test — the extension of McNemar's test to `k > 2` matched
|
|
114
|
+
* binary treatments. `data` has one row per subject, one column per
|
|
115
|
+
* treatment (0/1 entries).
|
|
116
|
+
*
|
|
117
|
+
* Q = (k−1)·(k·ΣCⱼ² − N²) / (k·N − ΣRᵢ²)
|
|
118
|
+
*
|
|
119
|
+
* where `Cⱼ` are column sums, `Rᵢ` are row sums, and `N = ΣRᵢ`. `dof = k −
|
|
120
|
+
* 1`; `pValue = 1 − chiSquaredCDF(Q, k−1)`. Matches
|
|
121
|
+
* `statsmodels.stats.contingency_tables.cochrans_q`.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* cochranQ([[1, 1, 0], [1, 0, 0], [1, 1, 1], [0, 1, 0], [1, 1, 0]]);
|
|
125
|
+
*/
|
|
126
|
+
export declare function cochranQ(data: readonly (readonly number[])[]): CochranQResult;
|
|
127
|
+
//# sourceMappingURL=inference-extra2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inference-extra2.d.ts","sourceRoot":"","sources":["../../src/stats/inference-extra2.ts"],"names":[],"mappings":"AAgBA;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAiB3E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAkBtF;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAsBxE;AAED,2DAA2D;AAC3D,MAAM,WAAW,eAAe;IAC9B,sDAAsD;IACtD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,qDAAqD;IACrD,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAsBD;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,EAAE,IAAI,GAAE,eAAoB,GAAG,MAAM,CAMtF;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,EAAE,IAAI,GAAE,eAAoB,GAAG,MAAM,CAMrF;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,EAAE,IAAI,GAAE,eAAoB,GAAG,MAAM,CAMrF;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAG5E;AAED,mCAAmC;AACnC,MAAM,WAAW,cAAc;IAC7B,qEAAqE;IACrE,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,iCAAiC;AACjC,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,OAAO,CACrB,KAAK,EAAE,SAAS,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,EACrC,IAAI,GAAE,cAAmB,GACxB,aAAa,CAYf;AAED,kCAAkC;AAClC,MAAM,WAAW,cAAc;IAC7B,CAAC,EAAE,MAAM,CAAC;IACV,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;CACb;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,GAAG,cAAc,CA8B7E"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Partial autocorrelation function up to `nlags` (inclusive), via the
|
|
3
|
+
* Levinson-Durbin recursion applied to the biased autocorrelations (`acf`).
|
|
4
|
+
* `pacf[0] = 1`. Matches `statsmodels.tsa.stattools.pacf(x, nlags, method='ldb')`.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* pacf([1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2], 3) // => [1, 0, -0.8333..., 0]
|
|
8
|
+
*/
|
|
9
|
+
export declare function pacf(x: number[], nlags: number): number[];
|
|
10
|
+
/** Result of {@link ljungBox}. */
|
|
11
|
+
export interface LjungBoxResult {
|
|
12
|
+
statistic: number;
|
|
13
|
+
pValue: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Ljung-Box portmanteau test for autocorrelation up to lag `lags`.
|
|
17
|
+
* `Q = n(n+2) * Σ_{k=1}^{lags} ρ_k² / (n-k)`, `pValue = 1 - chiSquaredCDF(Q, lags)`.
|
|
18
|
+
* Matches `statsmodels.stats.diagnostic.acorr_ljungbox`.
|
|
19
|
+
*/
|
|
20
|
+
export declare function ljungBox(x: number[], lags: number): LjungBoxResult;
|
|
21
|
+
/**
|
|
22
|
+
* Durbin-Watson statistic for residual autocorrelation:
|
|
23
|
+
* `Σ_{t=2}^{n}(e_t - e_{t-1})² / Σ_{t=1}^{n} e_t²`. Ranges (0, 4); ~2 indicates
|
|
24
|
+
* no autocorrelation, <2 positive autocorrelation, >2 negative. Matches
|
|
25
|
+
* `statsmodels.stats.stattools.durbin_watson`.
|
|
26
|
+
*/
|
|
27
|
+
export declare function durbinWatson(residuals: number[]): number;
|
|
28
|
+
/** Result of {@link adfuller}. */
|
|
29
|
+
export interface AdfullerResult {
|
|
30
|
+
statistic: number;
|
|
31
|
+
pValue: number;
|
|
32
|
+
usedLag: number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Augmented Dickey-Fuller unit-root test (constant-only "c" model):
|
|
36
|
+
* regresses `Δx_t` on `[1, x_{t-1}, Δx_{t-1}, ..., Δx_{t-maxlag}]` via OLS.
|
|
37
|
+
* `statistic = coefficients[1] / stderr[1]` (the t-stat on the lagged level,
|
|
38
|
+
* `coefficients[0]` being the intercept). `pValue` is an approximate
|
|
39
|
+
* MacKinnon-style interpolation (see module docstring) — not exact.
|
|
40
|
+
*
|
|
41
|
+
* Default `maxlag = floor(12 * (n/100)^0.25)` (matches
|
|
42
|
+
* `statsmodels.tsa.stattools.adfuller`'s default rule), clamped downward if
|
|
43
|
+
* needed so the regression has more observations than parameters; `usedLag`
|
|
44
|
+
* reports the lag count actually used.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* adfuller(whiteNoiseSeries) // => { statistic: <very negative>, pValue: <small>, usedLag }
|
|
48
|
+
*/
|
|
49
|
+
export declare function adfuller(x: number[], maxlag?: number): AdfullerResult;
|
|
50
|
+
//# sourceMappingURL=timeseries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeseries.d.ts","sourceRoot":"","sources":["../../src/stats/timeseries.ts"],"names":[],"mappings":"AA6BA;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CA+BzD;AAED,kCAAkC;AAClC,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,cAAc,CAUlE;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,MAAM,CAUxD;AAED,kCAAkC;AAClC,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;AAkDD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,cAAc,CAwCrE"}
|