@numero-uno-jpn/rstats 0.15.2 → 0.15.3
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 +114 -0
- package/README.ja.md +8 -8
- package/README.md +8 -8
- package/dist/chunks/{chunk-PEYGUK32.js → chunk-3THFTB36.js} +2 -2
- package/dist/chunks/chunk-3TSWYE5L.js +2 -0
- package/dist/chunks/{chunk-IBPWRQIF.js → chunk-3WPU6LGK.js} +2 -2
- package/dist/chunks/{chunk-VWJ74UHC.js → chunk-5ITR67MB.js} +2 -2
- package/dist/chunks/chunk-5NRFU6F6.js +2 -0
- package/dist/chunks/{chunk-XNPU54NH.js → chunk-E2LCSVQV.js} +1 -1
- package/dist/chunks/chunk-FCNVTIPJ.js +2 -0
- package/dist/chunks/chunk-FKAKALOZ.js +2 -0
- package/dist/chunks/{chunk-HBMHR5SS.js → chunk-HD73UKPT.js} +2 -2
- package/dist/chunks/{chunk-4Z2XDWKV.js → chunk-IUULP3LE.js} +1 -1
- package/dist/chunks/{chunk-Q4PGYESP.js → chunk-JQG3YQOC.js} +2 -2
- package/dist/chunks/{chunk-LG74QY5U.js → chunk-KT66SB7R.js} +1 -1
- package/dist/chunks/{chunk-SREPSVTT.js → chunk-MAUAOQG3.js} +2 -2
- package/dist/chunks/{chunk-YVREYVI2.js → chunk-MDYE7QP2.js} +2 -2
- package/dist/chunks/{chunk-XPLDEK6D.js → chunk-NM3Z2UBQ.js} +2 -2
- package/dist/chunks/{chunk-AJBLCNZ7.js → chunk-PMJI5QO6.js} +2 -2
- package/dist/chunks/chunk-UF7KOTHF.js +3 -0
- package/dist/chunks/chunk-UOE57JGT.js +2 -0
- package/dist/chunks/{chunk-3WQCKGKP.js → chunk-USPEBXSR.js} +2 -2
- package/dist/chunks/{chunk-PWVQVJTP.js → chunk-VLUL2HFW.js} +1 -1
- package/dist/chunks/{chunk-YGT4P7EU.js → chunk-ZIX7NYQF.js} +1 -1
- package/dist/descriptive.js +2 -2
- package/dist/distributions/beta.js +11 -1
- package/dist/distributions/cauchy.js +76 -5
- package/dist/distributions/exponential.js +6 -1
- package/dist/distributions/f.js +41 -5
- package/dist/distributions/gamma.js +34 -3
- package/dist/distributions/geometric.js +4 -1
- package/dist/distributions/invgamma.js +4 -0
- package/dist/distributions/kumaraswamy.js +22 -4
- package/dist/distributions/laplace.js +5 -2
- package/dist/distributions/logistic.js +8 -2
- package/dist/distributions/lognormal.js +12 -1
- package/dist/distributions/nbeta.js +66 -24
- package/dist/distributions/nchisq.js +58 -11
- package/dist/distributions/negbinomial.js +6 -1
- package/dist/distributions/normal.js +26 -1
- package/dist/distributions/nt.d.ts +28 -3
- package/dist/distributions/nt.js +145 -19
- package/dist/distributions/pareto.js +5 -0
- package/dist/distributions/t.js +55 -3
- package/dist/distributions/triangular.js +35 -8
- package/dist/distributions/tukey.js +16 -0
- package/dist/distributions/uniform.js +2 -0
- package/dist/distributions/weibull.js +23 -3
- package/dist/distributions.js +2 -2
- package/dist/internal/ddexp.d.ts +8 -0
- package/dist/internal/ddexp.js +27 -0
- package/dist/internal/invert.d.ts +5 -0
- package/dist/internal/invert.js +10 -5
- package/dist/internal/noncentral.d.ts +7 -0
- package/dist/internal/noncentral.js +9 -0
- package/dist/internal/poissonMixture.js +29 -6
- 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/beta.js +7 -0
- package/dist/special/gamma.js +4 -0
- package/dist/special/igam.js +33 -6
- package/dist/special/incbet.js +70 -6
- package/dist/special/incbetLargeA.js +7 -2
- package/dist/special/incbetPrefactor.d.ts +5 -0
- package/dist/special/incbetPrefactor.js +14 -3
- package/dist/special/loader.js +70 -21
- package/dist/special.js +2 -2
- package/dist/tests.js +2 -2
- package/package.json +1 -1
- package/dist/chunks/chunk-2CUKVVRO.js +0 -2
- package/dist/chunks/chunk-D4F7GQAY.js +0 -2
- package/dist/chunks/chunk-EBQMGCQZ.js +0 -2
- package/dist/chunks/chunk-JLAH3X77.js +0 -2
- package/dist/chunks/chunk-RCAL4VHM.js +0 -3
- package/dist/chunks/chunk-UFT662QZ.js +0 -2
package/dist/special/beta.js
CHANGED
|
@@ -55,6 +55,9 @@ export function beta(a, b) {
|
|
|
55
55
|
let sign = 1;
|
|
56
56
|
if (a === 0 || b === 0)
|
|
57
57
|
return Infinity;
|
|
58
|
+
// B(a, b) > 1/a overflows where 1/a does (the product below was NaN at beta(1e-310, 1e-310); R gives Inf)
|
|
59
|
+
if (1 / Math.min(a, b) === Infinity)
|
|
60
|
+
return Infinity;
|
|
58
61
|
if (Math.abs(a) < Math.abs(b))
|
|
59
62
|
[a, b] = [b, a];
|
|
60
63
|
if (Math.abs(a) > ASYMP_FACTOR * Math.abs(b) && a > ASYMP_FACTOR) {
|
|
@@ -120,6 +123,10 @@ export function lbeta(a, b) {
|
|
|
120
123
|
}
|
|
121
124
|
if (a === 0 || b === 0)
|
|
122
125
|
return Infinity;
|
|
126
|
+
// Γ of a shape below 1e-300 overflows (Γ(a) ≈ 1/a), and the product below was Infinity or NaN (lbeta(1e-310, 1e-310) was
|
|
127
|
+
// NaN, R gives 714.49452600871405): the logs instead, -log a each, which cancel by at most a few ulps
|
|
128
|
+
if (Math.min(a, b) < 1e-300)
|
|
129
|
+
return lgamma(a) + lgamma(b) - lgamma(a + b);
|
|
123
130
|
if (Math.abs(a) < Math.abs(b))
|
|
124
131
|
[a, b] = [b, a];
|
|
125
132
|
if (Math.abs(a) > ASYMP_FACTOR * Math.abs(b) && a > ASYMP_FACTOR)
|
package/dist/special/gamma.js
CHANGED
|
@@ -170,6 +170,10 @@ export function lgammaSign(x) {
|
|
|
170
170
|
return { value: Infinity, sign: 1 };
|
|
171
171
|
return { value: LOGPI - Math.log(z) - w, sign };
|
|
172
172
|
}
|
|
173
|
+
// log|Γ(x)| = -log|x| - γ x + O(x²), -log|x| to the double; the product below overflowed (1 / x) and lgamma was Infinity
|
|
174
|
+
// at a subnormal x (lgamma(5e-324) is 744.44007192138122, as R gives)
|
|
175
|
+
if (x !== 0 && Math.abs(x) < 1e-300)
|
|
176
|
+
return { value: -Math.log(Math.abs(x)), sign: x > 0 ? 1 : -1 };
|
|
173
177
|
if (x < 13) {
|
|
174
178
|
let z = 1;
|
|
175
179
|
let p = 0;
|
package/dist/special/igam.js
CHANGED
|
@@ -23,17 +23,27 @@ const SMALLRATIO = 0.3;
|
|
|
23
23
|
const LARGERATIO = 4.5;
|
|
24
24
|
const BIG = 4.503599627370496e15;
|
|
25
25
|
const BIGINV = 2.22044604925031308085e-16;
|
|
26
|
+
/**
|
|
27
|
+
* Below this the factor x^a e^-x / Gamma(a + 1) (dpoisRaw) is rounded on the subnormal grid or 0, and the linear value
|
|
28
|
+
* of the tail is exp of its log instead: the product with the series or continued fraction had lost digits, or was 0
|
|
29
|
+
* where the tail is a few subnormal ulps (pchisq(150856.77, 172464.33) was 0, its log -743.7469247408216, so 1e-323)
|
|
30
|
+
*/
|
|
31
|
+
const MIN_NORMAL = 2 ** -1022;
|
|
26
32
|
/** Series for P(a, x) (DLMF 8.11.4) */
|
|
27
33
|
function igamSeries(a, x, log) {
|
|
28
34
|
const ans = igamSeriesSum(a, x);
|
|
29
35
|
// x^a e^-x / Gamma(a) * ans / a = dpoisRaw(a, x) * ans
|
|
30
|
-
|
|
36
|
+
if (log)
|
|
37
|
+
return dpoisRaw(a, x, true) + Math.log(ans);
|
|
38
|
+
const d = dpoisRaw(a, x, false);
|
|
39
|
+
return d >= MIN_NORMAL ? d * ans : Math.exp(dpoisRaw(a, x, true) + Math.log(ans));
|
|
31
40
|
}
|
|
32
41
|
/** [log, linear] of igamSeries */
|
|
33
42
|
function igamSeriesBoth(a, x) {
|
|
34
43
|
const ans = igamSeriesSum(a, x);
|
|
35
44
|
const d = dpoisRawBoth(a, x);
|
|
36
|
-
|
|
45
|
+
const l = d[0] + Math.log(ans);
|
|
46
|
+
return [l, d[1] >= MIN_NORMAL ? d[1] * ans : Math.exp(l)];
|
|
37
47
|
}
|
|
38
48
|
/** sum_n x^n / ((a + 1) ... (a + n)): P(a, x) = x^a e^-x / Gamma(a + 1) times this */
|
|
39
49
|
export function igamSeriesSum(a, x) {
|
|
@@ -105,15 +115,17 @@ export function igamSeriesSumDD(a, x) {
|
|
|
105
115
|
function igamcContinuedFraction(a, x, log) {
|
|
106
116
|
const ans = igamcContinuedFractionValue(a, x);
|
|
107
117
|
// x^a e^-x / Gamma(a) * ans = a * dpoisRaw(a, x) * ans
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
118
|
+
if (log)
|
|
119
|
+
return Math.log(a) + dpoisRaw(a, x, true) + Math.log(ans);
|
|
120
|
+
const d = dpoisRaw(a, x, false);
|
|
121
|
+
return d >= MIN_NORMAL ? a * d * ans : Math.exp(Math.log(a) + dpoisRaw(a, x, true) + Math.log(ans));
|
|
111
122
|
}
|
|
112
123
|
/** [log, linear] of igamcContinuedFraction */
|
|
113
124
|
function igamcContinuedFractionBoth(a, x) {
|
|
114
125
|
const ans = igamcContinuedFractionValue(a, x);
|
|
115
126
|
const d = dpoisRawBoth(a, x);
|
|
116
|
-
|
|
127
|
+
const l = Math.log(a) + d[0] + Math.log(ans);
|
|
128
|
+
return [l, d[1] >= MIN_NORMAL ? a * d[1] * ans : Math.exp(l)];
|
|
117
129
|
}
|
|
118
130
|
/** The continued fraction of DLMF 8.9.2: Q(a, x) = x^a e^-x / Gamma(a) times this */
|
|
119
131
|
export function igamcContinuedFractionValue(a, x) {
|
|
@@ -325,6 +337,13 @@ function directTailBoth(a, x) {
|
|
|
325
337
|
const q = igamcSeries(a, x);
|
|
326
338
|
return { lower: false, log: Math.log(q), lin: q };
|
|
327
339
|
}
|
|
340
|
+
/**
|
|
341
|
+
* Below this a, Q(a, x) is taken as (a / A_SUB) Q(A_SUB, x): Q(a, x) / a varies with a by a relative O(a log x) only
|
|
342
|
+
* (below 1e-297 here). Q is then of the order of a, so subnormal for a below 1e-308 or so, and the direct forms had
|
|
343
|
+
* lost digits before the log was taken (pgamma(1, 4.8e-316, scale = 2.06, lower = FALSE, log = TRUE) was 5e-9
|
|
344
|
+
* off)
|
|
345
|
+
*/
|
|
346
|
+
const A_SUB = 1e-300;
|
|
328
347
|
/**
|
|
329
348
|
* Return [log, linear] of gammaInc from a single series/continued-fraction computation.
|
|
330
349
|
* The values are bit-identical to gammaInc(.., true) and gammaInc(.., false) respectively
|
|
@@ -355,6 +374,10 @@ export function gammaIncBoth(a, x, lower) {
|
|
|
355
374
|
return [Math.log1p(-Math.exp(lq)), -Math.expm1(lq)];
|
|
356
375
|
return [lq, Math.exp(lq)];
|
|
357
376
|
}
|
|
377
|
+
if (!lower && a < A_SUB) {
|
|
378
|
+
const [l, v] = gammaIncBoth(A_SUB, x, false);
|
|
379
|
+
return [l + Math.log(a / A_SUB), v * (a / A_SUB)];
|
|
380
|
+
}
|
|
358
381
|
const absxmaA = Math.abs(x - a) / a;
|
|
359
382
|
if (xsfAsymptotic(a, absxmaA)) {
|
|
360
383
|
const v = asymptoticSeries(a, x, lower);
|
|
@@ -400,6 +423,10 @@ export function gammaInc(a, x, lower, log) {
|
|
|
400
423
|
return log ? Math.log1p(-Math.exp(lq)) : -Math.expm1(lq);
|
|
401
424
|
return log ? lq : Math.exp(lq);
|
|
402
425
|
}
|
|
426
|
+
if (!lower && a < A_SUB) {
|
|
427
|
+
const v = gammaInc(A_SUB, x, false, log);
|
|
428
|
+
return log ? v + Math.log(a / A_SUB) : v * (a / A_SUB);
|
|
429
|
+
}
|
|
403
430
|
/* Asymptotic regime where a ~ x: both tails can be computed directly */
|
|
404
431
|
const absxmaA = Math.abs(x - a) / a;
|
|
405
432
|
if (xsfAsymptotic(a, absxmaA)) {
|
package/dist/special/incbet.js
CHANGED
|
@@ -17,7 +17,7 @@ import { dbinomExponent, dbinomRawDD } from "./loader.js";
|
|
|
17
17
|
import { ddAdd, ddDiv, ddLog, ddMul, ddMulNum, ddSub, isDoubleDouble, SPLITTER, twoProd, twoSum } from "./dd.js";
|
|
18
18
|
import { lgamma1p } from "./gamma.js";
|
|
19
19
|
import { lgammaDiffDD } from "./lgammaDiff.js";
|
|
20
|
-
import { HUGE_SHAPE, HUGE_SHAPE_MAX_SMALL, lgammaRatioHuge, prefactorParts, SMALL_SHAPE, smallShapeG, } from "./incbetPrefactor.js";
|
|
20
|
+
import { HUGE_SHAPE, HUGE_SHAPE_MAX_SMALL, lgammaRatioHuge, mulBig, prefactorParts, SMALL_SHAPE, smallShapeG, } from "./incbetPrefactor.js";
|
|
21
21
|
import { betaIncTemme, TEMME_MIN_M } from "./incbetTemme.js";
|
|
22
22
|
import { betaIncLargeA, LARGE_A_MIN, SMALL_B_MAX } from "./incbetLargeA.js";
|
|
23
23
|
const BIG = 4.503599627370496e15;
|
|
@@ -58,6 +58,11 @@ function smallPrefactorTimes(a, b, x, xc, m) {
|
|
|
58
58
|
const c = m * ms;
|
|
59
59
|
if (!(e[0] > -1400) || !Number.isFinite(c) || c === 0)
|
|
60
60
|
return undefined;
|
|
61
|
+
// (exp(e) directly above -700, where the prefactor is below the normal range through c alone, a shape below 1e-305:
|
|
62
|
+
// e + 700 would round e to the ulp of 700, 1e-13, and pbeta(1 - 6e-14, 0.97, 4.7e-307, { lowerTail: false }) was
|
|
63
|
+
// 1 - 5.5e-14, not 1)
|
|
64
|
+
if (e[0] > -700)
|
|
65
|
+
return Math.exp(e[0]) * (1 + e[1]) * c || undefined;
|
|
61
66
|
const v = Math.exp(e[0] + 700) * (1 + e[1]) * c * Math.exp(-700);
|
|
62
67
|
return v > 0 ? v : undefined;
|
|
63
68
|
}
|
|
@@ -631,6 +636,23 @@ function continuedFractionCoreOps(a, b, xd, xcd, second) {
|
|
|
631
636
|
const huge = Math.max(a, b) >= 2 ** 52 || stepsInexact(a);
|
|
632
637
|
// Above 1e150 the products of two of the parameters (h3 h4 = a (a + 1), ...) overflow: divide before multiplying
|
|
633
638
|
const vast = Math.max(a, b) > 1e150;
|
|
639
|
+
// The splitting of an operand, or of a quotient, above about 1.3e300 overflows in ddDiv and ddMul: where one would be
|
|
640
|
+
// that large, the operands are scaled by 2^±64 first (exactly; the other operand is then small, or the result
|
|
641
|
+
// overflows anyway), and a quotient back. pbeta(1.5e-236, 9220.5, 2.6e301) and pbeta(1e-307, 55.1, 6.3e307) were NaN
|
|
642
|
+
const div = (p, q) => {
|
|
643
|
+
if (q[0] > 1e299)
|
|
644
|
+
return ddDiv(scaled(p, 2 ** -64), scaled(q, 2 ** -64));
|
|
645
|
+
if (Math.abs(p[0]) > 1e299 * q[0])
|
|
646
|
+
return scaled(ddDiv(scaled(p, 2 ** -64), q), 2 ** 64);
|
|
647
|
+
return ddDiv(p, q);
|
|
648
|
+
};
|
|
649
|
+
const mul = (p, q) => {
|
|
650
|
+
if (Math.abs(q[0]) > 1e299)
|
|
651
|
+
return ddMul(scaled(p, 2 ** 64), scaled(q, 2 ** -64));
|
|
652
|
+
if (Math.abs(p[0]) > 1e299)
|
|
653
|
+
return ddMul(scaled(p, 2 ** -64), scaled(q, 2 ** 64));
|
|
654
|
+
return ddMul(p, q);
|
|
655
|
+
};
|
|
634
656
|
// Partial numerators k1 x k2 / (k3 k4) and k5 x k6 / (k7 k8). k1, k3, k4, k7, k8 are doubles, with
|
|
635
657
|
// double-double copies (h1, ...) that are used and advanced only when huge
|
|
636
658
|
let k1 = a;
|
|
@@ -654,7 +676,7 @@ function continuedFractionCoreOps(a, b, xd, xcd, second) {
|
|
|
654
676
|
let ans = [1, 0];
|
|
655
677
|
for (let n = 0; n < 100000; n++) {
|
|
656
678
|
let xk = vast
|
|
657
|
-
?
|
|
679
|
+
? mul(mul(z, div(h1, h3)), div(k2, h4))
|
|
658
680
|
: huge
|
|
659
681
|
? ddDiv(ddMul(ddMul(z, h1), k2), ddMul(h3, h4))
|
|
660
682
|
: ddDiv(ddMul(ddMulNum(z, k1), k2), twoProd(k3, k4));
|
|
@@ -665,7 +687,7 @@ function continuedFractionCoreOps(a, b, xd, xcd, second) {
|
|
|
665
687
|
qkm2 = qkm1;
|
|
666
688
|
qkm1 = qk;
|
|
667
689
|
xk = vast
|
|
668
|
-
?
|
|
690
|
+
? mul(mul(z, [k5, 0]), div(div(k6, h7), h8))
|
|
669
691
|
: ddDiv(ddMul(ddMulNum(z, k5), k6), huge ? ddMul(h7, h8) : twoProd(k7, k8));
|
|
670
692
|
pk = ddAdd(pkm1, ddMul(pkm2, xk));
|
|
671
693
|
qk = ddAdd(qkm1, ddMul(qkm2, xk));
|
|
@@ -713,6 +735,10 @@ function continuedFractionCoreOps(a, b, xd, xcd, second) {
|
|
|
713
735
|
}
|
|
714
736
|
return ans[0] + ans[1];
|
|
715
737
|
}
|
|
738
|
+
/** p s for a power of two s */
|
|
739
|
+
function scaled(p, s) {
|
|
740
|
+
return [p[0] * s, p[1] * s];
|
|
741
|
+
}
|
|
716
742
|
/** Whether the series can be used in frame (a, b, x) */
|
|
717
743
|
function pseriesOk(a, b, x) {
|
|
718
744
|
return b * x <= 1 && x <= 0.95;
|
|
@@ -810,17 +836,24 @@ export function betaIncTinyX(a, b, x, lx, lower, wantLog) {
|
|
|
810
836
|
let r = 1;
|
|
811
837
|
let lr = 0;
|
|
812
838
|
let e;
|
|
839
|
+
// a log x by mulBig (the splitting of a above 1e300 in ddMulNum overflowed: pbeta(1.5e-323, 1.4e304, 0.5) was NaN).
|
|
840
|
+
// Where it overflows to -Infinity, the terms of the order of a log a below are Infinity too, and the sum was NaN
|
|
841
|
+
// (pbeta(4.2e-310, 4.1e307, 1113))
|
|
842
|
+
const ax = mulBig(lx, a);
|
|
843
|
+
if (ax[0] === -Infinity)
|
|
844
|
+
return lower ? [-Infinity, 0] : [0, 1];
|
|
813
845
|
if (Math.min(a, b) < SMALL_SHAPE) {
|
|
814
846
|
const q = Math.min(a, b) / Math.max(a, b);
|
|
815
847
|
[r, lr] = a <= b ? [1 / (1 + q), -Math.log1p(q)] : [q / (1 + q), Math.log(q) - Math.log1p(q)];
|
|
816
|
-
e = ddAdd(ddAdd(
|
|
848
|
+
e = ddAdd(ddAdd(ax, smallShapeG(a, b)), [c, 0]);
|
|
817
849
|
}
|
|
818
850
|
else {
|
|
819
851
|
const lg = b >= HUGE_SHAPE && a <= HUGE_SHAPE_MAX_SMALL ? lgammaRatioHuge(a, b) : lgammaDiffDD(a, b);
|
|
820
|
-
e = ddAdd(ddAdd(
|
|
852
|
+
e = ddAdd(ddAdd(ax, lg), [c - lgamma1p(a), 0]);
|
|
821
853
|
}
|
|
822
854
|
const lt = lr + e[0] + e[1];
|
|
823
|
-
|
|
855
|
+
// (0 below the subnormal range, where the low part of e can be far beyond 1 and made it -0)
|
|
856
|
+
const v = e[0] < -746 ? 0 : r * (Math.exp(e[0]) * (1 + e[1]));
|
|
824
857
|
if (lower)
|
|
825
858
|
return [lt, v];
|
|
826
859
|
// The other tail: -expm1(lt), and its log from v where v is small (lt rounded to a double is off by up to ε |lt|,
|
|
@@ -839,11 +872,34 @@ function betaIncCore(a, b, xd, xcd, lower, wantLog) {
|
|
|
839
872
|
const r = betaIncUncapped(a, b, xd, xcd, lower, wantLog);
|
|
840
873
|
return r[1] > 1 || r[0] > 0 ? [Math.min(r[0], 0), Math.min(r[1], 1)] : r;
|
|
841
874
|
}
|
|
875
|
+
/**
|
|
876
|
+
* Below this shape s, the tail of the order of s (1 - I_x(s, b), or I_x(a, s)) is taken as (s / SUB_SHAPE) times its
|
|
877
|
+
* value at SUB_SHAPE, where the other shape is above SUB_OTHER: 1 - I_x(s, b) = s g(x, b) (1 + O(s / min(1, b)) times
|
|
878
|
+
* logs of x and b), so the relative error of the scaling is below 1e-19. The tail is subnormal for s below 1e-308 or
|
|
879
|
+
* so, and its log, taken of the subnormal value, had lost digits (dbeta(0.97, 0.13, 8.15e-322) did not match the
|
|
880
|
+
* differences of pbeta(x, 0.13, 8.15e-322, { logP: true }))
|
|
881
|
+
*/
|
|
882
|
+
const SUB_SHAPE = 1e-300;
|
|
883
|
+
const SUB_OTHER = 1e-280;
|
|
884
|
+
/** [log, linear] of the tail t at SUB_SHAPE scaled to the shape s (small), or of the other tail (!small) */
|
|
885
|
+
function subShapeTail(t, s, small) {
|
|
886
|
+
const r = s / SUB_SHAPE;
|
|
887
|
+
const v = t[1] * r;
|
|
888
|
+
if (small)
|
|
889
|
+
return [t[0] + Math.log(r), v];
|
|
890
|
+
return [Math.log1p(-v), 1 - v];
|
|
891
|
+
}
|
|
842
892
|
function betaIncUncapped(a, b, xd, xcd, lower, wantLog) {
|
|
843
893
|
if (xd[0] <= 0)
|
|
844
894
|
return lower ? [-Infinity, 0] : [0, 1];
|
|
845
895
|
if (xcd[0] <= 0)
|
|
846
896
|
return lower ? [0, 1] : [-Infinity, 0];
|
|
897
|
+
// The tail of the order of a shape below SUB_SHAPE (1 - I_x(a, b) for a tiny a, I_x(a, b) for a tiny b), from
|
|
898
|
+
// that at SUB_SHAPE scaled (see there), and the other tail as 1 minus it
|
|
899
|
+
if (a < SUB_SHAPE && b > SUB_OTHER)
|
|
900
|
+
return subShapeTail(betaIncUncapped(SUB_SHAPE, b, xd, xcd, false, wantLog), a, !lower);
|
|
901
|
+
if (b < SUB_SHAPE && a > SUB_OTHER)
|
|
902
|
+
return subShapeTail(betaIncUncapped(a, SUB_SHAPE, xd, xcd, true, wantLog), b, lower);
|
|
847
903
|
// x (or 1 - x) is subnormal: the series with its prefactor in logs (betaIncTinyX). The binomial-probability helpers
|
|
848
904
|
// break down on products of subnormals
|
|
849
905
|
if (xd[0] < DBL_MIN)
|
|
@@ -918,6 +974,14 @@ function betaIncUncapped(a, b, xd, xcd, lower, wantLog) {
|
|
|
918
974
|
const o = pseries(oa, ob, ox, oxc, false);
|
|
919
975
|
return [wantLog ? Math.log1p(-o) : NaN, 1 - o];
|
|
920
976
|
}
|
|
977
|
+
// Likewise from the complement of the series where it passes the cancellation check (see below), as the log already
|
|
978
|
+
// is: for a tiny shape the series value is 1 - O(shape) and its rounding of a few ulps was all of its distance from 1
|
|
979
|
+
// (pbeta(1 - 6e-14, 0.97, 4.7e-307, { lowerTail: false }) was 1 - 1.1e-16 beside a lower tail of 1.4e-305)
|
|
980
|
+
if (v > 0.5) {
|
|
981
|
+
const o = pseriesComplement(pa, pb, px, false);
|
|
982
|
+
if (pa * Math.abs(Math.log(px[0])) <= 32 * o)
|
|
983
|
+
return [wantLog ? Math.log1p(-o) : NaN, 1 - o];
|
|
984
|
+
}
|
|
921
985
|
return finish(v, otherDirect);
|
|
922
986
|
}
|
|
923
987
|
if (pseriesOk(oa, ob, ox[0])) {
|
|
@@ -126,7 +126,9 @@ export function betaIncLargeA(a, b, xd, yd, lower, wantLog) {
|
|
|
126
126
|
// with 100/u steps, did not end)
|
|
127
127
|
const lx = y < 1e-15 ? ddNeg(ddAdd(yd, [(y * y) / 2, 0])) : ddLog(xd);
|
|
128
128
|
const ld = [-lx[0], -lx[1]];
|
|
129
|
-
|
|
129
|
+
// (td scaled by 2^-64 and ld by 2^64 above 1e299, where the splitting of td overflowed: pbeta(1e-305, 55.1, 6.3e307)
|
|
130
|
+
// was NaN)
|
|
131
|
+
const ud = td[0] > 1e299 ? ddMul([td[0] * 2 ** -64, td[1] * 2 ** -64], [ld[0] * 2 ** 64, ld[1] * 2 ** 64]) : ddMul(td, ld);
|
|
130
132
|
const u = ud[0] + ud[1];
|
|
131
133
|
if (!(u > 0 && u < Infinity))
|
|
132
134
|
return undefined;
|
|
@@ -153,7 +155,10 @@ export function betaIncLargeA(a, b, xd, yd, lower, wantLog) {
|
|
|
153
155
|
}
|
|
154
156
|
else {
|
|
155
157
|
const { e } = dbinomExponent(a, b, xd, yd);
|
|
156
|
-
|
|
158
|
+
// (with a and a + b scaled by 2^-64 above 1e299, where the splitting of a in the products would overflow)
|
|
159
|
+
const as = a > 1e299 ? a * 2 ** -64 : a;
|
|
160
|
+
const bs = a > 1e299 ? b * 2 ** -64 : b;
|
|
161
|
+
const md = ddMul(ddDiv(twoProd(as, b), twoSum(as, bs)), INV_2PI);
|
|
157
162
|
const sh = Math.sqrt(md[0]);
|
|
158
163
|
const sq = twoProd(sh, sh);
|
|
159
164
|
[eHi, eLo, fac] = [-e[0], -e[1], sh];
|
|
@@ -50,3 +50,8 @@ export declare function lgammaRatioHuge(s: number, l: number): DD;
|
|
|
50
50
|
* from lgammaRatioHuge (lgammaDiff loses s where s/l underflows)
|
|
51
51
|
*/
|
|
52
52
|
export declare function smallShapeG(a: number, b: number): DD;
|
|
53
|
+
/**
|
|
54
|
+
* x a in double-double, also for a above 1e290 (where the splitting of a in ddMulNum would overflow); [±Infinity, 0]
|
|
55
|
+
* where the product overflows (the scaling back made it NaN)
|
|
56
|
+
*/
|
|
57
|
+
export declare function mulBig(x: DD, a: number): DD;
|
|
@@ -54,7 +54,13 @@ export function prefactorParts(a, b, x, xc) {
|
|
|
54
54
|
}
|
|
55
55
|
const lx = x[0] <= 0.5 ? ddLog(x) : log1m(xc);
|
|
56
56
|
const lxc = xc[0] <= 0.5 ? ddLog(xc) : log1m(x);
|
|
57
|
-
|
|
57
|
+
const ta = mulBig(lx, a);
|
|
58
|
+
const tb = mulBig(lxc, b);
|
|
59
|
+
// (both terms are at most 0; where one overflows the exponent is -Infinity, which the double-double sums made NaN:
|
|
60
|
+
// pbeta(0.998, 55.1, 6.3e307) was NaN)
|
|
61
|
+
if (!Number.isFinite(ta[0]) || !Number.isFinite(tb[0]))
|
|
62
|
+
return [c, [ta[0] + tb[0], 0]];
|
|
63
|
+
return [c, ddAdd(ddAdd(ta, tb), g)];
|
|
58
64
|
}
|
|
59
65
|
/**
|
|
60
66
|
* log Γ(l + s) - log Γ(l) in double-double for l >= HUGE_SHAPE and s <= HUGE_SHAPE_MAX_SMALL. From Stirling's series,
|
|
@@ -86,7 +92,12 @@ export function smallShapeG(a, b) {
|
|
|
86
92
|
function log1m(y) {
|
|
87
93
|
return y[0] < 1e-15 ? ddNeg(ddAdd(y, [(y[0] * y[0]) / 2, 0])) : ddLog(ddSub([1, 0], y));
|
|
88
94
|
}
|
|
89
|
-
/**
|
|
90
|
-
|
|
95
|
+
/**
|
|
96
|
+
* x a in double-double, also for a above 1e290 (where the splitting of a in ddMulNum would overflow); [±Infinity, 0]
|
|
97
|
+
* where the product overflows (the scaling back made it NaN)
|
|
98
|
+
*/
|
|
99
|
+
export function mulBig(x, a) {
|
|
100
|
+
if (!Number.isFinite(x[0] * a))
|
|
101
|
+
return [x[0] * a, 0];
|
|
91
102
|
return a > 1e290 ? ddMulNum(ddMulNum(x, a / 2 ** 64), 2 ** 64) : ddMulNum(x, a);
|
|
92
103
|
}
|
package/dist/special/loader.js
CHANGED
|
@@ -74,8 +74,7 @@ export function bd0dd(x, M) {
|
|
|
74
74
|
// enters them), so scale x and M by 2^-64 (exactly, unless the smaller one would become subnormal; its quotient is
|
|
75
75
|
// then far out and the logarithms are taken separately below) and the result back (pgamma(9.9e299, 1e300) was NaN)
|
|
76
76
|
if (Math.max(x, M[0]) > 1e299 && Math.min(x, M[0]) > 1e-250) {
|
|
77
|
-
|
|
78
|
-
return [r[0] * 2 ** 64, r[1] * 2 ** 64];
|
|
77
|
+
return scaleUp(bd0dd(x * 2 ** -64, [M[0] * 2 ** -64, M[1] * 2 ** -64]));
|
|
79
78
|
}
|
|
80
79
|
if (!isDoubleDouble())
|
|
81
80
|
return bd0ddOps(x, M);
|
|
@@ -353,7 +352,7 @@ export function bd0dd(x, M) {
|
|
|
353
352
|
// of the double-double division overflows (dgamma(9.3e281, 1.9e183, { rate: 3e21 }) threw a TypeError)
|
|
354
353
|
const ratio = x / M[0];
|
|
355
354
|
const lr = ratio > 1e-290 && ratio < 1e290 && Math.max(x, M[0]) < 1e300 ? ddLog(ddDiv([x, 0], M)) : ddSub(ddLog([x, 0]), ddLog(M));
|
|
356
|
-
return
|
|
355
|
+
return farDeviance(lr, x, [dh, dl]);
|
|
357
356
|
}
|
|
358
357
|
/** bd0dd written with calls to the double-double helpers (used when evaluating in double-precision mode; see src/special/dd.ts) */
|
|
359
358
|
function bd0ddOps(x, M) {
|
|
@@ -376,7 +375,25 @@ function bd0ddOps(x, M) {
|
|
|
376
375
|
// x log(x/M) + (M - x)
|
|
377
376
|
const ratio = x / M[0];
|
|
378
377
|
const lr = ratio > 1e-290 && ratio < 1e290 && Math.max(x, M[0]) < 1e300 ? ddLog(ddDiv([x, 0], M)) : ddSub(ddLog([x, 0]), ddLog(M));
|
|
379
|
-
return
|
|
378
|
+
return farDeviance(lr, x, d);
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* x lr - d for lr = log(x/M) and d = x - M (the far branch of bd0dd). Above 1e299 the splitting of x in the product
|
|
382
|
+
* overflows (pgamma(1e-300, 1e301) was NaN, where M is too small for the scaling at the top of bd0dd): the product and
|
|
383
|
+
* d are then taken times 2^-64 (exactly) and the sum scaled back, Infinity where that overflows
|
|
384
|
+
*/
|
|
385
|
+
function farDeviance(lr, x, d) {
|
|
386
|
+
if (x < 1e299)
|
|
387
|
+
return ddAdd(ddMulNum(lr, x), ddNeg(d));
|
|
388
|
+
return scaleUp(ddAdd(ddMulNum(lr, x * 2 ** -64), [-d[0] * 2 ** -64, -d[1] * 2 ** -64]));
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* A deviance computed times 2^-64, scaled back; [Infinity, 0] where it overflows (a finite low part beside it made
|
|
392
|
+
* the sums of its callers NaN: dgamma(1.3e27, 9.2e305, rate 0.44) was NaN)
|
|
393
|
+
*/
|
|
394
|
+
function scaleUp(r) {
|
|
395
|
+
const hi = r[0] * 2 ** 64;
|
|
396
|
+
return Number.isFinite(hi) ? [hi, r[1] * 2 ** 64] : [hi, 0];
|
|
380
397
|
}
|
|
381
398
|
/**
|
|
382
399
|
* bd0(x, n p) with n and p in double-double. Above 1e299 the splitting in the double-double product overflows, so n is
|
|
@@ -417,6 +434,20 @@ function expNegDD(e, log, logDenom, denom) {
|
|
|
417
434
|
return Math.exp(-e[0] - e[1] - 0.5 * logDenom());
|
|
418
435
|
return ((Math.exp(700 - e[0]) * (1 - e[1])) / Math.sqrt(d)) * Math.exp(-700);
|
|
419
436
|
}
|
|
437
|
+
/**
|
|
438
|
+
* n v for a double-double n that may exceed 1e299, where the splitting in ddMul overflows (dnbinom(0, 2.4e301, { prob:
|
|
439
|
+
* 1 - 2.3e-11 }) was NaN): n is then scaled by 2^-64 (exactly) and the product back
|
|
440
|
+
*/
|
|
441
|
+
function mulLarge(nn, v) {
|
|
442
|
+
if (!(nn[0] > 1e299))
|
|
443
|
+
return ddMul(nn, v);
|
|
444
|
+
return scaleUp(ddMul([nn[0] * 2 ** -64, nn[1] * 2 ** -64], v));
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* exp of a double-double log probability; 0 far below the subnormals, where the low part can exceed 1 and the first
|
|
448
|
+
* order correction would give -0
|
|
449
|
+
*/
|
|
450
|
+
const expLogDD = (l) => (l[0] < -2000 ? 0 : Math.exp(l[0]) * (1 + l[1]));
|
|
420
451
|
/**
|
|
421
452
|
* Binomial probability C(n, x) p^x q^(n-x). x and n need not be integers (used by the beta and F distributions).
|
|
422
453
|
* The caller passes q = 1 - p accurately.
|
|
@@ -451,26 +482,25 @@ export function dbinomRawDD(x, nmx, p, q, log) {
|
|
|
451
482
|
return one;
|
|
452
483
|
if (p[0] < 0.1) {
|
|
453
484
|
// n log q = -bd0(n, n q) - n p
|
|
454
|
-
const e = ddAdd(bd0Prod(n, nn, q),
|
|
455
|
-
return log ? -e[0] - e[1] :
|
|
485
|
+
const e = ddAdd(bd0Prod(n, nn, q), mulLarge(nn, p));
|
|
486
|
+
return log ? -e[0] - e[1] : expLogDD([-e[0], -e[1]]);
|
|
456
487
|
}
|
|
457
488
|
const lq = ddLog(q);
|
|
458
|
-
const lc =
|
|
459
|
-
return log ? lc[0] + lc[1] :
|
|
489
|
+
const lc = mulLarge(nn, lq);
|
|
490
|
+
return log ? lc[0] + lc[1] : expLogDD(lc);
|
|
460
491
|
}
|
|
461
492
|
if (nmx === 0) {
|
|
462
493
|
if (q[0] < 0.1) {
|
|
463
|
-
const e = ddAdd(bd0Prod(n, nn, p),
|
|
464
|
-
return log ? -e[0] - e[1] :
|
|
494
|
+
const e = ddAdd(bd0Prod(n, nn, p), mulLarge(nn, q));
|
|
495
|
+
return log ? -e[0] - e[1] : expLogDD([-e[0], -e[1]]);
|
|
465
496
|
}
|
|
466
|
-
const lc =
|
|
467
|
-
return log ? lc[0] + lc[1] :
|
|
497
|
+
const lc = mulLarge(nn, ddLog(p));
|
|
498
|
+
return log ? lc[0] + lc[1] : expLogDD(lc);
|
|
468
499
|
}
|
|
469
500
|
if (x < 0 || nmx < 0)
|
|
470
501
|
return zero;
|
|
471
502
|
// E = stirlerr(x) + stirlerr(n-x) - stirlerr(n) + bd0(x, np) + bd0(n-x, nq)
|
|
472
|
-
|
|
473
|
-
e = ddAdd(e, twoSum(stirlerr(x) + stirlerr(nmx), -stirlerr(n)));
|
|
503
|
+
const e = binomialExponent(x, nmx, nn, p, q);
|
|
474
504
|
// Denominator 2 pi x (n - x) / n
|
|
475
505
|
return expNegDD(e, log, () => LN_2PI + Math.log(x) + Math.log(nmx) - Math.log(n), () => 2 * Math.PI * x * (nmx / n));
|
|
476
506
|
}
|
|
@@ -481,9 +511,18 @@ export function dbinomRawDD(x, nmx, p, q, log) {
|
|
|
481
511
|
export function dbinomExponent(x, nmx, p, q) {
|
|
482
512
|
const nn = twoSum(x, nmx);
|
|
483
513
|
const n = nn[0];
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
514
|
+
return { e: binomialExponent(x, nmx, nn, p, q), logDenom: LN_2PI + Math.log(x) + Math.log(nmx) - Math.log(n) };
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* The exponent E = bd0(x, np) + bd0(n - x, nq) + stirlerr(x) + stirlerr(n - x) - stirlerr(n) in double-double;
|
|
518
|
+
* [Infinity, 0] where a deviance overflows (the double-double sums made it NaN: dbeta(0.998, 55.1, 6.3e307))
|
|
519
|
+
*/
|
|
520
|
+
function binomialExponent(x, nmx, nn, p, q) {
|
|
521
|
+
const d1 = bd0Prod(x, nn, p);
|
|
522
|
+
const d2 = bd0Prod(nmx, nn, q);
|
|
523
|
+
if (!Number.isFinite(d1[0] + d2[0]))
|
|
524
|
+
return [Infinity, 0];
|
|
525
|
+
return ddAdd(ddAdd(d1, d2), twoSum(stirlerr(x) + stirlerr(nmx), -stirlerr(nn[0])));
|
|
487
526
|
}
|
|
488
527
|
/** Poisson probability lambda^x e^-lambda / x!. x need not be an integer (used by the gamma distribution). */
|
|
489
528
|
export function dpoisRaw(x, lambda, log) {
|
|
@@ -505,11 +544,21 @@ function dpoisRawCore(x, lambda, wantLog, wantLin) {
|
|
|
505
544
|
if (lambda < x * DBL_MIN) {
|
|
506
545
|
if (!Number.isFinite(x))
|
|
507
546
|
return [-Infinity, 0];
|
|
508
|
-
|
|
547
|
+
// (lgamma1p(x) overflows from about 2.5e305 on, where x log(lambda) may too: the log is -Infinity, not NaN)
|
|
548
|
+
const lg = lgamma1p(x);
|
|
549
|
+
const v = lg === Infinity ? -Infinity : -lambda + x * Math.log(lambda) - lg;
|
|
509
550
|
return [v, wantLin ? Math.exp(v) : NaN];
|
|
510
551
|
}
|
|
511
|
-
const
|
|
552
|
+
const b = bd0dd(x, [lambda, 0]);
|
|
553
|
+
// (an overflowed deviance stays [Infinity, 0]: the double-double sum would make it NaN)
|
|
554
|
+
const e = b[0] === Infinity ? b : ddAdd(b, [stirlerr(x), 0]);
|
|
512
555
|
const logDenom = () => LN_2PI + Math.log(x);
|
|
513
|
-
|
|
514
|
-
|
|
556
|
+
// 2 pi x overflows above about 2.9e307: the linear value is then taken with pi x / 8 and divided by 4 (it was 0 where
|
|
557
|
+
// dchisq(1e308, 1e308) is 2.8e-155)
|
|
558
|
+
const big = x > 2e307;
|
|
559
|
+
const denom = big ? () => (Math.PI / 8) * x : () => 2 * Math.PI * x;
|
|
560
|
+
return [
|
|
561
|
+
wantLog ? expNegDD(e, true, logDenom, denom) : NaN,
|
|
562
|
+
wantLin ? expNegDD(e, false, logDenom, denom) / (big ? 4 : 1) : NaN,
|
|
563
|
+
];
|
|
515
564
|
}
|
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-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};
|
|
1
|
+
/*! rStats.js 0.15.3 | 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-NM3Z2UBQ.js";import{c as G,d as St,e as jt}from"./chunks/chunk-FKAKALOZ.js";import{A as v,H as ht,M as Dt,N 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-3TSWYE5L.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-KT66SB7R.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};
|