@numero-uno-jpn/rstats 0.15.0 → 0.15.2
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/CHANGELOG.md +48 -0
- package/README.ja.md +8 -8
- package/README.md +8 -8
- package/dist/chunks/chunk-2CUKVVRO.js +2 -0
- package/dist/chunks/{chunk-4XGKAHD3.js → chunk-3WQCKGKP.js} +2 -2
- package/dist/chunks/{chunk-7XHAE2LG.js → chunk-4Z2XDWKV.js} +1 -1
- package/dist/chunks/{chunk-QQIWOGHR.js → chunk-AJBLCNZ7.js} +2 -2
- package/dist/chunks/chunk-D4F7GQAY.js +2 -0
- package/dist/chunks/chunk-EBQMGCQZ.js +2 -0
- package/dist/chunks/{chunk-WEWXYHPR.js → chunk-HBMHR5SS.js} +2 -2
- package/dist/chunks/{chunk-HS7KIFMR.js → chunk-IBPWRQIF.js} +2 -2
- package/dist/chunks/chunk-JLAH3X77.js +2 -0
- package/dist/chunks/chunk-LG74QY5U.js +2 -0
- package/dist/chunks/{chunk-A3XZUJCP.js → chunk-PEYGUK32.js} +2 -2
- package/dist/chunks/{chunk-HNLKOICT.js → chunk-PWVQVJTP.js} +1 -1
- package/dist/chunks/{chunk-AEFWSUZ2.js → chunk-Q4PGYESP.js} +2 -2
- package/dist/chunks/{chunk-GZTLODPK.js → chunk-RCAL4VHM.js} +2 -2
- package/dist/chunks/{chunk-XMTYTJT6.js → chunk-SREPSVTT.js} +2 -2
- package/dist/chunks/chunk-UFT662QZ.js +2 -0
- package/dist/chunks/{chunk-CJ5ETQCK.js → chunk-VWJ74UHC.js} +2 -2
- package/dist/chunks/{chunk-VAPGDPHM.js → chunk-XNPU54NH.js} +1 -1
- package/dist/chunks/{chunk-PRDF6IU6.js → chunk-XPLDEK6D.js} +2 -2
- package/dist/chunks/{chunk-LWUTCYTZ.js → chunk-YGT4P7EU.js} +1 -1
- package/dist/chunks/{chunk-7GEYDIQC.js → chunk-YVREYVI2.js} +2 -2
- package/dist/descriptive.js +2 -2
- package/dist/distributions/arcsine.js +48 -4
- package/dist/distributions/beta.d.ts +1 -1
- package/dist/distributions/beta.js +64 -1
- package/dist/distributions/exponential.js +11 -2
- package/dist/distributions/f.js +104 -21
- package/dist/distributions/gamma.d.ts +13 -2
- package/dist/distributions/gamma.js +91 -12
- package/dist/distributions/geometric.js +16 -3
- package/dist/distributions/invgamma.js +56 -10
- package/dist/distributions/kumaraswamy.js +98 -17
- package/dist/distributions/lognormal.js +28 -4
- package/dist/distributions/nbeta.js +540 -37
- package/dist/distributions/nchisq.d.ts +25 -0
- package/dist/distributions/nchisq.js +396 -60
- package/dist/distributions/negbinomial.js +20 -5
- package/dist/distributions/normal.js +3 -0
- package/dist/distributions/nt.js +263 -51
- package/dist/distributions/pareto.js +68 -19
- package/dist/distributions/signrank.js +73 -20
- package/dist/distributions/t.js +48 -10
- package/dist/distributions/triangular.js +66 -27
- package/dist/distributions/tukey.js +94 -50
- package/dist/distributions/uniform.js +12 -9
- package/dist/distributions/weibull.js +43 -8
- package/dist/distributions.js +2 -2
- package/dist/internal/ddexp.d.ts +5 -0
- package/dist/internal/ddexp.js +28 -3
- package/dist/internal/discrete.js +30 -7
- package/dist/internal/invert.js +49 -0
- package/dist/internal/noncentral.d.ts +34 -0
- package/dist/internal/noncentral.js +115 -2
- package/dist/internal/poissonMixture.d.ts +7 -2
- package/dist/internal/poissonMixture.js +113 -32
- package/dist/linalg.js +2 -2
- package/dist/mixed.js +2 -2
- package/dist/numerics.js +2 -2
- package/dist/rstats.js +14 -14
- package/dist/special/dd.d.ts +1 -1
- package/dist/special/dd.js +4 -1
- package/dist/special/igam.js +93 -15
- package/dist/special/incbet.d.ts +10 -0
- package/dist/special/incbet.js +154 -48
- package/dist/special/incbetLargeA.js +47 -13
- package/dist/special/incbetPrefactor.d.ts +52 -0
- package/dist/special/incbetPrefactor.js +92 -0
- package/dist/special/incbetTemme.js +15 -3
- package/dist/special/loader.js +33 -7
- package/dist/special.js +2 -2
- package/dist/tests.js +2 -2
- package/package.json +1 -1
- package/dist/chunks/chunk-4EOKNOXP.js +0 -2
- package/dist/chunks/chunk-CMPDE3SZ.js +0 -2
- package/dist/chunks/chunk-LU5FHU2O.js +0 -2
- package/dist/chunks/chunk-LVXAWWUX.js +0 -2
- package/dist/chunks/chunk-NYGWVZOC.js +0 -2
- package/dist/chunks/chunk-VSKWQMSG.js +0 -2
|
@@ -23,16 +23,18 @@
|
|
|
23
23
|
// H side below it); the other tail is 1 - (that one), which is at least 1/2. Boost computes only the J side.
|
|
24
24
|
// - M is formed as [x^a (1-x)^b / B(a, b)] x^((b-1)/2) (l/y)^b, y = 1 - x, with the first factor from Loader's
|
|
25
25
|
// binomial density (dbinomExponent, the deviances in double-double), instead of Γ(a + b) / (Γ(a) T^b) times
|
|
26
|
-
// u^b e^-u / Γ(b), whose parts cancel for large a
|
|
26
|
+
// u^b e^-u / Γ(b), whose parts cancel for large a (for a small b or a huge a, the first factor from
|
|
27
|
+
// incbetPrefactor.ts instead).
|
|
27
28
|
// - l = -log x and u are formed in double-double from x in double-double: the result is about as sensitive to the
|
|
28
29
|
// absolute error of u as to a relative one, and u is of order b.
|
|
29
30
|
// - J_0 comes from a continued fraction evaluated backwards (below), not from the incomplete gamma function of
|
|
30
31
|
// igam.ts, and H_N from the series in double-double: both to about an ulp.
|
|
31
32
|
import { dbinomExponent } from "./loader.js";
|
|
32
|
-
import { ddAdd, ddDiv, ddLog, ddMul, ddMulNum, ddSub, twoProd, twoSum } from "./dd.js";
|
|
33
|
+
import { ddAdd, ddDiv, ddLog, ddMul, ddMulNum, ddNeg, ddSub, twoProd, twoSum } from "./dd.js";
|
|
33
34
|
import { erfcxNonNegative } from "./erf.js";
|
|
34
35
|
import { igamSeriesSumDD } from "./igam.js";
|
|
35
36
|
import { halfErfc } from "./incbetTemme.js";
|
|
37
|
+
import { prefactorParts } from "./incbetPrefactor.js";
|
|
36
38
|
/**
|
|
37
39
|
* Region where the expansion is used (the caller tries it where it would otherwise use the continued fraction):
|
|
38
40
|
* a >= LARGE_A_MIN, b <= SMALL_B_MAX, y = 1 - x <= Y_MAX, u <= U_MAX, and on the J side u >= U_MIN_J (below,
|
|
@@ -113,15 +115,21 @@ export function betaIncLargeA(a, b, xd, yd, lower, wantLog) {
|
|
|
113
115
|
// The median of Gamma(b, 1) is about b - 1/3 for b >= 1 and below 2^(-1/b) for small b
|
|
114
116
|
const med = b >= 1 ? b - 1 / 3 : Math.pow(0.5, 1 / b);
|
|
115
117
|
const jSide = u0 >= med;
|
|
116
|
-
|
|
118
|
+
// (Where x rounds to 1 nothing else in incbet.ts applies, so U_MAX is not imposed there)
|
|
119
|
+
if ((u0 > U_MAX && xd[0] < 1) || (jSide && u0 < U_MIN_J))
|
|
117
120
|
return undefined;
|
|
118
121
|
// T = a + (b - 1)/2, l = -log x and u = T l in double-double
|
|
119
122
|
const bm1 = twoSum(b, -1);
|
|
120
123
|
const td = ddAdd([a, 0], [bm1[0] / 2, bm1[1] / 2]);
|
|
121
|
-
|
|
124
|
+
// For y below 1e-15, l = y + y^2/2 (+ y^3/3, below 1e-30 relative) from y: the logarithm of x is accurate to about
|
|
125
|
+
// 1e-32 absolute, which is all of l when y is tiny (l came out 0 for y = 6e-79 and the continued fraction for J_0,
|
|
126
|
+
// with 100/u steps, did not end)
|
|
127
|
+
const lx = y < 1e-15 ? ddNeg(ddAdd(yd, [(y * y) / 2, 0])) : ddLog(xd);
|
|
122
128
|
const ld = [-lx[0], -lx[1]];
|
|
123
129
|
const ud = ddMul(td, ld);
|
|
124
130
|
const u = ud[0] + ud[1];
|
|
131
|
+
if (!(u > 0 && u < Infinity))
|
|
132
|
+
return undefined;
|
|
125
133
|
// (the low part of u, which the incomplete gamma functions below take into account)
|
|
126
134
|
const uLow = ud[1] - (u - ud[0]);
|
|
127
135
|
const l = ld[0];
|
|
@@ -129,14 +137,29 @@ export function betaIncLargeA(a, b, xd, yd, lower, wantLog) {
|
|
|
129
137
|
// M = [x^a y^b / B(a, b)] exp(b log(l/y) - (b - 1) l/2), with l - y in double-double (l/y = 1 + O(y)), and
|
|
130
138
|
// x^a y^b / B(a, b) = e^-E sqrt(m/(2 pi)), m = ab/(a + b), from the exponent E of Loader's binomial density.
|
|
131
139
|
// M = e^-E_hi sh (1 + δ): sqrt(m/(2 pi)) = sh + sl from m in double-double, and the small factors in δ, applied
|
|
132
|
-
// last, so that each rounds once
|
|
140
|
+
// last, so that each rounds once. For a small b or a huge a, x^a y^b / B(a, b) = c e^(eHi + eLo) from prefactorParts
|
|
141
|
+
// instead (Loader's exponent loses digits there: 2e-14 at pbeta(0.0066, 1.4e-166, 317.19, { lowerTail: false }) and
|
|
142
|
+
// 8e-14 at a = 1e300). In both cases M = e^eHi fac (1 + δ), with facCorr the relative correction of fac
|
|
133
143
|
const dl = ddSub(ld, yd);
|
|
134
144
|
const em = b * Math.log1p((dl[0] + dl[1]) / y) - ((b - 1) / 2) * l;
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
const
|
|
145
|
+
let eHi;
|
|
146
|
+
let eLo;
|
|
147
|
+
let fac;
|
|
148
|
+
let facCorr = 0;
|
|
149
|
+
const parts = prefactorParts(a, b, xd, yd);
|
|
150
|
+
if (parts !== undefined) {
|
|
151
|
+
const [c, es] = parts;
|
|
152
|
+
[eHi, eLo, fac] = [es[0], es[1], c];
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
const { e } = dbinomExponent(a, b, xd, yd);
|
|
156
|
+
const md = ddMul(ddDiv(twoProd(a, b), twoSum(a, b)), INV_2PI);
|
|
157
|
+
const sh = Math.sqrt(md[0]);
|
|
158
|
+
const sq = twoProd(sh, sh);
|
|
159
|
+
[eHi, eLo, fac] = [-e[0], -e[1], sh];
|
|
160
|
+
facCorr = (md[0] - sq[0] - sq[1] + md[1]) / (2 * md[0]);
|
|
161
|
+
}
|
|
162
|
+
const delta = Math.expm1(em + eLo) + facCorr;
|
|
140
163
|
const l2 = (l / 2) * (l / 2);
|
|
141
164
|
const t4 = 4 * T * T;
|
|
142
165
|
let sum;
|
|
@@ -188,11 +211,22 @@ export function betaIncLargeA(a, b, xd, yd, lower, wantLog) {
|
|
|
188
211
|
// rounding of u to a double, which would cost up to ε u times that
|
|
189
212
|
sum *= 1 + uLow * (1 - b / u + 1 / (u * h));
|
|
190
213
|
}
|
|
191
|
-
const mSum = Math.exp(
|
|
214
|
+
const mSum = Math.exp(eHi) * (fac * sum);
|
|
192
215
|
const small = mSum + mSum * delta;
|
|
193
216
|
// (far in the lower tails e^-E underflows; the series of incbet.ts handles them)
|
|
194
|
-
if (!(small >= 1e-290))
|
|
195
|
-
|
|
217
|
+
if (!(small >= 1e-290)) {
|
|
218
|
+
// ... except where x rounds to 1 (y below ε), where neither the series nor the continued fraction of incbet.ts
|
|
219
|
+
// applies (pnbinom(1.6e258, 2.8e-255, { mu: 53.6, lowerTail: false }) was NaN): the log from the factors
|
|
220
|
+
// (δ is not formed: the low part of the exponent, half an ulp of its high part, is no longer small when that is huge)
|
|
221
|
+
if (xd[0] < 1 || !(sum > 0))
|
|
222
|
+
return undefined;
|
|
223
|
+
// (fac sum can underflow where fac is a tiny shape: pbeta(4.2e-24, 2.5e-209, 2e213, { lowerTail: false, logP: true })
|
|
224
|
+
// was -Infinity)
|
|
225
|
+
const lfs = fac * sum > 0 ? Math.log(fac * sum) : Math.log(fac) + Math.log(sum);
|
|
226
|
+
const ls = eHi + (em + eLo) + lfs + Math.log1p(facCorr);
|
|
227
|
+
const v = Math.exp(ls);
|
|
228
|
+
return lower === jSide ? [wantLog ? ls : NaN, v] : [wantLog ? -v : NaN, 1 - v];
|
|
229
|
+
}
|
|
196
230
|
// The J side is I_x(a, b)
|
|
197
231
|
if (lower === jSide)
|
|
198
232
|
return [wantLog ? Math.log(small) : NaN, small];
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type DD } from "./dd.js";
|
|
2
|
+
/**
|
|
3
|
+
* Below this smaller shape the prefactor is formed by the small-shape form of prefactorParts. Loader's stirlerr of a
|
|
4
|
+
* shape s < 1 is lgamma1p(s) - (s + 1/2) log s + ..., whose rounding (absolute, about ε |log s| / 2) cancels against the
|
|
5
|
+
* log of the denominator: the prefactor was off by 2e-15 to 1e-14 relative for shapes from 1e-8 to 1e-30 (2e-14 at
|
|
6
|
+
* 1e-130: pbeta(1.08e-285, 1.56e-130, 2) was 1.0000000000000195). Against mpmath, the small-shape form was within 4e-16
|
|
7
|
+
* for smaller shapes from 1e-30 to 0.3 (Loader's 1.5e-15), and from 0.3 to 1 within 1.3e-15 with an rms error of
|
|
8
|
+
* 2.6e-16 (Loader's 1.1e-15 and 3.8e-16); from 1 on Loader's form is the better one where both shapes grow. Up to 1
|
|
9
|
+
* rather than 0.3: tails of a moderate shape from both forms disagreed by 1.6e-15 (pnbinom(0, 0.818, { prob: 0.0821 })
|
|
10
|
+
* and its upper tail), enough to move qnbinom of that upper tail to 1
|
|
11
|
+
*/
|
|
12
|
+
export declare const SMALL_SHAPE = 1;
|
|
13
|
+
/**
|
|
14
|
+
* From this larger shape on (with the smaller one at most HUGE_SHAPE_MAX_SMALL), the huge-shape form of
|
|
15
|
+
* prefactorParts. Loader's form was off by up to 2e-14 relative from 1e15 on and 8e-14 near 1e300 (against mpmath, the
|
|
16
|
+
* smaller shape from 1e-3 to 40 and 1 - x around it divided by the larger: pbeta(5.6e-161, 0.82, 1.5e160) and its
|
|
17
|
+
* upper tail added up to 1 + 3e-14); the huge-shape form stayed within 3.4e-15 from 1e15 on (the rounding of Γ(s)),
|
|
18
|
+
* but neglects terms of order s³/l² (see lgammaRatioHuge), which matter below about 1e10
|
|
19
|
+
*/
|
|
20
|
+
export declare const HUGE_SHAPE: number;
|
|
21
|
+
/** Largest smaller shape for the huge-shape form (Γ(s) is finite and accurate to a few ulps up to there) */
|
|
22
|
+
export declare const HUGE_SHAPE_MAX_SMALL = 100;
|
|
23
|
+
/**
|
|
24
|
+
* x^a (1-x)^b / B(a, b) = c exp(e) as [c, e] (e in double-double) where Loader's form loses digits: for
|
|
25
|
+
* min(a, b) < SMALL_SHAPE, or max(a, b) >= HUGE_SHAPE with min(a, b) <= HUGE_SHAPE_MAX_SMALL; undefined elsewhere.
|
|
26
|
+
* With s = min(a, b), l = max(a, b):
|
|
27
|
+
* - small shape: 1/B(a, b) = ab/(a + b) Γ(1+a+b)/(Γ(1+a) Γ(1+b)), c = ab/(a + b) = s/(1 + s/l) (no underflow of the
|
|
28
|
+
* product ab), and the log of the ratio of gamma functions from smallShapeG, of the size of s log l or less
|
|
29
|
+
* - huge shape: 1/B(a, b) = Γ(l + s)/(Γ(l) Γ(s)), c = 1/Γ(s), and log Γ(l + s) - log Γ(l) from lgammaRatioHuge
|
|
30
|
+
* a log x and b log(1-x) are formed in double-double (b log(1-x) can be large), each logarithm from the smaller of x and
|
|
31
|
+
* 1 - x: x may have rounded to 1 even in double-double (pf(2.5e-97, 1.7e80, 2.7e-95) passes 1 - x = 6.3e-79 with
|
|
32
|
+
* x = [1, 0]), and a log x, about -a (1 - x), then still matters for a huge a
|
|
33
|
+
*/
|
|
34
|
+
export declare function prefactorParts(a: number, b: number, x: DD, xc: DD): [number, DD] | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* log Γ(l + s) - log Γ(l) in double-double for l >= HUGE_SHAPE and s <= HUGE_SHAPE_MAX_SMALL. From Stirling's series,
|
|
37
|
+
* log Γ(l + s) - log Γ(l) = s log l + [(l + s - 1/2) log1p(s/l) - s] + [stirlerr(l + s) - stirlerr(l)]
|
|
38
|
+
* = s log l + s (s - 1) / (2 l) + O(s³/l²)
|
|
39
|
+
* (the stirlerr terms differ by about -s/(12 l²)); the neglected terms are below 1e-25 here. s log l is formed in
|
|
40
|
+
* double-double. lgammaDiff loses s itself where s/l underflows (it forms (l - 1/2) log1p(s/l) - s, which is then -s, not
|
|
41
|
+
* about 0): pbeta(2.2e-292, 2.4e-69, 4.5e290, { lowerTail: false }) was 6.87e-69, 4.44e-69 expected
|
|
42
|
+
*/
|
|
43
|
+
export declare function lgammaRatioHuge(s: number, l: number): DD;
|
|
44
|
+
/**
|
|
45
|
+
* log Γ(1+a+b)/(Γ(1+a) Γ(1+b)) for min(a, b) < SMALL_SHAPE (see prefactorParts), with s = min(a, b), l = max(a, b), as
|
|
46
|
+
* [lgamma(1+l+s) - lgamma(1+l)] - lgamma1p(s), or for l >= 1 with Γ(1+s+l)/Γ(1+l) = (s + l)/l Γ(s+l)/Γ(l). Each term
|
|
47
|
+
* is of the size of s (log l) and accurate relative to that: the result is about s (ψ(1+l) + γ), and where it decides
|
|
48
|
+
* 1 - I_x(a, b) = -expm1(...) it must be (with lgamma1p(a + b) for the first term, a + b dropped s at s = 5.9e-87,
|
|
49
|
+
* b = 0.0845, and pf(1e300, 0.169, 1.18e-86) came out 1.5e-4 too large). For l >= HUGE_SHAPE, lgamma(s+l) - lgamma(l)
|
|
50
|
+
* from lgammaRatioHuge (lgammaDiff loses s where s/l underflows)
|
|
51
|
+
*/
|
|
52
|
+
export declare function smallShapeG(a: number, b: number): DD;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// The factor x^a (1-x)^b / B(a, b) in front of the series, continued fractions and expansions of the incomplete beta
|
|
2
|
+
// function (incbet.ts, incbetLargeA.ts) where Loader's binomial form (loader.ts), used elsewhere, loses digits: when one
|
|
3
|
+
// shape is small, or one is huge and the other moderate. Derived from Γ(1 + s) = s Γ(s) and Stirling's series.
|
|
4
|
+
import { ddAdd, ddLog, ddMulNum, ddNeg, ddSub } from "./dd.js";
|
|
5
|
+
import { gamma, lgamma1p } from "./gamma.js";
|
|
6
|
+
import { lgammaDiff, lgammaDiffDD } from "./lgammaDiff.js";
|
|
7
|
+
/**
|
|
8
|
+
* Below this smaller shape the prefactor is formed by the small-shape form of prefactorParts. Loader's stirlerr of a
|
|
9
|
+
* shape s < 1 is lgamma1p(s) - (s + 1/2) log s + ..., whose rounding (absolute, about ε |log s| / 2) cancels against the
|
|
10
|
+
* log of the denominator: the prefactor was off by 2e-15 to 1e-14 relative for shapes from 1e-8 to 1e-30 (2e-14 at
|
|
11
|
+
* 1e-130: pbeta(1.08e-285, 1.56e-130, 2) was 1.0000000000000195). Against mpmath, the small-shape form was within 4e-16
|
|
12
|
+
* for smaller shapes from 1e-30 to 0.3 (Loader's 1.5e-15), and from 0.3 to 1 within 1.3e-15 with an rms error of
|
|
13
|
+
* 2.6e-16 (Loader's 1.1e-15 and 3.8e-16); from 1 on Loader's form is the better one where both shapes grow. Up to 1
|
|
14
|
+
* rather than 0.3: tails of a moderate shape from both forms disagreed by 1.6e-15 (pnbinom(0, 0.818, { prob: 0.0821 })
|
|
15
|
+
* and its upper tail), enough to move qnbinom of that upper tail to 1
|
|
16
|
+
*/
|
|
17
|
+
export const SMALL_SHAPE = 1;
|
|
18
|
+
/**
|
|
19
|
+
* From this larger shape on (with the smaller one at most HUGE_SHAPE_MAX_SMALL), the huge-shape form of
|
|
20
|
+
* prefactorParts. Loader's form was off by up to 2e-14 relative from 1e15 on and 8e-14 near 1e300 (against mpmath, the
|
|
21
|
+
* smaller shape from 1e-3 to 40 and 1 - x around it divided by the larger: pbeta(5.6e-161, 0.82, 1.5e160) and its
|
|
22
|
+
* upper tail added up to 1 + 3e-14); the huge-shape form stayed within 3.4e-15 from 1e15 on (the rounding of Γ(s)),
|
|
23
|
+
* but neglects terms of order s³/l² (see lgammaRatioHuge), which matter below about 1e10
|
|
24
|
+
*/
|
|
25
|
+
export const HUGE_SHAPE = 2 ** 52;
|
|
26
|
+
/** Largest smaller shape for the huge-shape form (Γ(s) is finite and accurate to a few ulps up to there) */
|
|
27
|
+
export const HUGE_SHAPE_MAX_SMALL = 100;
|
|
28
|
+
/**
|
|
29
|
+
* x^a (1-x)^b / B(a, b) = c exp(e) as [c, e] (e in double-double) where Loader's form loses digits: for
|
|
30
|
+
* min(a, b) < SMALL_SHAPE, or max(a, b) >= HUGE_SHAPE with min(a, b) <= HUGE_SHAPE_MAX_SMALL; undefined elsewhere.
|
|
31
|
+
* With s = min(a, b), l = max(a, b):
|
|
32
|
+
* - small shape: 1/B(a, b) = ab/(a + b) Γ(1+a+b)/(Γ(1+a) Γ(1+b)), c = ab/(a + b) = s/(1 + s/l) (no underflow of the
|
|
33
|
+
* product ab), and the log of the ratio of gamma functions from smallShapeG, of the size of s log l or less
|
|
34
|
+
* - huge shape: 1/B(a, b) = Γ(l + s)/(Γ(l) Γ(s)), c = 1/Γ(s), and log Γ(l + s) - log Γ(l) from lgammaRatioHuge
|
|
35
|
+
* a log x and b log(1-x) are formed in double-double (b log(1-x) can be large), each logarithm from the smaller of x and
|
|
36
|
+
* 1 - x: x may have rounded to 1 even in double-double (pf(2.5e-97, 1.7e80, 2.7e-95) passes 1 - x = 6.3e-79 with
|
|
37
|
+
* x = [1, 0]), and a log x, about -a (1 - x), then still matters for a huge a
|
|
38
|
+
*/
|
|
39
|
+
export function prefactorParts(a, b, x, xc) {
|
|
40
|
+
const s = Math.min(a, b);
|
|
41
|
+
const l = Math.max(a, b);
|
|
42
|
+
let c;
|
|
43
|
+
let g;
|
|
44
|
+
if (s < SMALL_SHAPE) {
|
|
45
|
+
c = s / (1 + s / l);
|
|
46
|
+
g = smallShapeG(a, b);
|
|
47
|
+
}
|
|
48
|
+
else if (l >= HUGE_SHAPE && s <= HUGE_SHAPE_MAX_SMALL) {
|
|
49
|
+
c = 1 / gamma(s);
|
|
50
|
+
g = lgammaRatioHuge(s, l);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
const lx = x[0] <= 0.5 ? ddLog(x) : log1m(xc);
|
|
56
|
+
const lxc = xc[0] <= 0.5 ? ddLog(xc) : log1m(x);
|
|
57
|
+
return [c, ddAdd(ddAdd(mulBig(lx, a), mulBig(lxc, b)), g)];
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* log Γ(l + s) - log Γ(l) in double-double for l >= HUGE_SHAPE and s <= HUGE_SHAPE_MAX_SMALL. From Stirling's series,
|
|
61
|
+
* log Γ(l + s) - log Γ(l) = s log l + [(l + s - 1/2) log1p(s/l) - s] + [stirlerr(l + s) - stirlerr(l)]
|
|
62
|
+
* = s log l + s (s - 1) / (2 l) + O(s³/l²)
|
|
63
|
+
* (the stirlerr terms differ by about -s/(12 l²)); the neglected terms are below 1e-25 here. s log l is formed in
|
|
64
|
+
* double-double. lgammaDiff loses s itself where s/l underflows (it forms (l - 1/2) log1p(s/l) - s, which is then -s, not
|
|
65
|
+
* about 0): pbeta(2.2e-292, 2.4e-69, 4.5e290, { lowerTail: false }) was 6.87e-69, 4.44e-69 expected
|
|
66
|
+
*/
|
|
67
|
+
export function lgammaRatioHuge(s, l) {
|
|
68
|
+
return ddAdd(mulBig(ddLog([l, 0]), s), [(s * (s - 1)) / (2 * l), 0]);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* log Γ(1+a+b)/(Γ(1+a) Γ(1+b)) for min(a, b) < SMALL_SHAPE (see prefactorParts), with s = min(a, b), l = max(a, b), as
|
|
72
|
+
* [lgamma(1+l+s) - lgamma(1+l)] - lgamma1p(s), or for l >= 1 with Γ(1+s+l)/Γ(1+l) = (s + l)/l Γ(s+l)/Γ(l). Each term
|
|
73
|
+
* is of the size of s (log l) and accurate relative to that: the result is about s (ψ(1+l) + γ), and where it decides
|
|
74
|
+
* 1 - I_x(a, b) = -expm1(...) it must be (with lgamma1p(a + b) for the first term, a + b dropped s at s = 5.9e-87,
|
|
75
|
+
* b = 0.0845, and pf(1e300, 0.169, 1.18e-86) came out 1.5e-4 too large). For l >= HUGE_SHAPE, lgamma(s+l) - lgamma(l)
|
|
76
|
+
* from lgammaRatioHuge (lgammaDiff loses s where s/l underflows)
|
|
77
|
+
*/
|
|
78
|
+
export function smallShapeG(a, b) {
|
|
79
|
+
const s = Math.min(a, b);
|
|
80
|
+
const l = Math.max(a, b);
|
|
81
|
+
if (l < 1)
|
|
82
|
+
return [lgammaDiff(s, 1 + l) - lgamma1p(s), 0];
|
|
83
|
+
return ddAdd(l >= HUGE_SHAPE ? lgammaRatioHuge(s, l) : lgammaDiffDD(s, l), [Math.log1p(s / l) - lgamma1p(s), 0]);
|
|
84
|
+
}
|
|
85
|
+
/** log(1 - y) in double-double (0 <= y <= 1/2); below 1e-15, -(y + y^2/2) (the next term is below 1e-30 relative) */
|
|
86
|
+
function log1m(y) {
|
|
87
|
+
return y[0] < 1e-15 ? ddNeg(ddAdd(y, [(y[0] * y[0]) / 2, 0])) : ddLog(ddSub([1, 0], y));
|
|
88
|
+
}
|
|
89
|
+
/** x a in double-double, also for a above 1e290 (where the splitting of a in ddMulNum would overflow) */
|
|
90
|
+
function mulBig(x, a) {
|
|
91
|
+
return a > 1e290 ? ddMulNum(ddMulNum(x, a / 2 ** 64), 2 ** 64) : ddMulNum(x, a);
|
|
92
|
+
}
|
|
@@ -153,6 +153,16 @@ function erfcxMinusLeading(y) {
|
|
|
153
153
|
t = (-k * (k + 0.5)) / (z + 2 * k + 1.5 + t);
|
|
154
154
|
return -1 / (4 * SQRT_PI * y * (z + 1.5 + t));
|
|
155
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* r x in double-double for r up to the largest double: above 1e299 the splitting in the product overflows, so r is
|
|
158
|
+
* scaled by 2^-64 (exactly) and the product back (pbeta(0.5, 6e299, 6e299) was Infinity)
|
|
159
|
+
*/
|
|
160
|
+
function mulLarge(r, x) {
|
|
161
|
+
if (!(r[0] > 1e299))
|
|
162
|
+
return ddMul(r, x);
|
|
163
|
+
const p = ddMul([r[0] * 2 ** -64, r[1] * 2 ** -64], x);
|
|
164
|
+
return [p[0] * 2 ** 64, p[1] * 2 ** 64];
|
|
165
|
+
}
|
|
156
166
|
/**
|
|
157
167
|
* I_x(a, b) (lower) or 1 - I_x(a, b) by the uniform asymptotic expansion, as [log, linear] (log NaN unless
|
|
158
168
|
* wantLog). x and 1 - x are given in double-double. Returns undefined outside the region where the expansion is
|
|
@@ -161,7 +171,9 @@ function erfcxMinusLeading(y) {
|
|
|
161
171
|
export function betaIncTemme(a, b, xd, xcd, lower, wantLog) {
|
|
162
172
|
const rr = twoSum(a, b);
|
|
163
173
|
const r = rr[0];
|
|
164
|
-
|
|
174
|
+
// (a b overflows beyond 1.8e308: then a (b / r))
|
|
175
|
+
const ab = a * b;
|
|
176
|
+
const m = Number.isFinite(ab) ? ab / r : a * (b / r);
|
|
165
177
|
if (!(m >= TEMME_MIN_M) || !Number.isFinite(r))
|
|
166
178
|
return undefined;
|
|
167
179
|
const p = a / r;
|
|
@@ -172,11 +184,11 @@ export function betaIncTemme(a, b, xd, xcd, lower, wantLog) {
|
|
|
172
184
|
if (Math.abs(x - p) > 2 * pq)
|
|
173
185
|
return undefined;
|
|
174
186
|
// r x - a exactly enough (sign of x - p, and g_0 in the tail form)
|
|
175
|
-
const rx =
|
|
187
|
+
const rx = mulLarge(rr, xd);
|
|
176
188
|
const dx = ddSub(rx, [a, 0]);
|
|
177
189
|
const d = dx[0] + dx[1];
|
|
178
190
|
// E = bd0(a, r x) + bd0(b, r (1 - x)) in double-double
|
|
179
|
-
const e = ddAdd(bd0dd(a, rx), bd0dd(b,
|
|
191
|
+
const e = ddAdd(bd0dd(a, rx), bd0dd(b, mulLarge(rr, xcd)));
|
|
180
192
|
const E = e[0] + e[1];
|
|
181
193
|
const tau2 = (2 * E) / m;
|
|
182
194
|
if (!(tau2 <= TAU_MAX * TAU_MAX))
|
package/dist/special/loader.js
CHANGED
|
@@ -70,6 +70,13 @@ const TAIL_IN_DOUBLE = 0.12;
|
|
|
70
70
|
* When x and M are close, it is computed by the series in v = (x - M)/(x + M) (Loader 2000).
|
|
71
71
|
*/
|
|
72
72
|
export function bd0dd(x, M) {
|
|
73
|
+
// bd0 is homogeneous of degree 1: from about 1e300 the splitting in the double-double products overflows (x + M
|
|
74
|
+
// enters them), so scale x and M by 2^-64 (exactly, unless the smaller one would become subnormal; its quotient is
|
|
75
|
+
// then far out and the logarithms are taken separately below) and the result back (pgamma(9.9e299, 1e300) was NaN)
|
|
76
|
+
if (Math.max(x, M[0]) > 1e299 && Math.min(x, M[0]) > 1e-250) {
|
|
77
|
+
const r = bd0dd(x * 2 ** -64, [M[0] * 2 ** -64, M[1] * 2 ** -64]);
|
|
78
|
+
return [r[0] * 2 ** 64, r[1] * 2 ** 64];
|
|
79
|
+
}
|
|
73
80
|
if (!isDoubleDouble())
|
|
74
81
|
return bd0ddOps(x, M);
|
|
75
82
|
// d = x - M and the series expand the same operations as bd0ddOps below, in the same order, without allocating arrays
|
|
@@ -342,9 +349,10 @@ export function bd0dd(x, M) {
|
|
|
342
349
|
return [sh, sl];
|
|
343
350
|
}
|
|
344
351
|
// x log(x/M) + (M - x), with log(x/M) from the double-double quotient (one logarithm instead of two) unless the
|
|
345
|
-
// quotient leaves the normal range, where its low part would be lost
|
|
352
|
+
// quotient leaves the normal range, where its low part would be lost, or x or M is above 1e300, where the splitting
|
|
353
|
+
// of the double-double division overflows (dgamma(9.3e281, 1.9e183, { rate: 3e21 }) threw a TypeError)
|
|
346
354
|
const ratio = x / M[0];
|
|
347
|
-
const lr = ratio > 1e-290 && ratio < 1e290 ? ddLog(ddDiv([x, 0], M)) : ddSub(ddLog([x, 0]), ddLog(M));
|
|
355
|
+
const lr = ratio > 1e-290 && ratio < 1e290 && Math.max(x, M[0]) < 1e300 ? ddLog(ddDiv([x, 0], M)) : ddSub(ddLog([x, 0]), ddLog(M));
|
|
348
356
|
return ddAdd(ddMulNum(lr, x), [-dh, -dl]);
|
|
349
357
|
}
|
|
350
358
|
/** bd0dd written with calls to the double-double helpers (used when evaluating in double-precision mode; see src/special/dd.ts) */
|
|
@@ -367,9 +375,24 @@ function bd0ddOps(x, M) {
|
|
|
367
375
|
}
|
|
368
376
|
// x log(x/M) + (M - x)
|
|
369
377
|
const ratio = x / M[0];
|
|
370
|
-
const lr = ratio > 1e-290 && ratio < 1e290 ? ddLog(ddDiv([x, 0], M)) : ddSub(ddLog([x, 0]), ddLog(M));
|
|
378
|
+
const lr = ratio > 1e-290 && ratio < 1e290 && Math.max(x, M[0]) < 1e300 ? ddLog(ddDiv([x, 0], M)) : ddSub(ddLog([x, 0]), ddLog(M));
|
|
371
379
|
return ddAdd(ddMulNum(lr, x), ddNeg(d));
|
|
372
380
|
}
|
|
381
|
+
/**
|
|
382
|
+
* bd0(x, n p) with n and p in double-double. Above 1e299 the splitting in the double-double product overflows, so n is
|
|
383
|
+
* scaled by 2^-64 there (exactly) and the product back. Where n p is not a normal number well inside the range (below
|
|
384
|
+
* 1e-290, down to 0 by underflow, as with tiny shapes: pbeta(5.8e-295, 2.8e-193, 3.5e-153) threw a TypeError), its
|
|
385
|
+
* logarithm is taken as log n + log p
|
|
386
|
+
*/
|
|
387
|
+
function bd0Prod(x, nn, p) {
|
|
388
|
+
const s = nn[0] > 1e299 ? 2 ** -64 : 1;
|
|
389
|
+
const ms = ddMul([nn[0] * s, nn[1] * s], p);
|
|
390
|
+
const M = [ms[0] / s, ms[1] / s];
|
|
391
|
+
if (M[0] >= 1e-290)
|
|
392
|
+
return bd0dd(x, M);
|
|
393
|
+
const lr = ddSub(ddLog([x, 0]), ddAdd(ddLog(nn), ddLog(p)));
|
|
394
|
+
return ddAdd(ddMulNum(lr, x), twoSum(nn[0] * p[0], -x));
|
|
395
|
+
}
|
|
373
396
|
/** Double-precision version of bd0 */
|
|
374
397
|
export function bd0(x, M) {
|
|
375
398
|
if (!Number.isFinite(x) || !Number.isFinite(M) || M === 0)
|
|
@@ -385,6 +408,9 @@ function expNegDD(e, log, logDenom, denom) {
|
|
|
385
408
|
return -e[0] - e[1] - 0.5 * logDenom();
|
|
386
409
|
if (e[0] < 700)
|
|
387
410
|
return (Math.exp(-e[0]) * (1 - e[1])) / Math.sqrt(denom());
|
|
411
|
+
// Far below the subnormals; e[1] can then exceed 1 (it is up to half an ulp of e[0]) and 1 - e[1] would give -0
|
|
412
|
+
if (e[0] > 2000)
|
|
413
|
+
return 0;
|
|
388
414
|
// Region where the result is near subnormal: multiply by exp(-700) last so that rounding happens once, at the end
|
|
389
415
|
const d = denom();
|
|
390
416
|
if (!Number.isFinite(d) || d === 0)
|
|
@@ -425,7 +451,7 @@ export function dbinomRawDD(x, nmx, p, q, log) {
|
|
|
425
451
|
return one;
|
|
426
452
|
if (p[0] < 0.1) {
|
|
427
453
|
// n log q = -bd0(n, n q) - n p
|
|
428
|
-
const e = ddAdd(
|
|
454
|
+
const e = ddAdd(bd0Prod(n, nn, q), ddMul(nn, p));
|
|
429
455
|
return log ? -e[0] - e[1] : Math.exp(-e[0]) * (1 - e[1]);
|
|
430
456
|
}
|
|
431
457
|
const lq = ddLog(q);
|
|
@@ -434,7 +460,7 @@ export function dbinomRawDD(x, nmx, p, q, log) {
|
|
|
434
460
|
}
|
|
435
461
|
if (nmx === 0) {
|
|
436
462
|
if (q[0] < 0.1) {
|
|
437
|
-
const e = ddAdd(
|
|
463
|
+
const e = ddAdd(bd0Prod(n, nn, p), ddMul(nn, q));
|
|
438
464
|
return log ? -e[0] - e[1] : Math.exp(-e[0]) * (1 - e[1]);
|
|
439
465
|
}
|
|
440
466
|
const lc = ddMul(nn, ddLog(p));
|
|
@@ -443,7 +469,7 @@ export function dbinomRawDD(x, nmx, p, q, log) {
|
|
|
443
469
|
if (x < 0 || nmx < 0)
|
|
444
470
|
return zero;
|
|
445
471
|
// E = stirlerr(x) + stirlerr(n-x) - stirlerr(n) + bd0(x, np) + bd0(n-x, nq)
|
|
446
|
-
let e = ddAdd(
|
|
472
|
+
let e = ddAdd(bd0Prod(x, nn, p), bd0Prod(nmx, nn, q));
|
|
447
473
|
e = ddAdd(e, twoSum(stirlerr(x) + stirlerr(nmx), -stirlerr(n)));
|
|
448
474
|
// Denominator 2 pi x (n - x) / n
|
|
449
475
|
return expNegDD(e, log, () => LN_2PI + Math.log(x) + Math.log(nmx) - Math.log(n), () => 2 * Math.PI * x * (nmx / n));
|
|
@@ -455,7 +481,7 @@ export function dbinomRawDD(x, nmx, p, q, log) {
|
|
|
455
481
|
export function dbinomExponent(x, nmx, p, q) {
|
|
456
482
|
const nn = twoSum(x, nmx);
|
|
457
483
|
const n = nn[0];
|
|
458
|
-
let e = ddAdd(
|
|
484
|
+
let e = ddAdd(bd0Prod(x, nn, p), bd0Prod(nmx, nn, q));
|
|
459
485
|
e = ddAdd(e, twoSum(stirlerr(x) + stirlerr(nmx), -stirlerr(n)));
|
|
460
486
|
return { e, logDenom: LN_2PI + Math.log(x) + Math.log(nmx) - Math.log(n) };
|
|
461
487
|
}
|
package/dist/special.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! rStats.js 0.15.
|
|
2
|
-
import{a as wt,b as Lt,c as _t,d as Et}from"./chunks/chunk-PRDF6IU6.js";import{c as G,d as St,e as jt,j as ht}from"./chunks/chunk-LU5FHU2O.js";import{A as v,C as Dt,D as Ft,b as $,c as qt,h as ft,k as d,l as q,m as U,n as _,o as C,p as Z,q as ct,u as z,v as lt,w as mt,y as ut}from"./chunks/chunk-CMPDE3SZ.js";import{b as E,d as j,f as T,g as J,h as at,i as O,k as L}from"./chunks/chunk-4EOKNOXP.js";var Mt=22250738585072014e-324;function W(t,e,n){if(t<10)return Math.pow(e/2,t)/q(t+1)*n;let s=e/2,r=z(t,s,!1);if(r>=Mt&&s<700){let a=r*Math.exp(s)*n;if(Math.abs(a)>=Mt)return a}let o=z(t,s,!0)+s+Math.log(Math.abs(n));return Math.sign(n)*Math.exp(o)}var D=Number.EPSILON,H=1e6;function pt(t){return Math.expm1(C(t))}function Tt(t,e){let n=pt(t),s=pt(-t),r=Math.log(e/2),o=Math.exp(t*r),a=-r*t,i=Math.abs(t)<D?1:d(t)/(t*Math.PI),c=Math.abs(a)<D?1:Math.sinh(a)/a,l=Math.abs(t)<D?-.5772156649015329:.5/t*(n-s)*i,f=(2+n+s)*i/2,m=(n+1)/(2*o),u=(1+s)*o/2,M=(Math.cosh(a)*l+c*-r*f)/i,p=m,h=1,S=h*M,k=h*p;for(let I=1;I<H&&(M=(I*M+m+u)/(I*I-t*t),m/=I-t,u/=I+t,p=m-I*M,h*=e*e/(4*I),S+=h*M,k+=h*p,!(Math.abs(h*M)<Math.abs(S)*D));I++);return[S,2*k/e]}function At(t,e){let n=Math.sqrt(Number.MIN_VALUE*4503599627370496),s=n,r=n,o=0;for(let a=1;a<H;a++){let i=2*(t+a)/e;s=i+1/s,o=i+o,s===0&&(s=n),o===0&&(o=n),o=1/o;let c=s*o;if(r*=c,Math.abs(c-1)<=2*D)break}return r}function Jt(t,e){let n=t*t-.25,s=2*(e+1),r=1/s,o=r,a=r,i=0,c=1,l=-n,f=l,m=1+f*a;for(let p=2;p<H;p++){n-=2*(p-1),s+=2,r=1/(s+n*r),a*=s*r-1,o+=a;let h=(i-(s-2)*c)/n;if(i=c,c=h,l*=-n/p,f+=l*h,m+=f*a,h<D&&(l*=h,i/=h,c/=h),Math.abs(f*a)<Math.abs(m)*D)break}let u=(.5+t+e+(t*t-.25)*o)/e,M=Math.sqrt(Math.PI/(2*e))/m;return[M,M*u]}function V(t,e){if(!Number.isFinite(e))return e>0?t*(1/0):t*0;for(;e>1e3;)t*=2**1e3,e-=1e3;for(;e<-1e3;)t*=2**-1e3,e+=1e3;return t*2**e}function bt(t,e){let n=Math.round(t),s=t-n,r,o;if(s===-.5)r=o=Math.sqrt(Math.PI/(2*e));else if(e<=2){let[i,c]=Tt(s,e),l=Math.exp(e);r=i*l,o=c*l}else[r,o]=Jt(s,e);let a=0;for(let i=1;i<=n;i++){let c=2*(s+i)/e,l=Math.log2(Math.abs(o))+Math.log2(c);if(l>900&&Number.isFinite(l)){let m=Math.ceil(l-800);r=V(r,-m),o=V(o,-m),a+=m}let f=c*o+r;r=o,o=f}return{k:r,k1:o,exp2:a}}function Kt(t,e){let n=e*e/4,s=1,r=0;for(let o=1;o<H&&(r+=s,s*=n/o,s/=o+t,!(Math.abs(s)<=D*Math.abs(r)));o++);return W(t,e,r+s)}function Rt(t,e,n){if(t===0||!Number.isFinite(t))return t;let s=t,r=e,o=n>0?700:-700,a=Math.exp(o);for(;Math.abs(n)>700;){n-=o,s*=a;let i=Math.floor(Math.log2(Math.abs(s)));s=V(s,-i),r+=i}return V(s*Math.exp(n),r)}function x(t,e,n){let s=t.ex+n;return s===0?V(t.m,t.e2):Rt(t.m,t.e2,s*e)}function Yt(t,e){if(t===.5)return{m:Math.sqrt(2/(e*Math.PI))*(-Math.expm1(-2*e)/2),e2:0,ex:1};if(t>0&&e/t<.25)return{m:Kt(t,e),e2:0,ex:0};let n=(4*t*t+10)/(8*e);if(n*=n,n*=n,n/=24,n<D*10&&e>100){let i=4*t*t,c=8*e,l=i-1,f=c,m=1-l/f;return l*=i-9,f*=c*2,m+=l/f,l*=i-25,f*=c*3,m-=l/f,{m:m/Math.sqrt(2*e*Math.PI),e2:0,ex:1}}let{k:s,k1:r,exp2:o}=bt(t,e),a=At(t,e);return{m:1/(e*(s*a+r)),e2:-o,ex:1}}function Nt(t,e){let n=4*t*t,s=8*e,r=(n-1)/s,o=r*(n-9)/(2*s),a=o*(n-25)/(3*s),i=a*(n-49)/(4*s),c=1+r+o+a;if(Math.abs(i)<D*Math.abs(c))return{m:c*Math.sqrt(Math.PI)/Math.sqrt(2*e),e2:0,ex:-1};let{k:l,exp2:f}=bt(t,e);return{m:l,e2:f,ex:-1}}function Ct(t,e,n={}){let s=n.exponScaled??!1;if(Number.isNaN(t)||Number.isNaN(e)||t<0||!Number.isFinite(e))return NaN;let r=Math.abs(e),o=e<0&&e!==Math.floor(e);if(t===0)return o?d(r)>0?1/0:-1/0:e===0?1:0;if(t===1/0)return s?0:1/0;let a=s?-1:0,i=x(Yt(r,t),t,a);if(!o)return i;let c=Nt(r,t);return i+x({...c,m:2/Math.PI*d(r)*c.m},t,a)}function Qt(t,e,n={}){let s=n.exponScaled??!1;if(Number.isNaN(t)||Number.isNaN(e)||t<0||!Number.isFinite(e))return NaN;let r=Math.abs(e);return t===0?1/0:t===1/0?0:x(Nt(r,t),t,s?1:0)}var y=Number.EPSILON;function A(t,e){if(!Number.isFinite(e))return e>0?t*(1/0):t*0;for(;e>1e3;)t*=2**1e3,e-=1e3;for(;e<-1e3;)t*=2**-1e3,e+=1e3;return t*2**e}function gt(t,e,n,s,r){let o=s,a=r,i=0;for(let c=1;c<=n;c++){let l=2*(t+c)/e,f=Math.log2(Math.abs(a))+Math.log2(l);if(f>900&&Number.isFinite(f)){let u=Math.ceil(f-800);o=A(o,-u),a=A(a,-u),i+=u}let m=l*a-o;o=a,a=m}return{y:o,y1:a,e2:i}}var K=1e6,g=Math.sqrt(22250738585072014e-324),Ut=Number.MAX_VALUE;function It(t){return Math.expm1(C(t))}function Q(t){return d(.5-Math.abs(t%2))}function dt(t,e){let n=-(e/2)*(e/2),s=1,r=0;for(let o=1;o<K&&(r+=s,s*=n/(o*(o+t)),!(Math.abs(s)<=y*Math.abs(r)));o++);return W(t,e,r+s)}function Vt(t,e){let n=Math.log(e/2),s=0,r=t>=170||709.78/t<Math.abs(n),o;if(r){let u=_(t);if(n=t*n,o=u-Math.log(Math.PI)-n,709.78<o){let M=Math.ceil((o-700)/Math.LN2);o-=M*Math.LN2,s=M}o=-Math.exp(o)}else{let u=q(t);n=Math.pow(e/2,t),Ut*n<u&&(u*=2**-1e3,s=1e3),o=-u/(Math.PI*n)}let a=-(e/2)*(e/2),i=1,c=0;for(let u=1;u<K&&(c+=i,i*=a/(u*(u-t)),!(Math.abs(i)<=y*Math.abs(c)));u++);let l=(c+i)*o,f;if(!r)f=q(-t)*Q(t)*n/Math.PI;else{let u=U(-t);f=Math.exp(u.value+n)*u.sign/Math.PI}i=1;let m=0;for(let u=1;u<K&&(m+=i,i*=a/(u*(u+t)),!(Math.abs(i)<=y*Math.abs(m)));u++);return m+=i,l-=A(f*m,-s),{m:l,e2:s}}function Xt(t,e){let n=1,s=0,r=1,o=8*e,a=1,i=4*t*t,c=1,l=!0;do{c*=(i-a*a)/(r*o),s+=c,r+=1,a+=2;let f=(a*a-i)/(r*o);l=Math.abs(f)<.5,c*=f,n+=c,r+=1,a+=2}while(Math.abs(c)>2*y*n&&l);return l?{p:n,q:s}:void 0}function Bt(t,e){let n=It(t),s=It(-t),r=d(t),o=d(t/2),a=Math.pow(e/2,t),i=Math.log(e/2),c=-i*t,l=Math.abs(c)<y?1:Math.sinh(c)/c,f=Math.abs(t)<y?t*Math.PI*Math.PI/2:2*o*o/t,m=t===0?-.5772156649015329:(n-s)/((1+n)*(1+s)*2*t),u=(2+n+s)/((1+n)*(1+s)*2),M=Math.abs(t)<y?1/Math.PI:t/r,p=(m*Math.cosh(c)-u*i*l)*2*M,h=M/(a*(1+s)),S=M*a/(1+n),k=p+f*S,I=h,F=1,R=F*k,X=F*I,B=t*t,b=-e*e/4;for(let N=1;N<K&&(p=(N*p+h+S)/(N*N-B),h/=N-t,S/=N+t,k=p+f*S,I=h-N*k,F*=b/N,R+=F*k,X+=F*I,!(Math.abs(F*k)<Math.abs(R)*y));N++);return[-R,-2*X/e]}function Ot(t,e){let n=[g,0],s=[g,0],r=[0,0],o=1,a=[e,0];for(let i=1;i<K*100;i++){let c=E(t,i),l=O([2*c[0],2*c[1]],a);n=T(l,O([1,0],n)),r=T(l,r),n[0]===0&&(n=[g,0]),r[0]===0&&(r=[g,0]),r=O([1,0],r);let f=J(n,r);if(s=J(s,f),r[0]<0&&(o=-o),Math.abs(f[0]-1+f[1])<y*y)break}return{fv:-(s[0]+s[1]),sign:o}}function yt(t,e){if(e>30)return Ot(t,e);let n=g,s=g,r=0,o=1;for(let a=1;a<K*100;a++){let i=2*(t+a)/e;n=i-1/n,r=i-r,n===0&&(n=g),r===0&&(r=g),r=1/r;let c=n*r;if(s*=c,r<0&&(o=-o),Math.abs(c-1)<2*y)break}return{fv:-s,sign:o}}function Pt(t,e){let n=-.5/e,s=1,r=n,o=s,a=t*t,i=(.25-a)/e,c=2*e,l=2,f=r*r+1;o=l+i*r/f,r=c+i/f;let m=c,u=l;Math.abs(r)+Math.abs(o)<g&&(r=g),Math.abs(m)+Math.abs(u)<g&&(m=g),f=m*m+u*u,m=m/f,u=-u/f;let M=r*m-o*u,p=o*m+r*u;f=n,n=f*M-s*p,s=f*p+s*M;for(let h=2;h<K&&(i=h-.5,i*=i,i-=a,l+=2,f=r*r+o*o,r=c+i*r/f,o=l-i*o/f,m=c+i*m,u=l+i*u,Math.abs(r)+Math.abs(o)<g&&(r=g),Math.abs(m)+Math.abs(u)<g&&(m=g),f=m*m+u*u,m=m/f,u=-u/f,M=r*m-o*u,p=o*m+r*u,f=n,n=f*M-s*p,s=f*p+s*M,!(Math.abs(M-1)+Math.abs(p)<2*y));h++);return{p:n,q:s}}function Zt(t,e){let n=1,s=4*t*t,r=2*e;return r*=r,n+=(s-1)/(2*r),n+=3*(s-1)*(s-9)/(r*r*8),n+=15*(s-1)*(s-9)*(s-25)/(r*r*r*8*6),Math.sqrt(n*2/(Math.PI*e))}function Gt(t,e){let n=4*t*t,s=4*e,r=s*s,o=0;return o+=(n-1)/(2*s),s*=r,o+=(n-1)*(n-25)/(6*s),s*=r,o+=(n-1)*(n*n-114*n+1073)/(5*s),s*=r,o+=(n-1)*(5*n*n*n-1535*n*n+54703*n-375733)/(14*s),o}function Wt(t,e){let n=Zt(t,e),s=Gt(t,e),r=Math.cos(e),o=Math.sin(e),a=Q(t/2+.25),i=d(t/2+.25),c=Math.sin(s),l=Math.cos(s),f=(c*(r*a+o*i)+l*(o*a-r*i))*n;return{j:(l*(r*a+o*i)-c*(o*a-r*i))*n,y:f}}function tt(t,e,n){let s=Math.round(t),r=t-s,o=2/(e*Math.PI);if(!n&&(e<5||t>e*e/4))return{j:dt(t,e),y:{m:NaN,e2:0}};if(e<1&&r!==0&&Math.log(y/2)>t*Math.log(e/2*(e/2)/t))return{j:dt(t,e),y:Vt(t,e)};if(Math.max(t,1)<e*.011048543456039806){let b=Wt(t,e);return{j:b.j,y:{m:b.y,e2:0}}}if(e>8){let b=Xt(t,e);if(b!==void 0){let N=(t/2+.25)%2,P=Math.sin(e),w=Math.cos(e),Y=d(N),rt=Q(N),st=P*rt-Y*w,ot=w*rt+P*Y,it=Math.SQRT2/(Math.sqrt(Math.PI)*Math.sqrt(e));return{j:it*(b.p*ot-b.q*st),y:{m:it*(b.p*st+b.q*ot),e2:0}}}}if(e<=2){let[b,N]=Bt(r,e),P=gt(r,e,s,b,N),{fv:w}=yt(t,e);return{j:A(o/(P.y*w-P.y1),-P.e2),y:{m:P.y,e2:P.e2}}}let{fv:a,sign:i}=yt(t,e);if(e>=t&&t>2){let{p:b,q:N}=Pt(t,e),P=t/e-a,w=(b-P)/N;w===0&&(w=t*y/e);let Y=i*Math.sqrt(o/(N+w*(b-P)));return{j:Y,y:{m:w*Y,e2:0}}}let c=g,l=a*i*c,f=i*c,m=0;for(let b=s;b>0;b--){let N=2*(r+b)/e;Math.abs(f)>2**900&&(l*=2**-900,f*=2**-900,m+=900);let P=N*f-l;P===0&&(P=l*y/2),l=f,f=P}let u=A(i*c/f,-m),M=l/f,{p,q:h}=Pt(r,e),S=r/e-M,k=(p-S)/h;k===0&&(k=r*y/e);let I=Math.sign(f)*Math.sqrt(o/(h+k*(p-S))),F=I*u,R=k*I,X=R*(r/e-p-h/k);if(!n)return{j:F,y:{m:NaN,e2:0}};let B=gt(r,e,s,R,X);return{j:F,y:{m:B.y,e2:B.e2}}}function Ht(t,e){if(Number.isNaN(t)||Number.isNaN(e)||t<0||!Number.isFinite(e))return NaN;let n=Math.abs(e),s=e<0&&e!==Math.floor(e);if(t===0)return e===0?1:s?d(n)>0?1/0:-1/0:0;if(t===1/0)return 0;if(!s){let o=tt(n,t,!1).j;return e<0&&n%2===1?-o:o}let r=tt(n,t,!0);return Q(n)*r.j-A(d(n)*r.y.m,r.y.e2)}function $t(t,e){if(Number.isNaN(t)||Number.isNaN(e)||t<0||!Number.isFinite(e))return NaN;let n=Math.abs(e),s=e<0;if(t===0){if(!s)return-1/0;let i=Q(n);return i===0?0:i>0?-1/0:1/0}if(t===1/0)return 0;let r=tt(n,t,!0);if(!s)return A(r.y.m,r.y.e2);let o=Q(n),a=d(n);return(a!==0?a*r.j:0)+(o===0?0:A(o*r.y.m,r.y.e2))}function zt(t,e){if(Number.isNaN(t)||Number.isNaN(e)||t<0||!(e>0))return{lower:NaN,upper:NaN,logLower:NaN,logUpper:NaN};let n=_(e),s=q(e),r=l=>{let f=v(e,t,l,!1),m=s*f;if(Number.isFinite(s)&&f>kt&&Number.isFinite(m)&&m>kt)return[m,Math.log(m)];let u=n+v(e,t,l,!0);return u<710&&u>-746&&t>0&&(l?t<e:t>e)?vt(t,e,l):[Math.exp(u),u]},[o,a]=r(!0),[i,c]=r(!1);return{lower:o,upper:i,logLower:a,logUpper:c}}var kt=22250738585072014e-324;function vt(t,e,n){let s=j(at(L([t,0]),e),[-t,0]);n?s=j(s,L([mt(e,t)/e,0])):s=j(s,L([ut(e,t),0]));let r=s[0]+s[1];return[s[0]>-708?Math.exp(s[0])*(1+s[1]):Math.exp(r),r]}function et(t){return Number.isNaN(t)||t<0||t>2?NaN:-ft(t/2)*Math.SQRT1_2}function xt(t){if(Number.isNaN(t)||t<-1||t>1)return NaN;let e=t<0?-1:1,n=Math.abs(t);if(n>=.5)return e*et(1-n);if(n<1e-8)return t*.886226925452758*(1+Math.PI/12*t*t);let s=et(1-n);for(let r=0;r<3;r++){let o=($(s)-n)/(1.1283791670955126*Math.exp(-s*s));if(s-=o,Math.abs(o)<=1e-17*s)break}return e*s}function te(t,e){if(Number.isNaN(t)||Number.isNaN(e)||t<0||e<0)return NaN;let n=e===Math.floor(e);return t===Math.floor(t)&&n&&e>t?0:!Number.isFinite(t)||!Number.isFinite(e)?ie(t,e):n&&e<=1e3?ee(t,e):ne(t,e)}function ee(t,e){let n=[1,0];for(let s=0;s<e;s++){let r=E(t,-s),o=n[0]*r[0];if(!Number.isFinite(o)){let a=Math.sign(o);for(let i=s+1;i<e;i++)t-i<0&&(a=-a);return a*(1/0)}n=Math.abs(n[0])>1e290||Math.abs(r[0])>1e290?[(n[0]+n[1])*(r[0]+r[1]),0]:J(n,r)}return n[0]+n[1]}function ne(t,e){let[n,s]=E(t,-e);if(n+1<=0)return re(t,n,s);if(t>1e280)return e*e<1e-17*t?Math.pow(t,e):1/0;let r;if(n>=15){if(e*Math.log(n+1)>720)return 1/0;let o=E(t,-n),a=T(J(o,L([t,0])),ct(n,[t,0]));a=j(a,[Z(t)-Z(n),0]),r=Math.sqrt(t/n)*Math.exp(a[0])*(1+a[1])}else if(t<30)r=q(t+1)/q(n+1);else{if(_(t+1)-_(n+1)>720)return 1/0;let o=T(nt(t+1),L([q(n+1),0]));r=Math.exp(o[0])*(1+o[1])}return s!==0&&Number.isFinite(r)&&r!==0&&(r*=Math.exp(-s*G(n+1))),r}function re(t,e,n){let s=j(E(e,1),[n,0]),r=d(s[0])+d(s[0]+.5)*Math.PI*s[1];if(r===0)return 0;let o=Math.sign(r),a=j(T(L([Math.abs(r),0]),oe),[-n*G(-e),0]);if(_(t+1)+_(-e)+a[0]>720)return o*(1/0);let i=j(j(nt(t+1),nt(-e)),a);return o*Math.exp(i[0])*(1+i[1])}var se=[.9189385332046728,-38782941580672414e-33],oe=[1.1447298858494002,10265951162707826e-33];function nt(t){if(t<15)return L([q(t),0]);let e=T(J(E(t,-.5),L([t,0])),[t,0]);return j(j(e,se),[Z(t),0])}function ie(t,e){let n=U(t+1),s=U(t-e+1);return n.sign*s.sign*Math.exp(n.value-s.value)}function ae(t){return Number.isNaN(t)||t<-1?NaN:t===-1||t===1/0?-1/0:lt(t)}function fe(t){return Number.isNaN(t)||t===-1/0?NaN:t===1/0||t<=-1&&t===Math.floor(t)?1/0:C(t)}function ce(t){return Number.isNaN(t)||t<0?NaN:t===0?-1/0:t===1/0?0:ht(-t)}function le(t){return Number.isNaN(t)?NaN:t<=-37?Math.exp(t):t<=18?Math.log1p(Math.exp(t)):t<=33.3?t+Math.exp(-t):t}export{Ct as besselI,Ht as besselJ,Qt as besselK,$t as besselY,Dt as beta,wt as choose,G as digamma,$ as erf,qt as erfc,et as erfcinv,xt as erfinv,_t as factorial,q as gamma,zt as gammainc,Ft as lbeta,Lt as lchoose,Et as lfactorial,_ as lgamma,fe as lgamma1p,ce as log1mexp,le as log1pexp,ae as log1pmx,te as perm,jt as psigamma,St as trigamma};
|
|
1
|
+
/*! rStats.js 0.15.2 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
|
|
2
|
+
import{a as wt,b as Lt,c as _t,d as Et}from"./chunks/chunk-XPLDEK6D.js";import{f as ht,k as G,l as St,m as jt}from"./chunks/chunk-D4F7GQAY.js";import{A as v,D as Dt,E as Ft,b as $,c as qt,h as ft,k as d,l as q,m as U,n as _,o as C,p as Z,q as ct,u as z,v as lt,w as mt,y as ut}from"./chunks/chunk-2CUKVVRO.js";import{b as E,d as j,f as T,g as J,h as at,i as O,k as L}from"./chunks/chunk-LG74QY5U.js";var Mt=22250738585072014e-324;function W(t,e,n){if(t<10)return Math.pow(e/2,t)/q(t+1)*n;let s=e/2,r=z(t,s,!1);if(r>=Mt&&s<700){let a=r*Math.exp(s)*n;if(Math.abs(a)>=Mt)return a}let o=z(t,s,!0)+s+Math.log(Math.abs(n));return Math.sign(n)*Math.exp(o)}var D=Number.EPSILON,H=1e6;function pt(t){return Math.expm1(C(t))}function Tt(t,e){let n=pt(t),s=pt(-t),r=Math.log(e/2),o=Math.exp(t*r),a=-r*t,i=Math.abs(t)<D?1:d(t)/(t*Math.PI),c=Math.abs(a)<D?1:Math.sinh(a)/a,l=Math.abs(t)<D?-.5772156649015329:.5/t*(n-s)*i,f=(2+n+s)*i/2,m=(n+1)/(2*o),u=(1+s)*o/2,M=(Math.cosh(a)*l+c*-r*f)/i,p=m,h=1,S=h*M,k=h*p;for(let I=1;I<H&&(M=(I*M+m+u)/(I*I-t*t),m/=I-t,u/=I+t,p=m-I*M,h*=e*e/(4*I),S+=h*M,k+=h*p,!(Math.abs(h*M)<Math.abs(S)*D));I++);return[S,2*k/e]}function At(t,e){let n=Math.sqrt(Number.MIN_VALUE*4503599627370496),s=n,r=n,o=0;for(let a=1;a<H;a++){let i=2*(t+a)/e;s=i+1/s,o=i+o,s===0&&(s=n),o===0&&(o=n),o=1/o;let c=s*o;if(r*=c,Math.abs(c-1)<=2*D)break}return r}function Jt(t,e){let n=t*t-.25,s=2*(e+1),r=1/s,o=r,a=r,i=0,c=1,l=-n,f=l,m=1+f*a;for(let p=2;p<H;p++){n-=2*(p-1),s+=2,r=1/(s+n*r),a*=s*r-1,o+=a;let h=(i-(s-2)*c)/n;if(i=c,c=h,l*=-n/p,f+=l*h,m+=f*a,h<D&&(l*=h,i/=h,c/=h),Math.abs(f*a)<Math.abs(m)*D)break}let u=(.5+t+e+(t*t-.25)*o)/e,M=Math.sqrt(Math.PI/(2*e))/m;return[M,M*u]}function V(t,e){if(!Number.isFinite(e))return e>0?t*(1/0):t*0;for(;e>1e3;)t*=2**1e3,e-=1e3;for(;e<-1e3;)t*=2**-1e3,e+=1e3;return t*2**e}function bt(t,e){let n=Math.round(t),s=t-n,r,o;if(s===-.5)r=o=Math.sqrt(Math.PI/(2*e));else if(e<=2){let[i,c]=Tt(s,e),l=Math.exp(e);r=i*l,o=c*l}else[r,o]=Jt(s,e);let a=0;for(let i=1;i<=n;i++){let c=2*(s+i)/e,l=Math.log2(Math.abs(o))+Math.log2(c);if(l>900&&Number.isFinite(l)){let m=Math.ceil(l-800);r=V(r,-m),o=V(o,-m),a+=m}let f=c*o+r;r=o,o=f}return{k:r,k1:o,exp2:a}}function Kt(t,e){let n=e*e/4,s=1,r=0;for(let o=1;o<H&&(r+=s,s*=n/o,s/=o+t,!(Math.abs(s)<=D*Math.abs(r)));o++);return W(t,e,r+s)}function Rt(t,e,n){if(t===0||!Number.isFinite(t))return t;let s=t,r=e,o=n>0?700:-700,a=Math.exp(o);for(;Math.abs(n)>700;){n-=o,s*=a;let i=Math.floor(Math.log2(Math.abs(s)));s=V(s,-i),r+=i}return V(s*Math.exp(n),r)}function x(t,e,n){let s=t.ex+n;return s===0?V(t.m,t.e2):Rt(t.m,t.e2,s*e)}function Yt(t,e){if(t===.5)return{m:Math.sqrt(2/(e*Math.PI))*(-Math.expm1(-2*e)/2),e2:0,ex:1};if(t>0&&e/t<.25)return{m:Kt(t,e),e2:0,ex:0};let n=(4*t*t+10)/(8*e);if(n*=n,n*=n,n/=24,n<D*10&&e>100){let i=4*t*t,c=8*e,l=i-1,f=c,m=1-l/f;return l*=i-9,f*=c*2,m+=l/f,l*=i-25,f*=c*3,m-=l/f,{m:m/Math.sqrt(2*e*Math.PI),e2:0,ex:1}}let{k:s,k1:r,exp2:o}=bt(t,e),a=At(t,e);return{m:1/(e*(s*a+r)),e2:-o,ex:1}}function Nt(t,e){let n=4*t*t,s=8*e,r=(n-1)/s,o=r*(n-9)/(2*s),a=o*(n-25)/(3*s),i=a*(n-49)/(4*s),c=1+r+o+a;if(Math.abs(i)<D*Math.abs(c))return{m:c*Math.sqrt(Math.PI)/Math.sqrt(2*e),e2:0,ex:-1};let{k:l,exp2:f}=bt(t,e);return{m:l,e2:f,ex:-1}}function Ct(t,e,n={}){let s=n.exponScaled??!1;if(Number.isNaN(t)||Number.isNaN(e)||t<0||!Number.isFinite(e))return NaN;let r=Math.abs(e),o=e<0&&e!==Math.floor(e);if(t===0)return o?d(r)>0?1/0:-1/0:e===0?1:0;if(t===1/0)return s?0:1/0;let a=s?-1:0,i=x(Yt(r,t),t,a);if(!o)return i;let c=Nt(r,t);return i+x({...c,m:2/Math.PI*d(r)*c.m},t,a)}function Qt(t,e,n={}){let s=n.exponScaled??!1;if(Number.isNaN(t)||Number.isNaN(e)||t<0||!Number.isFinite(e))return NaN;let r=Math.abs(e);return t===0?1/0:t===1/0?0:x(Nt(r,t),t,s?1:0)}var y=Number.EPSILON;function A(t,e){if(!Number.isFinite(e))return e>0?t*(1/0):t*0;for(;e>1e3;)t*=2**1e3,e-=1e3;for(;e<-1e3;)t*=2**-1e3,e+=1e3;return t*2**e}function gt(t,e,n,s,r){let o=s,a=r,i=0;for(let c=1;c<=n;c++){let l=2*(t+c)/e,f=Math.log2(Math.abs(a))+Math.log2(l);if(f>900&&Number.isFinite(f)){let u=Math.ceil(f-800);o=A(o,-u),a=A(a,-u),i+=u}let m=l*a-o;o=a,a=m}return{y:o,y1:a,e2:i}}var K=1e6,g=Math.sqrt(22250738585072014e-324),Ut=Number.MAX_VALUE;function It(t){return Math.expm1(C(t))}function Q(t){return d(.5-Math.abs(t%2))}function dt(t,e){let n=-(e/2)*(e/2),s=1,r=0;for(let o=1;o<K&&(r+=s,s*=n/(o*(o+t)),!(Math.abs(s)<=y*Math.abs(r)));o++);return W(t,e,r+s)}function Vt(t,e){let n=Math.log(e/2),s=0,r=t>=170||709.78/t<Math.abs(n),o;if(r){let u=_(t);if(n=t*n,o=u-Math.log(Math.PI)-n,709.78<o){let M=Math.ceil((o-700)/Math.LN2);o-=M*Math.LN2,s=M}o=-Math.exp(o)}else{let u=q(t);n=Math.pow(e/2,t),Ut*n<u&&(u*=2**-1e3,s=1e3),o=-u/(Math.PI*n)}let a=-(e/2)*(e/2),i=1,c=0;for(let u=1;u<K&&(c+=i,i*=a/(u*(u-t)),!(Math.abs(i)<=y*Math.abs(c)));u++);let l=(c+i)*o,f;if(!r)f=q(-t)*Q(t)*n/Math.PI;else{let u=U(-t);f=Math.exp(u.value+n)*u.sign/Math.PI}i=1;let m=0;for(let u=1;u<K&&(m+=i,i*=a/(u*(u+t)),!(Math.abs(i)<=y*Math.abs(m)));u++);return m+=i,l-=A(f*m,-s),{m:l,e2:s}}function Xt(t,e){let n=1,s=0,r=1,o=8*e,a=1,i=4*t*t,c=1,l=!0;do{c*=(i-a*a)/(r*o),s+=c,r+=1,a+=2;let f=(a*a-i)/(r*o);l=Math.abs(f)<.5,c*=f,n+=c,r+=1,a+=2}while(Math.abs(c)>2*y*n&&l);return l?{p:n,q:s}:void 0}function Bt(t,e){let n=It(t),s=It(-t),r=d(t),o=d(t/2),a=Math.pow(e/2,t),i=Math.log(e/2),c=-i*t,l=Math.abs(c)<y?1:Math.sinh(c)/c,f=Math.abs(t)<y?t*Math.PI*Math.PI/2:2*o*o/t,m=t===0?-.5772156649015329:(n-s)/((1+n)*(1+s)*2*t),u=(2+n+s)/((1+n)*(1+s)*2),M=Math.abs(t)<y?1/Math.PI:t/r,p=(m*Math.cosh(c)-u*i*l)*2*M,h=M/(a*(1+s)),S=M*a/(1+n),k=p+f*S,I=h,F=1,R=F*k,X=F*I,B=t*t,b=-e*e/4;for(let N=1;N<K&&(p=(N*p+h+S)/(N*N-B),h/=N-t,S/=N+t,k=p+f*S,I=h-N*k,F*=b/N,R+=F*k,X+=F*I,!(Math.abs(F*k)<Math.abs(R)*y));N++);return[-R,-2*X/e]}function Ot(t,e){let n=[g,0],s=[g,0],r=[0,0],o=1,a=[e,0];for(let i=1;i<K*100;i++){let c=E(t,i),l=O([2*c[0],2*c[1]],a);n=T(l,O([1,0],n)),r=T(l,r),n[0]===0&&(n=[g,0]),r[0]===0&&(r=[g,0]),r=O([1,0],r);let f=J(n,r);if(s=J(s,f),r[0]<0&&(o=-o),Math.abs(f[0]-1+f[1])<y*y)break}return{fv:-(s[0]+s[1]),sign:o}}function yt(t,e){if(e>30)return Ot(t,e);let n=g,s=g,r=0,o=1;for(let a=1;a<K*100;a++){let i=2*(t+a)/e;n=i-1/n,r=i-r,n===0&&(n=g),r===0&&(r=g),r=1/r;let c=n*r;if(s*=c,r<0&&(o=-o),Math.abs(c-1)<2*y)break}return{fv:-s,sign:o}}function Pt(t,e){let n=-.5/e,s=1,r=n,o=s,a=t*t,i=(.25-a)/e,c=2*e,l=2,f=r*r+1;o=l+i*r/f,r=c+i/f;let m=c,u=l;Math.abs(r)+Math.abs(o)<g&&(r=g),Math.abs(m)+Math.abs(u)<g&&(m=g),f=m*m+u*u,m=m/f,u=-u/f;let M=r*m-o*u,p=o*m+r*u;f=n,n=f*M-s*p,s=f*p+s*M;for(let h=2;h<K&&(i=h-.5,i*=i,i-=a,l+=2,f=r*r+o*o,r=c+i*r/f,o=l-i*o/f,m=c+i*m,u=l+i*u,Math.abs(r)+Math.abs(o)<g&&(r=g),Math.abs(m)+Math.abs(u)<g&&(m=g),f=m*m+u*u,m=m/f,u=-u/f,M=r*m-o*u,p=o*m+r*u,f=n,n=f*M-s*p,s=f*p+s*M,!(Math.abs(M-1)+Math.abs(p)<2*y));h++);return{p:n,q:s}}function Zt(t,e){let n=1,s=4*t*t,r=2*e;return r*=r,n+=(s-1)/(2*r),n+=3*(s-1)*(s-9)/(r*r*8),n+=15*(s-1)*(s-9)*(s-25)/(r*r*r*8*6),Math.sqrt(n*2/(Math.PI*e))}function Gt(t,e){let n=4*t*t,s=4*e,r=s*s,o=0;return o+=(n-1)/(2*s),s*=r,o+=(n-1)*(n-25)/(6*s),s*=r,o+=(n-1)*(n*n-114*n+1073)/(5*s),s*=r,o+=(n-1)*(5*n*n*n-1535*n*n+54703*n-375733)/(14*s),o}function Wt(t,e){let n=Zt(t,e),s=Gt(t,e),r=Math.cos(e),o=Math.sin(e),a=Q(t/2+.25),i=d(t/2+.25),c=Math.sin(s),l=Math.cos(s),f=(c*(r*a+o*i)+l*(o*a-r*i))*n;return{j:(l*(r*a+o*i)-c*(o*a-r*i))*n,y:f}}function tt(t,e,n){let s=Math.round(t),r=t-s,o=2/(e*Math.PI);if(!n&&(e<5||t>e*e/4))return{j:dt(t,e),y:{m:NaN,e2:0}};if(e<1&&r!==0&&Math.log(y/2)>t*Math.log(e/2*(e/2)/t))return{j:dt(t,e),y:Vt(t,e)};if(Math.max(t,1)<e*.011048543456039806){let b=Wt(t,e);return{j:b.j,y:{m:b.y,e2:0}}}if(e>8){let b=Xt(t,e);if(b!==void 0){let N=(t/2+.25)%2,P=Math.sin(e),w=Math.cos(e),Y=d(N),rt=Q(N),st=P*rt-Y*w,ot=w*rt+P*Y,it=Math.SQRT2/(Math.sqrt(Math.PI)*Math.sqrt(e));return{j:it*(b.p*ot-b.q*st),y:{m:it*(b.p*st+b.q*ot),e2:0}}}}if(e<=2){let[b,N]=Bt(r,e),P=gt(r,e,s,b,N),{fv:w}=yt(t,e);return{j:A(o/(P.y*w-P.y1),-P.e2),y:{m:P.y,e2:P.e2}}}let{fv:a,sign:i}=yt(t,e);if(e>=t&&t>2){let{p:b,q:N}=Pt(t,e),P=t/e-a,w=(b-P)/N;w===0&&(w=t*y/e);let Y=i*Math.sqrt(o/(N+w*(b-P)));return{j:Y,y:{m:w*Y,e2:0}}}let c=g,l=a*i*c,f=i*c,m=0;for(let b=s;b>0;b--){let N=2*(r+b)/e;Math.abs(f)>2**900&&(l*=2**-900,f*=2**-900,m+=900);let P=N*f-l;P===0&&(P=l*y/2),l=f,f=P}let u=A(i*c/f,-m),M=l/f,{p,q:h}=Pt(r,e),S=r/e-M,k=(p-S)/h;k===0&&(k=r*y/e);let I=Math.sign(f)*Math.sqrt(o/(h+k*(p-S))),F=I*u,R=k*I,X=R*(r/e-p-h/k);if(!n)return{j:F,y:{m:NaN,e2:0}};let B=gt(r,e,s,R,X);return{j:F,y:{m:B.y,e2:B.e2}}}function Ht(t,e){if(Number.isNaN(t)||Number.isNaN(e)||t<0||!Number.isFinite(e))return NaN;let n=Math.abs(e),s=e<0&&e!==Math.floor(e);if(t===0)return e===0?1:s?d(n)>0?1/0:-1/0:0;if(t===1/0)return 0;if(!s){let o=tt(n,t,!1).j;return e<0&&n%2===1?-o:o}let r=tt(n,t,!0);return Q(n)*r.j-A(d(n)*r.y.m,r.y.e2)}function $t(t,e){if(Number.isNaN(t)||Number.isNaN(e)||t<0||!Number.isFinite(e))return NaN;let n=Math.abs(e),s=e<0;if(t===0){if(!s)return-1/0;let i=Q(n);return i===0?0:i>0?-1/0:1/0}if(t===1/0)return 0;let r=tt(n,t,!0);if(!s)return A(r.y.m,r.y.e2);let o=Q(n),a=d(n);return(a!==0?a*r.j:0)+(o===0?0:A(o*r.y.m,r.y.e2))}function zt(t,e){if(Number.isNaN(t)||Number.isNaN(e)||t<0||!(e>0))return{lower:NaN,upper:NaN,logLower:NaN,logUpper:NaN};let n=_(e),s=q(e),r=l=>{let f=v(e,t,l,!1),m=s*f;if(Number.isFinite(s)&&f>kt&&Number.isFinite(m)&&m>kt)return[m,Math.log(m)];let u=n+v(e,t,l,!0);return u<710&&u>-746&&t>0&&(l?t<e:t>e)?vt(t,e,l):[Math.exp(u),u]},[o,a]=r(!0),[i,c]=r(!1);return{lower:o,upper:i,logLower:a,logUpper:c}}var kt=22250738585072014e-324;function vt(t,e,n){let s=j(at(L([t,0]),e),[-t,0]);n?s=j(s,L([mt(e,t)/e,0])):s=j(s,L([ut(e,t),0]));let r=s[0]+s[1];return[s[0]>-708?Math.exp(s[0])*(1+s[1]):Math.exp(r),r]}function et(t){return Number.isNaN(t)||t<0||t>2?NaN:-ft(t/2)*Math.SQRT1_2}function xt(t){if(Number.isNaN(t)||t<-1||t>1)return NaN;let e=t<0?-1:1,n=Math.abs(t);if(n>=.5)return e*et(1-n);if(n<1e-8)return t*.886226925452758*(1+Math.PI/12*t*t);let s=et(1-n);for(let r=0;r<3;r++){let o=($(s)-n)/(1.1283791670955126*Math.exp(-s*s));if(s-=o,Math.abs(o)<=1e-17*s)break}return e*s}function te(t,e){if(Number.isNaN(t)||Number.isNaN(e)||t<0||e<0)return NaN;let n=e===Math.floor(e);return t===Math.floor(t)&&n&&e>t?0:!Number.isFinite(t)||!Number.isFinite(e)?ie(t,e):n&&e<=1e3?ee(t,e):ne(t,e)}function ee(t,e){let n=[1,0];for(let s=0;s<e;s++){let r=E(t,-s),o=n[0]*r[0];if(!Number.isFinite(o)){let a=Math.sign(o);for(let i=s+1;i<e;i++)t-i<0&&(a=-a);return a*(1/0)}n=Math.abs(n[0])>1e290||Math.abs(r[0])>1e290?[(n[0]+n[1])*(r[0]+r[1]),0]:J(n,r)}return n[0]+n[1]}function ne(t,e){let[n,s]=E(t,-e);if(n+1<=0)return re(t,n,s);if(t>1e280)return e*e<1e-17*t?Math.pow(t,e):1/0;let r;if(n>=15){if(e*Math.log(n+1)>720)return 1/0;let o=E(t,-n),a=T(J(o,L([t,0])),ct(n,[t,0]));a=j(a,[Z(t)-Z(n),0]),r=Math.sqrt(t/n)*Math.exp(a[0])*(1+a[1])}else if(t<30)r=q(t+1)/q(n+1);else{if(_(t+1)-_(n+1)>720)return 1/0;let o=T(nt(t+1),L([q(n+1),0]));r=Math.exp(o[0])*(1+o[1])}return s!==0&&Number.isFinite(r)&&r!==0&&(r*=Math.exp(-s*G(n+1))),r}function re(t,e,n){let s=j(E(e,1),[n,0]),r=d(s[0])+d(s[0]+.5)*Math.PI*s[1];if(r===0)return 0;let o=Math.sign(r),a=j(T(L([Math.abs(r),0]),oe),[-n*G(-e),0]);if(_(t+1)+_(-e)+a[0]>720)return o*(1/0);let i=j(j(nt(t+1),nt(-e)),a);return o*Math.exp(i[0])*(1+i[1])}var se=[.9189385332046728,-38782941580672414e-33],oe=[1.1447298858494002,10265951162707826e-33];function nt(t){if(t<15)return L([q(t),0]);let e=T(J(E(t,-.5),L([t,0])),[t,0]);return j(j(e,se),[Z(t),0])}function ie(t,e){let n=U(t+1),s=U(t-e+1);return n.sign*s.sign*Math.exp(n.value-s.value)}function ae(t){return Number.isNaN(t)||t<-1?NaN:t===-1||t===1/0?-1/0:lt(t)}function fe(t){return Number.isNaN(t)||t===-1/0?NaN:t===1/0||t<=-1&&t===Math.floor(t)?1/0:C(t)}function ce(t){return Number.isNaN(t)||t<0?NaN:t===0?-1/0:t===1/0?0:ht(-t)}function le(t){return Number.isNaN(t)?NaN:t<=-37?Math.exp(t):t<=18?Math.log1p(Math.exp(t)):t<=33.3?t+Math.exp(-t):t}export{Ct as besselI,Ht as besselJ,Qt as besselK,$t as besselY,Dt as beta,wt as choose,G as digamma,$ as erf,qt as erfc,et as erfcinv,xt as erfinv,_t as factorial,q as gamma,zt as gammainc,Ft as lbeta,Lt as lchoose,Et as lfactorial,_ as lgamma,fe as lgamma1p,ce as log1mexp,le as log1pexp,ae as log1pmx,te as perm,jt as psigamma,St as trigamma};
|