@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/distributions.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! rStats.js 0.15.
|
|
2
|
-
import{B as mi,a as ve,b as ke,c as cr,f as gn,g as Ue,h as Ve,i as dr,l as He,m as Ke,n as Ye,r as $e,s as ze,t as Je,u as We,v as Ze,w as Te,x as Ni,y as ci}from"./chunks/chunk-JLAH3X77.js";import{a as F,b as In,c as ei,d as qn,e as ii,f as oi,g as ui,h as si,i as fi,j as ai}from"./chunks/chunk-3WQCKGKP.js";import{a as br,b as xn}from"./chunks/chunk-YGT4P7EU.js";import{a as yn,b as Pe,c as ti,d as ri,e as ni,f as g,h as Fn,i as ft,j as J}from"./chunks/chunk-4Z2XDWKV.js";import{A as Ee,B as _e,C as lr,F as De,G as Oe,H as gt,L as Xe,M as Ce,N as je,a as cn,b as st,c as ar,d as mn,e as jt,f as qe,g as we,h as Nr,l as pn,o as Mn,p as hn,q as Re,r as Ae,s as mr,v as Le,w as Se,x as pr,y as Mr,z as hr}from"./chunks/chunk-EBQMGCQZ.js";import{a as w,b as E,c as d,d as q,e as Bt,h as dn,k as bn,q as Qe,r as Be,s as Ge}from"./chunks/chunk-UFT662QZ.js";import{a as B,b as C,c as Gt,d as dt,e as G,f as X,g as Xt,h as Ct,i as bt}from"./chunks/chunk-D4F7GQAY.js";import{E as ln,d as Qt,e as M,f as Ie,g as lt,h as ut,l as fn,n as an,s as rt,u as Nn}from"./chunks/chunk-2CUKVVRO.js";import{b as O,c as sn,d as I,f as D,g as Q,h as $,i as z,k as b}from"./chunks/chunk-LG74QY5U.js";function pi(r,n,e={}){let t=e.log??!1,i=n.length;if(r.length!==i)throw new RangeError("x and prob must have the same length");if(n.some(a=>!Number.isFinite(a)||a<0))throw new RangeError("probabilities must be finite and non-negative");if(!n.some(a=>a>0))throw new RangeError("probabilities must not all be 0");if(r.some(a=>!(a>=0)||!Number.isFinite(a)||a!==Math.round(a)))throw new RangeError("x must be non-negative integers");let o=r.reduce((a,c)=>a+c,0);if(e.size!==void 0&&e.size!==o)throw new RangeError("size must equal the sum of x");for(let a=0;a<i;a++)if(n[a]===0&&r[a]>0)return t?-1/0:0;let u=new Array(i+1).fill([0,0]),s=new Array(i+1).fill(0);for(let a=i-1;a>=0;a--)u[a]=I(u[a+1],[n[a],0]),s[a]=s[a+1]+r[a];let f=0,N=1;for(let a=0;a<i;a++){if(n[a]===0)continue;let c=u[a+1];if(c[0]===0)break;let m=z([n[a],0],u[a]),p=z(c,u[a]),h=r[a],l=s[a+1];t?f+=rt(h,l,m,p,!0):N*=rt(h,l,m,p,!1)}return t?f:N}function gr(r,n){return Number.isFinite(n-r)?1:.5}function Mi(r,n,e,t){if(Number.isNaN(r)||Number.isNaN(n)||Number.isNaN(e))return NaN;if(!(e>n))return NaN;if(r<n||r>e)return d(t);let i=gr(n,e),o=e*i-n*i;return t?-Math.log(o)+Math.log(i):i/o}function hi(r,n,e,t,i){if(Number.isNaN(r)||Number.isNaN(n)||Number.isNaN(e))return NaN;if(e<n||!Number.isFinite(n)||!Number.isFinite(e))return NaN;if(r>=e)return E(t,i);if(r<=n)return w(t,i);let o=gr(n,e),u=e*o-n*o,s=t?(r*o-n*o)/u:(e*o-r*o)/u;return i?Math.log(s):s}function li(r,n,e,t,i){if(Number.isNaN(r)||Number.isNaN(n)||Number.isNaN(e))return NaN;if(e<n||!Number.isFinite(n)||!Number.isFinite(e))return NaN;let o=q(r,n,e,t,i);if(Number.isNaN(o))return NaN;if(e===n)return n;if(o!==void 0)return o;let u=gr(n,e)!==1,s=N=>u?(1-N)*n+N*e:n+N*(e-n),f=i?Math.exp(r):r;return t?s(f):f<.5?u?f*n+(1-f)*e:e-f*(e-n):s(i?-Math.expm1(r):.5-r+.5)}function di(r,n={}){let{min:e=0,max:t=1,log:i=!1}=n;return M(r,o=>Mi(o,e,t,i))}function bi(r,n={}){let{min:e=0,max:t=1,lowerTail:i=!0,logP:o=!1}=n;return M(r,u=>hi(u,e,t,i,o))}function gi(r,n={}){let{min:e=0,max:t=1,lowerTail:i=!0,logP:o=!1}=n;return M(r,u=>li(u,e,t,i,o))}var xi=2**-1022;function yi(r,n,e){if(Number.isNaN(r)||Number.isNaN(n))return NaN;if(n<0||n===1/0)return NaN;if(r<0)return d(e);let t=dt(n,r);if(Number.isNaN(t[0]))return NaN;if(e)return Math.log(n)-t[0]-t[1];let i=G(t);if(i<xi&&n>1&&t[0]<1500){let o=D(b([n,0]),t);return o[0]<-746?0:B(o)[0]}return n*i}function Fi(r,n,e){if(!n)return e?-r[0]-r[1]:G(r);let t=r[0]+r[1];return e?Xt(r):-Math.expm1(-t)}function Ii(r,n,e,t){if(Number.isNaN(r)||Number.isNaN(n))return NaN;if(n<0)return NaN;if(r<=0)return w(e,t);let i=dt(n,r);return Number.isNaN(i[0])?NaN:i[0]===1/0?E(e,t):Fi(i,e,t)}function qi(r,n,e,t){if(Number.isNaN(r)||Number.isNaN(n))return NaN;if(n<0)return NaN;let i=q(r,0,1/0,e,t);if(Number.isNaN(i)||i===0)return i;let o;return t?o=e?X(r):r:o=e?Math.log1p(-r):Math.log(r),-o/n}function wi(r,n={}){let{rate:e=1,log:t=!1}=n;return M(r,i=>yi(i,e,t))}function vi(r,n={}){let{rate:e=1,lowerTail:t=!0,logP:i=!1}=n;return M(r,o=>Ii(o,e,t,i))}function ki(r,n={}){let{rate:e=1,lowerTail:t=!0,logP:i=!1}=n;return M(r,o=>qi(o,e,t,i))}var Ri=.9189385332046728,Ai=.3989422804014327,Li=2**-1022,Si=[.9189385332046728,-38782941580672414e-33];function vn(r,n,e){let t=D(b([r,0]),[n,0]);if(e===1)return t;let i=t[0]/e;return Number.isFinite(i)&&Math.abs(i)<1e300?z(t,[e,0]):[i,0]}function Ut(r){if(Math.abs(r[0])>1e150)return[r[0]*r[0]/2,0];let n=Q(r,r);return[n[0]/2,n[1]/2]}function Ei(r,n){if(r[0]>-Math.SQRT2){if(r[0]<Math.SQRT2)return lt(r[0]+r[1],{logP:n});let e=wn(r[0],[r[0],r[1]],!1);return n?Math.log1p(-e):1-e}return wn(-r[0],[-r[0],-r[1]],n)}function wn(r,n,e){let t=.5*Qt(r*Math.SQRT1_2),i=Ut(n);return e?Math.log(t)-i[0]-i[1]:t*G(i)}var xr=2.5066282746310007;function _i(r,n,e,t){let i=e?r:-r,o,u=(s,f,N)=>-f[0]-N[0]+(-f[1]-N[1])+Math.log(s);if(i<=-Math.SQRT2){let s=.5*Qt(-i*Math.SQRT1_2),f=t?[n,0]:b([n,0]);o=-u(s,Ut([-i,0]),f)*xr*s}else if(i>=Math.SQRT2){let s=.5*Qt(i*Math.SQRT1_2),f=t?-Math.expm1(n):1-n;o=u(s,Ut([i,0]),b([f,0]))*xr*s}else{let s=lt(i),f=Math.exp(-i*i/2)/xr;o=((t?Math.exp(n):n)-s)/f}return Number.isFinite(o)?O(r,e?o:-o):[r,0]}function Di(r,n,e,t){if(Number.isNaN(r)||Number.isNaN(n)||Number.isNaN(e))return NaN;if(e<0)return NaN;if(r<=0)return d(t);if(e===0)return Math.log(r)===n?1/0:d(t);if(!Number.isFinite(r)||!Number.isFinite(n)||!Number.isFinite(e)){let f=(Math.log(r)-n)/e;return Number.isNaN(f)?NaN:d(t)}let i=vn(r,n,e),o=Ut(i),u=()=>I(I(o,Si),I(b([r,0]),b([e,0])));if(t){if(!(o[0]<1e300))return-(Ri+o[0]+o[1]+Math.log(e)+Math.log(r));let f=u();return-(f[0]+f[1])}let s=G(o);if(s===0)return 0;if(s<Li){let f=u();return f[0]>746?0:B([-f[0],-f[1]])[0]}return Ai*s/e/r}function Oi(r,n,e,t,i){if(Number.isNaN(r)||Number.isNaN(n)||Number.isNaN(e))return NaN;if(e<0)return NaN;if(r<=0)return w(t,i);if(e===0||!Number.isFinite(r)||!Number.isFinite(n)||!Number.isFinite(e))return lt(Math.log(r),{mean:n,sd:e,lowerTail:t,logP:i});let o=vn(r,n,e);return Ei(t?o:[-o[0],-o[1]],i)}function Qi(r,n,e,t,i){if(Number.isNaN(r)||Number.isNaN(n)||Number.isNaN(e))return NaN;let o=ut(r,{lowerTail:t,logP:i});if(!Number.isFinite(o)||!(e>0)||!Number.isFinite(e)||!Number.isFinite(n))return Math.exp(ut(r,{mean:n,sd:e,lowerTail:t,logP:i}));let u=_i(o,r,t,i),s=I(I(dt(e,u[0]),[e*u[1],0]),[n,0]);return Math.abs(s[0])<750?Math.exp(s[0])*(1+s[1]):Math.exp(s[0])}function Bi(r,n={}){let{meanlog:e=0,sdlog:t=1,log:i=!1}=n;return M(r,o=>Di(o,e,t,i))}function Gi(r,n={}){let{meanlog:e=0,sdlog:t=1,lowerTail:i=!0,logP:o=!1}=n;return M(r,u=>Oi(u,e,t,i,o))}function Xi(r,n={}){let{meanlog:e=0,sdlog:t=1,lowerTail:i=!0,logP:o=!1}=n;return M(r,u=>Qi(u,e,t,i,o))}function Ci(r,n,e,t){if(Number.isNaN(r)||Number.isNaN(n)||Number.isNaN(e))return NaN;if(!(e>0))return NaN;let i=C(r,n,e);if(Number.isNaN(i[0]))return NaN;let o=i[0]<0?[-i[0],-i[1]]:[i[0],i[1]],u=G(o);return t?-o[0]-o[1]-Math.log(e)-2*Math.log1p(u):u/(e*(1+u)*(1+u))}function ji(r,n,e,t,i){if(Number.isNaN(r)||Number.isNaN(n)||Number.isNaN(e))return NaN;if(!(e>0))return NaN;let o=C(r,n,e);if(Number.isNaN(o[0]))return NaN;let u=o[0]<0?[-o[0],-o[1]]:[o[0],o[1]],s=G(u);return t===o[0]>=0?i?-Math.log1p(s):1/(1+s):i?-u[0]-u[1]-Math.log1p(s):s/(1+s)}function Ui(r,n){return n?r-X(r):r<.25?Math.log(r/(1-r)):Math.log1p((2*r-1)/(1-r))}function Vi(r,n,e,t,i){if(Number.isNaN(r)||Number.isNaN(n)||Number.isNaN(e))return NaN;let o=q(r,-1/0,1/0,t,i);if(o!==void 0)return o;if(e<0)return NaN;if(e===0)return n;let u=Ui(r,i);return Ct(n,e,t?u:-u)}function Hi(r,n={}){let{location:e=0,scale:t=1,log:i=!1}=n;return M(r,o=>Ci(o,e,t,i))}function Ki(r,n={}){let{location:e=0,scale:t=1,lowerTail:i=!0,logP:o=!1}=n;return M(r,u=>ji(u,e,t,i,o))}function Yi(r,n={}){let{location:e=0,scale:t=1,lowerTail:i=!0,logP:o=!1}=n;return M(r,u=>Vi(u,e,t,i,o))}function Fr(r,n){return r===1?1:Math.pow(r,n)}var Vt=2**-1022;function Rn(r,n){if(n===1)return b([r,0]);let e=r/n;return e>=Vt&&e<1/0&&r<1e300?b(C(r,0,n)):D(b([r,0]),b([n,0]))}function yr(r,n){let e=r[0]*n;return n<1e300&&Number.isFinite(e)?$(r,n):[e,0]}function kn(r,n){let e=r/n;return e>=Vt&&e<1/0?Math.log(e):Math.log(r)-Math.log(n)}function Ir(...r){return r.every(Number.isFinite)}function qr(r,n,e,t){if(Number.isNaN(r)||Number.isNaN(n)||Number.isNaN(e))return NaN;if(!(n>0)||!(e>0))return NaN;if(r<0||r===1/0)return d(t);if(r===0&&n<1)return 1/0;if(!Ir(n,e)){let f=Fr(r/e,n-1),N=f*(r/e);return t?-N+Math.log(n*f/e):n*f*Math.exp(-N)/e}if(r===0)return n>1?d(t):t?-Math.log(e):1/e;let i=Rn(r,e),o=B(yr(i,n));if(o[0]===1/0)return d(t);let u=D(n===1?[0,0]:yr(i,n-1),o),s=n/e;return t?kn(n,e)+u[0]+u[1]:u[0]<-2500?0:s>=Vt&&s<1/0&&u[0]>-708?s*Math.exp(u[0])*(1+u[1]):Math.exp(kn(n,e)+u[0])*(1+u[1])}function $i(r,n,e,t,i){if(Number.isNaN(r)||Number.isNaN(n)||Number.isNaN(e))return NaN;if(!(n>0)||!(e>0))return NaN;if(r<=0)return w(t,i);let o;if(Ir(r,n,e)){let s=yr(Rn(r,e),n);if(o=B(s),t&&i&&s[0]<-700)return o[0]===0?-1/0:s[0]+s[1]}else if(o=[Fr(r/e,n),0],Number.isNaN(o[0]))return NaN;if(!t)return i?-o[0]-o[1]:G(o);let u=o[0]+o[1];return i?Xt(o):-Math.expm1(-u)}function zi(r,n,e,t,i){if(Number.isNaN(r)||Number.isNaN(n)||Number.isNaN(e))return NaN;if(!(n>0)||!(e>0))return NaN;let o=q(r,0,1/0,t,i);if(o!==void 0)return o;let u;i?u=t?X(r):r:u=t?Math.log1p(-r):Math.log(r);let s=Fr(-u,1/n);return s>=Vt&&s<1/0||!Ir(n,e)||s===1?e*s:Math.exp(Math.log(e)+Math.log(-u)/n)}function Ji(r,n,e={}){let{scale:t=1,log:i=!1}=e;return M(r,o=>qr(o,n,t,i))}function Wi(r,n,e={}){let{scale:t=1,lowerTail:i=!0,logP:o=!1}=e;return M(r,u=>$i(u,n,t,i,o))}function wr(r,n,e={}){let{scale:t=1,lowerTail:i=!0,logP:o=!1}=e;return M(r,u=>zi(u,n,t,i,o))}function Ht(r){return r<=.5?{pd:[r,0],qd:O(1,-r)}:{pd:O(1,-(1-r)),qd:[1-r,0]}}function An(r,n,e,t){if(r<1e290)return rt(0,r,n,e,t);let i=Q([r/2**64,0],$(b(e),2**64));return i[0]>-1/0?t?i[0]+i[1]:Math.exp(i[0])*(1+i[1]):t?-1/0:0}function kr(r){return!(r>0)||r>1}function Zi(r,n,e){if(Number.isNaN(r)||Number.isNaN(n))return NaN;if(kr(n))return NaN;if(bt(r)||r<0||!Number.isFinite(r))return d(e);let t=Math.round(r),{pd:i,qd:o}=Ht(n),u=An(t,i,o,e);return e?Math.log(n)+u:n*u}function vr(r,n,e){let{pd:t,qd:i}=Ht(n);return An(r+1,t,i,e)}function Ti(r,n,e,t){if(!e)return vr(r,n,t);let i=vr(r,n,!0);return t?i<-Math.LN2?Math.log1p(-vr(r,n,!1)):Math.log(-Math.expm1(i)):-Math.expm1(i)}function Pi(r,n,e,t){return Number.isNaN(r)||Number.isNaN(n)?NaN:kr(n)?NaN:r<0?w(e,t):!Number.isFinite(r)||n===1?E(e,t):Ti(Math.floor(r+1e-7),n,e,t)}function to(r,n,e,t){if(Number.isNaN(r)||Number.isNaN(n))return NaN;if(kr(n))return NaN;let i=q(r,0,1/0,e,t);if(Number.isNaN(i))return NaN;if(n===1)return 0;if(i!==void 0)return i;let o;return t?o=e?X(r):r:o=e?Math.log1p(-r):Math.log(r),Math.max(0,Math.ceil(o/Math.log1p(-n)-1-1e-12))}function ro(r,n,e={}){let t=e.log??!1;return M(r,i=>Zi(i,n,t))}function no(r,n,e={}){let{lowerTail:t=!0,logP:i=!1}=e;return M(r,o=>Pi(o,n,t,i))}function Rr(r,n,e={}){let{lowerTail:t=!0,logP:i=!1}=e;return M(r,o=>to(o,n,t,i))}function Ar(r,n){let e=O(r,n);return{size:r,pd:z([r,0],e),qd:z([n,0],e)}}function Lr(r,n){return{size:r,...Ht(n)}}function Sr(r,n,e){let{size:t,pd:i,qd:o}=n,u=rt(t,r,i,o,e);if(r===0)return u;let s=t/(t+r);return e?u+Math.log(s):u*s}function xt(r,n,e,t){let i=eo(r,n);return i!==void 0?e?t?Math.log1p(-i):1-i:t?Math.log(i):i:bn(n.size,r+1,n.pd,n.qd,e,t)}function eo(r,n){let{size:e,pd:t,qd:i}=n,o=i[0]+i[1],u=t[0]+t[1];if(!(e<=1)||!(o>=.95)||u<1e-4)return;let s=r+1,f=e,N=dn(s,f,i,t),a=N!==void 0?N[0]*(Math.exp(N[1][0])*(1+N[1][1]))/s:rt(s,f,i,t,!1)*f/(s+f);if(!(a>1e-290))return;let c=O(s,f),m=[1,0],p=[1,0];for(let h=0;h<1e6;h++){let l=z(I(c,[h,0]),[s+1+h,0]);if(m=Q(Q(m,l),i),p=I(p,m),m[0]<1e-18*p[0]*u){let y=a*(p[0]+p[1]);return y<=.5?y:void 0}}}function Ln(r,n,e,t){let i=n.pd[0]+n.pd[1],o=1/i,u=(n.qd[0]+n.qd[1])*o,s=n.size*u,f=Math.sqrt(n.size*u*o),N=(o+u)/f,a;if(i<.05){let m=jt(r,n.size,1,e,t);if(a=m/Math.log1p(i/(n.qd[0]+n.qd[1])),a===1/0&&m>0&&Number.isFinite(m))return 1/0}else{let m=ut(r,{lowerTail:e,logP:t});a=s+f*(m+N*(m*m-1)/6)}let c=Number.isFinite(a)?Math.max(a,0):Number.isFinite(s)?s:0;return c>1e4&&(c=io(c,r,n,e,t)),pn({p:r,lowerTail:e,logP:t,cdf:(m,p,h)=>xt(m,n,p,h),y0:c,lo:0,hi:1/0})}function io(r,n,e,t,i){let o=Number.EPSILON,u=n;i?u=t?n*(1+2*o):n*(1-2*o):t?u=n*(1-8*o):1-n>32*o&&(u=n*(1+8*o));let s=i?u:Math.log(u),f=s<=-Math.LN2?t:!t,N=s<=-Math.LN2?s:i?Math.log(-Math.expm1(u)):Math.log1p(-u),a=r,c=xt(a,e,f,!0)-N,m=NaN,p=NaN;for(let h=0;h<8&&c!==0;h++){let l;if(Number.isNaN(m)||c===p){let y=(f?1:-1)*Math.exp(Sr(a,e,!0)-(c+N));l=a-c/y}else l=a-c*(a-m)/(c-p);if(!Number.isFinite(l)||l<=0)break;if(Math.abs(l-a)<.5)return l;m=a,p=c,a=l,c=xt(a,e,f,!0)-N}return a}function oo(r,n,e,t){if(Number.isNaN(r)||Number.isNaN(n)||Number.isNaN(e))return NaN;if(n<0||!(e>0)||e>1)return NaN;if(bt(r)||r<0||!Number.isFinite(r))return d(t);let i=Math.round(r);return n===0||e===1?i===0?t?0:1:d(t):n===1/0?d(t):Sr(i,Lr(n,e),t)}function uo(r,n,e,t,i){return Number.isNaN(r)||Number.isNaN(n)||Number.isNaN(e)?NaN:n<0||!(e>0)||e>1||n===1/0?NaN:r<0?w(t,i):n===0||e===1||!Number.isFinite(r)?E(t,i):xt(Math.floor(r+1e-7),Lr(n,e),t,i)}function so(r,n,e,t,i){if(Number.isNaN(r)||Number.isNaN(n)||Number.isNaN(e))return NaN;if(n<0||e<0||e>1)return NaN;if(e===1||n===0)return 0;if(e===0)return NaN;let o=q(r,0,1/0,t,i);return o!==void 0?o:n===1/0?1/0:Ln(r,Lr(n,e),t,i)}function fo(r,n,e,t){if(Number.isNaN(r)||Number.isNaN(n)||Number.isNaN(e))return NaN;if(n<0||e<0)return NaN;if(bt(r)||r<0||!Number.isFinite(r))return d(t);let i=Math.round(r);return n===0?i===0?t?0:1:e===0?NaN:d(t):e===1/0?d(t):n===1/0?Nn(i,e,t):e===0?i===0?t?0:1:d(t):Sr(i,Ar(n,e),t)}function ao(r,n,e,t,i){return Number.isNaN(r)||Number.isNaN(n)||Number.isNaN(e)?NaN:n<0||e<0||e===1/0?NaN:r<0?w(t,i):n===0||e===0||!Number.isFinite(r)?E(t,i):n===1/0?Mn(r,e,t,i):xt(Math.floor(r+1e-7),Ar(n,e),t,i)}function No(r,n,e,t,i){if(Number.isNaN(r)||Number.isNaN(n)||Number.isNaN(e))return NaN;if(n===1/0)return hn(r,e,t,i);if(n===0||e===0)return 0;if(n<0||e<0)return NaN;if(e===1/0)return q(r,0,1/0,t,i)??NaN;let o=q(r,0,1/0,t,i);return o!==void 0?o:Ln(r,Ar(n,e),t,i)}function Er(r){let{prob:n,mu:e}=r;if(n!==void 0&&e!==void 0)throw new TypeError("specify exactly one of prob and mu");if(n!==void 0)return{kind:"prob",v:n};if(e!==void 0)return{kind:"mu",v:e};throw new TypeError("specify exactly one of prob and mu")}function co(r,n,e){let t=e.log??!1,i=Er(e);return i.kind==="prob"?M(r,o=>oo(o,n,i.v,t)):M(r,o=>fo(o,n,i.v,t))}function mo(r,n,e){let{lowerTail:t=!0,logP:i=!1}=e,o=Er(e);return o.kind==="prob"?M(r,u=>uo(u,n,o.v,t,i)):M(r,u=>ao(u,n,o.v,t,i))}function _r(r,n,e){let{lowerTail:t=!0,logP:i=!1}=e,o=Er(e);return o.kind==="prob"?M(r,u=>so(u,n,o.v,t,i)):M(r,u=>No(u,n,o.v,t,i))}var Dr=(r,n)=>r>0&&n>0&&Number.isFinite(n),yt=2**-1022,Sn=1e15;function po(r,n,e,t){if(Number.isNaN(r)||!Dr(n,e))return NaN;if(r<=0||r===1/0)return d(t);if(n===1/0)return NaN;let[i,o]=C(e,0,r);if(i===1/0)return d(t);if(i<yt){let N=Gt(e,r),a=I(D(n<1e300?$(N,n):[N[0]*n,0],b([r,0])),[-an(n),0]);return t?a[0]+a[1]:a[0]<-746?0:B(a)[0]}let u=Number.isFinite(o)&&n<=Sn?n*(o/i)-o:0,s=()=>{let N=st(i,n,1,!1),a=N*i;return N>=yt&&a>=yt?a/r:void 0};if(t){let N=st(i,n,1,!0),a=N+Math.log(i)-Math.log(r)+u;if(!(Math.abs(a)<.5*Math.abs(N)))return a;let c=s();return c!==void 0&&c>=yt&&c<1/0?Math.log(c)+u:a}let f=s();return f===void 0?Math.exp(st(i,n,1,!0)+Math.log(i)-Math.log(r)+u):f*(1+u)}function Mo(r,n,e,t,i){if(Number.isNaN(r)||!Dr(n,e))return NaN;if(r<=0)return w(t,i);if(r===1/0||n===1/0)return E(t,i);let[o,u]=C(e,0,r);if(o<yt)return ar(e,n,r,!t,i);let s=ar(o,n,1,!t,i);if(!(u!==0&&Number.isFinite(u)&&Number.isFinite(o)&&n<=Sn))return s;let f=t?-1:1;if(!i)return s+f*st(o,n,1,!1)*u;if(!(Math.abs(s)<1e8))return s;let N=f*Math.exp(st(o,n,1,!0)-s)*u;return Number.isFinite(N)?s+N:s}function ho(r,n,e,t,i){if(Number.isNaN(r)||!Dr(n,e))return NaN;let o=q(r,0,1/0,t,i);if(o!==void 0)return o;if(n===1/0)return 0;let{lower:u,logTarget:s,linearTarget:f}=Bt(r,!t,i),N=mn(s,u,n,f);return N!==void 0?Math.log(e)-N[0]>710?1/0:B(D(b([e,0]),N))[0]:e/jt(r,n,1,!t,i)}function lo(r,n,e={}){let{beta:t=1,log:i=!1}=e;return M(r,o=>po(o,n,t,i))}function bo(r,n,e={}){let{beta:t=1,lowerTail:i=!0,logP:o=!1}=e;return M(r,u=>Mo(u,n,t,i,o))}function Or(r,n,e={}){let{beta:t=1,lowerTail:i=!0,logP:o=!1}=e;return M(r,u=>ho(u,n,t,i,o))}var Br=(r,n)=>r>0&&n>0&&Number.isFinite(n),H=22250738585072014e-324,En=(r,n,e)=>-Math.sign(e)*Math.exp(Math.log(Math.abs(e))+n*Math.log(r)),Gr=(r,n)=>r<1&&-(n*Math.log(r))<H;function _n(r,n){let e=Math.pow(r,n);return e<.5?Math.log1p(-e):Gr(r,n)?Math.log(n)+Math.log(-Math.log(r)):Math.log(-Math.expm1(n*Math.log(r)))}function Qr(r,n,e){let t=Math.pow(r,n);if(t>=.5){if(!Gr(r,n))return Math.pow(-Math.expm1(n*Math.log(r)),e);let s=Math.pow(n*2**600*-Math.log(r),e)*Math.pow(2,-600*e);return s>=H&&s<1/0?s:Math.exp(e*(Math.log(n)+Math.log(-Math.log(r))))}let i=1-t,o=1-i-t,u=e*o/i;return Math.abs(u)<1e-8?Math.pow(i,e)*(1+u):Math.exp(e*Math.log1p(-t))}var go=(r,n)=>r===0?0:r*Math.log(n);function xo(r,n,e,t,i){if(r===0||!(n<1e300)||!(e<1e300))return Math.log(n)+Math.log(e)+go(n-1,r)+t;let o=b([r,0]),u=I(b([n,0]),b([e,0]));if(n!==1&&(u=I(u,Q(o,O(n,-1)))),e===1||r===1||i<H){if(!Number.isFinite(t))return u[0]+t;let N=I(u,[t,0]);return N[0]+N[1]}let s=i<=1e-10?[Math.log1p(-i),0]:Gr(r,n)?I(b([n,0]),b([-o[0],-o[1]])):b(D([1,0],B(Q(o,[n,0])))),f=I(u,Q(s,O(e,-1)));return f[0]+f[1]}function Xr(r,n,e,t){if(Number.isNaN(r)||!Br(n,e))return NaN;if(r<0||r>1)return d(t);if(n===1/0)return r===1?1/0:d(t);let i=Math.pow(r,n),o=r>0&&i<H,u=r===1?-1/0:_n(r,n),s=e===1?0:o?En(r,n,e-1):(e-1)*u,f=xo(r,n,e,s,i);if(t)return f;let N=n===1?1:i>1e-290?i/r:Math.pow(r,n-1);if(r>0&&N<H)return Math.exp(f);let a=n*e,c=a*N,m=e===1||r===0?1:o?Math.exp(s):Qr(r,n,e-1),p=c*m;return a>=H&&c>=H&&m>=H&&p>H&&p<1/0?p:Math.exp(f)}function Cr(r,n,e,t,i){if(Number.isNaN(r)||!Br(n,e))return NaN;if(r<=0)return w(t,i);if(r>=1)return E(t,i);if(n===1/0)return w(t,i);let o=Math.pow(r,n),u=o<H,s=u?En(r,n,e):e*_n(r,n);return t?i?Math.max(e,1)*o<1e-10?Math.log(e)+n*Math.log(r)+Math.log1p(-(e-1)*o/2):s<-Math.LN2&&!u?Math.log1p(-Qr(r,n,e)):X(s):-Math.expm1(s):i?s:u?Math.exp(s):Qr(r,n,e)}function Ft(r,n,e,t,i){if(Number.isNaN(r)||!Br(n,e))return NaN;let o=q(r,0,1,t,i);if(o!==void 0)return o;if(n===1/0)return 1;let u=t?i?X(r):Math.log1p(-r):i?r:Math.log(r),s=u/e;if(!(s<=-H))return Math.exp((Math.log(-u)-Math.log(e))/n);if(s<-Math.LN2)return Math.exp(Math.log1p(-Math.exp(s))/n);let f=-Math.expm1(s),N=1/n;if(!(n<1e300))return Math.pow(f,N);let[a,c]=sn(n,N);return Math.pow(f,N)*(1+Math.log(f)*(1-a-c)/n)}function yo(r,n,e,t={}){let{log:i=!1}=t;return M(r,o=>Xr(o,n,e,i))}function Fo(r,n,e,t={}){let{lowerTail:i=!0,logP:o=!1}=t;return M(r,u=>Cr(u,n,e,i,o))}function jr(r,n,e,t={}){let{lowerTail:i=!0,logP:o=!1}=t;return M(r,u=>Ft(u,n,e,i,o))}var Ur=(r,n)=>r>0&&n>0&&Number.isFinite(n),W=2**-1022;function On(r,n){if(r<1e308){let[t,i]=C(r,0,n);if(t<1/0){let o=i/t;return[t,o,Math.log(t)+o]}}let e=Gt(r,n);return[1/0,0,e[0]+e[1]]}function Dn(r,n,[e,t,i],o){let u=o*t;if(Math.abs(u)<1e-8){let s=e<1/0?Math.pow(e,-o):Math.pow(r,-o),f=e<1/0?1:Math.pow(n,o);if(s>=W&&f>=W&&f<1/0&&s*f>=W)return s*f*(1-u)}return Math.exp(-o*i)}function Io(r,n,e,t){if(Number.isNaN(r)||!Ur(n,e))return NaN;if(r<e||r===1/0)return d(t);if(n===1/0)return r===e?1/0:d(t);let[i,o,u]=On(r,e),s=n/e,f=s>=W&&s<1/0?Math.log(s):Math.log(n)-Math.log(e),N=f-(n+1)*u,a=()=>{if(!(s<1/0&&Math.abs(n*o)<1e-8))return 0;let m=Math.pow(i,-n),p=m>=W?0:Math.pow(i,-n/2);return m>=W?s*m/i:p>=W?s*p/i*p:0};if(t){if(!(Math.abs(N)<.5*Math.abs(f)))return N;let m=a();return m>=W&&m<1/0?Math.log(m)+Math.log1p(-(n+1)*o):N}let c=a();return c>=W&&c<1/0?c*(1-(n+1)*o):Math.exp(N)}function qo(r,n,e,t,i){if(Number.isNaN(r)||!Ur(n,e))return NaN;if(r<=e)return w(t,i);if(r===1/0||n===1/0)return E(t,i);let o=On(r,e),u=-n*o[2];return t?i?u<-Math.LN2?Math.log1p(-Dn(r,e,o,n)):X(u):-Math.expm1(u):i?u:Dn(r,e,o,n)}function Vr(r,n,e,t,i){if(Number.isNaN(r)||!Ur(n,e))return NaN;let o=q(r,e,1/0,t,i);if(o!==void 0)return o;if(n===1/0)return e;let s=-(t?i?X(r):Math.log1p(-r):i?r:Math.log(r))/n,f=Math.exp(s);return f<1/0?e*f:Math.exp(Math.log(e)+s)}function wo(r,n={}){let{a:e=1,b:t=1,log:i=!1}=n;return M(r,o=>Io(o,e,t,i))}function vo(r,n={}){let{a:e=1,b:t=1,lowerTail:i=!0,logP:o=!1}=n;return M(r,u=>qo(u,e,t,i,o))}function ko(r,n={}){let{a:e=1,b:t=1,lowerTail:i=!0,logP:o=!1}=n;return M(r,u=>Vr(u,e,t,i,o))}var Hr=(r,n,e)=>Number.isFinite(r)&&Number.isFinite(n)&&r<n&&r<=e&&e<=n,Kr=(r,n)=>Number.isFinite(n-r)?1:.5;function Qn(r,n,e,t,i){if(Number.isNaN(r)||!Hr(n,e,t))return NaN;if(r<n||r>e)return d(i);let o=Kr(n,e);if(o!==1){let N=Qn(r*o,n*o,e*o,t*o,i);return i?N+Math.log(o):N*o}let u=e-n,s=r===t?0:r<t?(t-r)/(t-n):(r-t)/(e-t);if(s<.5)return i?Math.LN2-Math.log(u)+Math.log1p(-s):2*(1-s)/u;let f=r<t?(r-n)/(t-n):(e-r)/(e-t);return i?Math.LN2-Math.log(u)+Math.log(f):2*f/u}function Ro(r,n,e,t){let i=e-n;if(r<=t){let[s,f]=[(r-n)/(t-n),(r-n)/i];return[s*f,(e-t)/i+(t-r)/(t-n)*(f+(t-n)/i),Math.log(s)+Math.log(f)]}let[o,u]=[(e-r)/(e-t),(e-r)/i];return[(t-n)/i+(r-t)/(e-t)*(u+(e-t)/i),o*u,Math.log(o)+Math.log(u)]}function Ao(r,n,e,t,i,o){if(Number.isNaN(r)||!Hr(n,e,t))return NaN;if(r<=n)return w(i,o);if(r>=e)return E(i,o);let u=Kr(n,e),[s,f,N]=Ro(r*u,n*u,e*u,t*u),a=Math.min(i?s:f,1);return o?a>.5?Math.log1p(-(i?f:s)):a<2**-1022&&i===r<=t?N:Math.log(a):a}function Bn(r,n,e,t,i,o){if(Number.isNaN(r)||!Hr(n,e,t))return NaN;let u=q(r,n,e,i,o);if(u!==void 0)return u;let s=Kr(n,e);if(s!==1)return Bn(r,n*s,e*s,t*s,i,o)/s;let f=e-n,N=o?Math.exp(r):r,a=o&&N<2**-1022?Math.exp(r/2):Math.sqrt(N),c=i?N:o?-Math.expm1(r):1-r,m=i?o?-Math.expm1(r):1-r:N,p=(t-n)/f,h=(e-t)/f,l;if(p>0&&c<=p){let y=c/(t-n)*f;l=y<=.5?n+(i?a:Math.sqrt(c))*Math.sqrt(f)*Math.sqrt(t-n):t-(t-n)*((m-h)/p)/(1+Math.sqrt(y))}else{let y=m/(e-t)*f;l=y<=.5?e-(i?Math.sqrt(m):a)*Math.sqrt(f)*Math.sqrt(e-t):t+(e-t)*((c-p)/h)/(1+Math.sqrt(y))}return Math.min(Math.max(l,n),e)}function Lo(r,n={}){let{a:e=-1,b:t=1,log:i=!1}=n,o=n.c??(e+t)/2;return M(r,u=>Qn(u,e,t,o,i))}function So(r,n={}){let{a:e=-1,b:t=1,lowerTail:i=!0,logP:o=!1}=n,u=n.c??(e+t)/2;return M(r,s=>Ao(s,e,t,u,i,o))}function Yr(r,n={}){let{a:e=-1,b:t=1,lowerTail:i=!0,logP:o=!1}=n,u=n.c??(e+t)/2;return M(r,s=>Bn(s,e,t,u,i,o))}var $r=(r,n)=>!Number.isNaN(r)&&n>0&&Number.isFinite(n);function Eo(r,n,e,t){if(Number.isNaN(r)||!$r(n,e))return NaN;if(!Number.isFinite(n))return t?-1/0:0;let i=C(r,n,e),o=i[0]<0?[-i[0],-i[1]]:[i[0],i[1]];return t?-o[0]-o[1]-Math.log(2*e):G(o)/(2*e)}function _o(r,n,e,t,i){if(Number.isNaN(r)||!$r(n,e))return NaN;if(!Number.isFinite(n)){let f=n===1/0?0:1,N=t?f:1-f;return i?Math.log(N):N}let o=C(r,n,e),u=o[0]<0?[-o[0],-o[1]]:[o[0],o[1]],s=G(u)/2;return t===o[0]<0?i?-u[0]-u[1]-Math.LN2:s:i?Math.log1p(-s):1-s}function Do(r,n,e,t,i){if(Number.isNaN(r)||!$r(n,e))return NaN;let o=q(r,-1/0,1/0,t,i);if(o!==void 0)return o;if(!Number.isFinite(n))return n;let{lower:u,logTarget:s,linearTarget:f}=Bt(r,t,i),N=f!==void 0?Math.log(2*f):Math.LN2+s;return Ct(n,e,u?N:-N)}function Oo(r,n={}){let{mu:e=0,sigma:t=1,log:i=!1}=n;return M(r,o=>Eo(o,e,t,i))}function Qo(r,n={}){let{mu:e=0,sigma:t=1,lowerTail:i=!0,logP:o=!1}=n;return M(r,u=>_o(u,e,t,i,o))}function Bo(r,n={}){let{mu:e=0,sigma:t=1,lowerTail:i=!0,logP:o=!1}=n;return M(r,u=>Do(u,e,t,i,o))}var Jr=(r,n)=>Number.isFinite(r)&&Number.isFinite(n)&&r<n;function Go(r,n,e,t){if(Number.isNaN(r)||!Jr(n,e))return NaN;if(r<n||r>e)return d(t);if(r===n||r===e)return 1/0;if(!t)return 1/(Math.PI*Math.sqrt(r-n)*Math.sqrt(e-r));let i=I(b(O(r,-n)),b(O(e,-r)));return-Kt[0]-.5*i[0]-(Kt[1]+.5*i[1])}var Kt=[1.1447298858494002,10265951162707826e-33],zr=[Math.LN2-Kt[0],23190468138462996e-33-Kt[1]],Xo=[-zr[0],-zr[1]],Co=1e-20,jo=2**-1022;function Uo(r,n,e,t,i){if(Number.isNaN(r)||!Jr(n,e))return NaN;if(r<=n)return w(t,i);if(r>=e)return E(t,i);let o=e-n,u=r-n<=e-r,s=u?r-n:e-r,f=s/o;if(f<Co){let N=I(zr,$(D(b([s,0]),b([o,0])),.5)),a=Math.sqrt(s)/Math.sqrt(o)*(2/Math.PI),c=a>=jo?a:Math.exp(N[0]);return t===u?i?N[0]+N[1]:c:i?Math.log1p(-c):1-c}return u?Mr(f,.5,.5,t,i):Mr(f,.5,.5,!t,i)}function Wr(r,n,e,t,i){if(Number.isNaN(r)||!Jr(n,e))return NaN;let o=q(r,n,e,t,i);if(o!==void 0)return o;let u=i?[r,0]:b([r,0]),s=i?r>-Math.LN2?b([-Math.expm1(r),0]):[Math.log1p(-Math.exp(r)),0]:r>=.5?b([1-r,0]):[Math.log1p(-r),0],[f,N]=t?[u,s]:[s,u];for(let[c,m]of[[f,!0],[N,!1]]){if(!(c[0]<-40))continue;let p=I($(I(c,Xo),2),b([e-n,0])),h=p[0]<-746?0:B(p)[0];return m?Math.min(n+h,e):Math.max(e-h,n)}let a=hr(r,.5,.5,t,i);return a<=.5?n+(e-n)*a:e-(e-n)*hr(r,.5,.5,!t,i)}function Vo(r,n={}){let{a:e=0,b:t=1,log:i=!1}=n;return M(r,o=>Go(o,e,t,i))}function Ho(r,n={}){let{a:e=0,b:t=1,lowerTail:i=!0,logP:o=!1}=n;return M(r,u=>Uo(u,e,t,i,o))}function Zr(r,n={}){let{a:e=0,b:t=1,lowerTail:i=!0,logP:o=!1}=n;return M(r,u=>Wr(u,e,t,i,o))}var v={mean:NaN,variance:NaN,sd:NaN,median:NaN,mode:NaN,skewness:NaN,kurtosis:NaN};function R(r,n,e,t,i,o){return{mean:r,variance:n,sd:Math.sqrt(n),median:e,mode:t,skewness:i,kurtosis:o}}function Gn(r,n,e,t){return Cn(i=>i,r,n,n,e,t)}function Cn(r,n,e,t,i,o){let u=50*Number.EPSILON,s=[2,3,4].map(N=>{let a=p=>(r(p)-e)**N*n(p),c=br(a,i,t,0,u,200).result,m=o===1/0?xn(a,t,1,0,u,200).result:br(a,t,o,0,u,200).result;return c+m}),f=s[0];return{variance:f,skewness:s[1]/f**1.5,kurtosis:s[2]/(f*f)-3}}function Ko(r,n){let[e,t]=Q([r,0],[n,0]),i=Math.floor(e);return e===i&&t<0?i-1:i}function Xn(r,n,e){let t=D(Q(r,[n,0]),[e,0]);return t[0]+t[1]<=0}var Yt=(r,n)=>r[n]!==void 0;function Yo(r,n={}){let e=n;switch(r){case"norm":{let{mean:t=0,sd:i=1}=e;return Number.isFinite(t)&&i>0&&Number.isFinite(i)?R(t,i*i,t,t,0,0):v}case"lnorm":{let{meanlog:t=0,sdlog:i=1}=e;if(!(Number.isFinite(t)&&i>0&&Number.isFinite(i)))return v;let o=i*i,u=Math.expm1(o),s=Math.exp(o);return R(Math.exp(t+o/2),u*Math.exp(2*t+o),Math.exp(t),Math.exp(t-o),(s+2)*Math.sqrt(u),u*(16+u*(15+u*(6+u))))}case"unif":{let{min:t=0,max:i=1}=e;if(!(Number.isFinite(t)&&Number.isFinite(i)&&t<i))return v;let o=t+(i-t)/2;return R(o,(i-t)**2/12,o,NaN,0,-1.2)}case"exp":{let{rate:t=1}=e;return t>0&&Number.isFinite(t)?R(1/t,1/(t*t),Math.LN2/t,0,2,6):v}case"gamma":{let t=e.shape??NaN,i=Yt(e,"scale")?e.scale:1/(e.rate??1);return t>0&&Number.isFinite(t)&&i>0&&Number.isFinite(i)?R(t*i,t*i*i,Nr(.5,t,{scale:i}),t>=1?(t-1)*i:0,2/Math.sqrt(t),6/t):v}case"chisq":{let t=e.df??NaN;return t>0&&Number.isFinite(t)?R(t,2*t,cr(.5,t),Math.max(t-2,0),Math.sqrt(8/t),12/t):v}case"beta":{let t=e.shape1??NaN,i=e.shape2??NaN;if(!(t>0&&i>0&&Number.isFinite(t)&&Number.isFinite(i)))return v;let o=t+i,u;return t>1&&i>1?u=(t-1)/(o-2):t===1&&i===1||t<1&&i<1?u=NaN:u=t<=1&&i>=1?0:1,R(t/o,t*i/(o*o*(o+1)),lr(.5,t,i),u,2*(i-t)*Math.sqrt(o+1)/((o+2)*Math.sqrt(t*i)),6*((t-i)**2*(o+1)-t*i*(o+2))/(t*i*(o+2)*(o+3)))}case"t":{let t=e.df??NaN;if(!(t>0))return v;let i=t>2?t===1/0?1:t/(t-2):t>1?1/0:NaN,o=t>4?t===1/0?0:6/(t-4):t>2?1/0:NaN;return R(t>1?0:NaN,i,0,0,t>3?0:NaN,o)}case"f":{let t=e.df1??NaN,i=e.df2??NaN;if(!(t>0&&i>0&&Number.isFinite(t)&&Number.isFinite(i)))return v;let o=i>2?i/(i-2):NaN,u=i>4?2*i*i*(t+i-2)/(t*(i-2)**2*(i-4)):i>2?1/0:NaN,s=i>6?(2*t+i-2)*Math.sqrt(8*(i-4))/((i-6)*Math.sqrt(t*(t+i-2))):NaN,f=i>8?12*(t*(5*i-22)*(t+i-2)+(i-4)*(i-2)**2)/(t*(i-6)*(i-8)*(t+i-2)):NaN;return R(o,u,pr(.5,t,i),t>2?(t-2)/t*(i/(i+2)):0,s,f)}case"cauchy":{let{location:t=0,scale:i=1}=e;return Number.isFinite(t)&&i>0&&Number.isFinite(i)?R(NaN,NaN,t,t,NaN,NaN):v}case"weibull":{let t=e.shape??NaN,i=e.scale??1;if(!(t>0&&Number.isFinite(t)&&i>0&&Number.isFinite(i)))return v;let o=fn(1+1/t),u=Gn(s=>qr(s,t,1,!1),o,0,1/0);return R(i*o,i*i*u.variance,wr(.5,t,{scale:i}),t>1?i*Math.pow((t-1)/t,1/t):0,u.skewness,u.kurtosis)}case"logis":{let{location:t=0,scale:i=1}=e;return Number.isFinite(t)&&i>0&&Number.isFinite(i)?R(t,i*i*Math.PI*Math.PI/3,t,t,0,1.2):v}case"binom":{let t=e.size??NaN,i=e.prob??NaN;if(!(Number.isInteger(t)&&t>=0&&i>=0&&i<=1))return v;let o=1-i;return R(t*i,t*i*o,gt(.5,t,i),Math.min(t,Ko(t+1,i)),(o-i)/Math.sqrt(t*i*o),(1-6*i*o)/(t*i*o))}case"pois":{let t=e.lambda??NaN;return t>0&&Number.isFinite(t)?R(t,t,mr(.5,t),Math.floor(t),1/Math.sqrt(t),1/t):v}case"geom":{let t=e.prob??NaN;if(!(t>0&&t<=1))return v;let i=1-t;return R(i/t,i/(t*t),Rr(.5,t),0,(2-t)/Math.sqrt(i),6+t*t/i)}case"nbinom":{let t=e.size??NaN;if(!(t>0&&Number.isFinite(t)))return v;let i=Yt(e,"mu")?t/(t+e.mu):e.prob??NaN;if(!(i>0&&i<=1))return v;let o=1-i,u=Yt(e,"mu")?{mu:e.mu}:{prob:i},s=N=>Yt(e,"mu")?Xn([N,0],t,(t-1)*e.mu):Xn(I([t-1,0],[N,0]),i,t-1),f=0;if(t>1){for(f=Math.max(0,Math.floor((t-1)*o/i)-1);s(f+1);)f++;for(;f>0&&!s(f);)f--}return R(t*o/i,t*o/(i*i),_r(.5,t,u),f,(2-i)/Math.sqrt(t*o),6/t+i*i/(t*o))}case"hyper":{let t=e.m??NaN,i=e.n??NaN,o=e.k??NaN;if(!([t,i,o].every(N=>Number.isInteger(N)&&N>=0)&&o<=t+i))return v;let u=t+i,s=Math.floor((o+1)*(t+1)/(u+2)),f=((u-1)*u*u*(u*(u+1)-6*t*i-6*o*(u-o))+6*o*t*i*(u-o)*(5*u-6))/(o*t*i*(u-o)*(u-2)*(u-3));return R(o*t/u,o*t/u*(i/u)*(u-o)/(u-1),dr(.5,t,i,o),s,(u-2*t)*Math.sqrt(u-1)*(u-2*o)/(Math.sqrt(o*t*i*(u-o))*(u-2)),f)}case"invgamma":{let t=e.alpha??NaN,i=e.beta??1;return t>0&&Number.isFinite(t)&&i>0&&Number.isFinite(i)?R(t>1?i/(t-1):1/0,t>2?i*i/((t-1)**2*(t-2)):t>1?1/0:NaN,Or(.5,t,{beta:i}),i/(t+1),t>3?4*Math.sqrt(t-2)/(t-3):NaN,t>4?(30*t-66)/((t-3)*(t-4)):NaN):v}case"kumar":{let t=e.a??NaN,i=e.b??NaN;if(!(t>0&&i>0&&Number.isFinite(t)&&Number.isFinite(i)))return v;let o=i*Math.exp(ln(1+1/t,i)),u=i<1?Cn(f=>Ft(f,t,i,!0,!1),()=>1,o,Cr(o,t,i,!0,!1),0,1):Gn(f=>Xr(f,t,i,!1),o,0,1),s;return t>=1&&i>=1?s=t===1&&i===1?NaN:Math.pow((t-1)/(t*i-1),1/t):t<1&&i<1?s=NaN:s=t<1?0:1,R(o,u.variance,jr(.5,t,i),s,u.skewness,u.kurtosis)}case"pareto":{let{a:t=1,b:i=1}=e;return t>0&&Number.isFinite(t)&&i>0&&Number.isFinite(i)?R(t>1?t*i/(t-1):1/0,t>2?i*i*t/((t-1)**2*(t-2)):t>1?1/0:NaN,i*Math.pow(2,1/t),i,t>3?2*(1+t)/(t-3)*Math.sqrt((t-2)/t):NaN,t>4?6*(t**3+t*t-6*t-2)/(t*(t-3)*(t-4)):NaN):v}case"triang":{let{a:t=-1,b:i=1}=e,o=e.c??(t+i)/2;if(!(Number.isFinite(t)&&Number.isFinite(i)&&t<i&&t<=o&&o<=i))return v;let u=t*t+i*i+o*o-t*i-t*o-i*o;return R((t+i+o)/3,u/18,Yr(.5,{a:t,b:i,c:o}),o,Math.SQRT2*(t+i-2*o)*(2*t-i-o)*(t-2*i+o)/(5*u**1.5),-.6)}case"laplace":{let{mu:t=0,sigma:i=1}=e;return Number.isFinite(t)&&i>0&&Number.isFinite(i)?R(t,2*i*i,t,t,0,3):v}case"arcsine":{let{a:t=0,b:i=1}=e;return Number.isFinite(t)&&Number.isFinite(i)&&t<i?R(t+(i-t)/2,(i-t)**2/8,Zr(.5,{a:t,b:i}),NaN,0,-1.5):v}}throw new RangeError(`unknown distribution '${String(r)}'`)}var Jo=[82758667,1871391091,4127413238,3672831523,69195019,1871391091,3672091415,3528743235,69195019],Wo=[1511326704,3759209742,1610795712,4292754251,1511326704,3889917532,3859662829,4292754251,3708466080],Zo=[2427906178,3580155704,949770784,226153695,1230515664,3580155704,1988835001,986791581,1230515664],To=[1464411153,277697599,1610723613,32183930,1464411153,1022607788,2824425944,32183930,2093834863];function Po(r,n,e){let t=Math.floor(n/65536);return(r*t%e*65536+r*(n-t*65536))%e}function jn(r,n,e){let t=r[0];if(!Number.isInteger(t)||t%100!==7)throw new RangeError("the state must be a .Random.seed of L'Ecuyer-CMRG (kind code ending in 07)");let i=yn(r),o=new Int32Array(7);o[0]=t;for(let u=0;u<2;u++){let s=u===0?n:e,f=u===0?4294967087:4294944443;for(let N=0;N<3;N++){let a=0;for(let c=0;c<3;c++)a=(a+Po(s[3*N+c],i[3*u+c],f))%f;o[1+3*u+N]=a|0}}return o}function tu(r){return jn(r,Zo,To)}function ru(r){return jn(r,Jo,Wo)}var nu=-.5,eu=.3333333,iu=-.2500068,ou=.2000118,uu=-.1661269,su=.1421878,fu=-.1384794,au=.125006,Nu=1/7,cu=1/12,mu=1/24,Un=.3989422804014327,pu=[1,1,2,6,24,120,720,5040,40320,362880],Z=0,Vn=0,Hn=new Float64Array(36),$t=0,Kn=0,Tr=0,zt=0,Yn=0,It=0,$n=0,zn=0,Jn=0,at=0,qt=0,Wn=0,Zn=0,Tn=0,Pn=0,wt=0;function Nt(r){if(!Number.isFinite(r)||r<0)return NaN;if(r<=0)return 0;let n=r>=10,e=!1;if(!(n&&r===$t))if(n)e=!0,$t=r,It=Math.sqrt(r),$n=6*r*r,Jn=Math.floor(r-1.1484);else for(r!==$t&&($t=r,Vn=Math.max(1,Math.trunc(r)),Z=0,zt=Yn=Tr=Math.exp(-r));;){let p=g();if(p<=Yn)return 0;if(Z>0){let h=p>.458?Math.min(Z,Vn):1;for(let l=h;l<=Z;l++)if(p<=Hn[l])return l;if(Z===35)continue}Z++;for(let h=Z;h<=35;h++)if(Tr*=r/h,zt+=Tr,Hn[h]=zt,p<=zt)return Z=h,h;Z=35}let t=-1,i=0,o=0,u=0,s=r+It*ft();if(s>=0&&(t=Math.floor(s),t>=Jn||(i=t,o=r-i,u=g(),$n*u>=o*o*o)))return t;(e||r!==Kn)&&(Kn=r,zn=Un/It,at=mu/r,qt=.3*at*at,wt=Nu*at*qt,Pn=qt-15*wt,Tn=at-6*qt+45*wt,Zn=1-at+3*qt-15*wt,Wn=.1069/r);let f=0,N=0,a=0,c=0,m=()=>{if(t<10)f=-r,N=Math.pow(r,t)/pu[t];else{let l=cu/i;l=l*(1-4.8*l*l);let y=o/i;Math.abs(y)<=.25?f=i*y*y*(((((((au*y+fu)*y+su)*y+uu)*y+ou)*y+iu)*y+eu)*y+nu)-l:f=i*Math.log(1+y)-o-l,N=Un/Math.sqrt(i)}let p=(.5-o)/It,h=p*p;a=-.5*h,c=zn*(((wt*h+Pn)*h+Tn)*h+Zn)};if(s>=0&&(m(),c-u*c<=N*Math.exp(f-a)))return t;for(;;){let p=J();u=2*g()-1;let h=1.8+(u>=0?p:-p);if(h>-.6744&&(t=Math.floor(r+It*h),i=t,o=r-i,m(),Wn*Math.abs(u)<=N*Math.exp(f+p)-c*Math.exp(a+p)))break}return t}function Mu(r,n){return F(r,()=>Nt(n))}function hu(r,n){return F(r,()=>!Number.isFinite(n)||n<=0||n>1?NaN:Nt(J()*((1-n)/n)))}function lu(r,n,e){let{prob:t,mu:i}=e;if(t===void 0==(i===void 0))throw new TypeError("specify exactly one of prob and mu");let o=Number.isFinite(n)?n:Number.MAX_VALUE/2;if(i!==void 0)return F(r,()=>!Number.isFinite(i)||Number.isNaN(n)||n<=0||i<0?NaN:i===0?0:Nt(T(o,i/o)));let u=t;return F(r,()=>!Number.isFinite(u)||Number.isNaN(n)||n<=0||u<=0||u>1?NaN:u===1?0:Nt(T(o,(1-u)/u)))}var du=5.656854,bu=.36787944117144233,gu=.04166669,xu=.02083148,yu=.00801191,Fu=.00144121,Iu=-7388e-8,qu=24511e-8,wu=2424e-7,vu=.3333333,ku=-.250003,Ru=.2000062,Au=-.1662921,Lu=.1423657,Su=-.1367177,Eu=.1233795,te=0,re=0,j=0,ct=0,ne=0,Pr=0,vt=0,kt=0,Jt=0;function ee(r){let n=r/(j+j);return Math.abs(n)<=.25?Pr+.5*r*r*((((((Eu*n+Su)*n+Lu)*n+Au)*n+Ru)*n+ku)*n+vu)*n:Pr-j*r+.25*r*r+(ct+ct)*Math.log(1+n)}function T(r,n){if(Number.isNaN(r)||Number.isNaN(n))return NaN;if(r<=0||n<=0)return n===0||r===0?0:NaN;if(!Number.isFinite(r)||!Number.isFinite(n))return 1/0;if(r<1){let u=1+bu*r,s;for(;;){let f=u*g();if(f>=1){if(s=-Math.log((u-f)/r),J()>=(1-r)*Math.log(s))break}else if(s=Math.exp(Math.log(f)/r),J()>=s)break}return n*s}r!==te&&(te=r,ct=r-.5,j=Math.sqrt(ct),ne=du-j*12);let e=ft(),t=j+.5*e,i=t*t;if(e>=0)return n*i;let o=g();if(ne*o<=e*e*e)return n*i;if(r!==re){re=r;let u=1/r;Pr=((((((wu*u+qu)*u+Iu)*u+Fu)*u+yu)*u+xu)*u+gu)*u,r<=3.686?(vt=.463+j+.178*ct,kt=1.235,Jt=.195/j-.079+.16*j):r<=13.022?(vt=1.654+.0076*ct,kt=1.68/j+.275,Jt=.062/j+.024):(vt=1.77,kt=.75,Jt=.1515/j)}if(t>0){let u=ee(e);if(Math.log(1-o)<=u)return n*i}for(;;){let u=J();if(o=g(),o=o+o-1,e=o<0?vt-kt*u:vt+kt*u,e>=-.71874483771719){let s=ee(e);if(s>0){let f=Math.expm1(s);if(Jt*Math.abs(o)<=f*Math.exp(u-.5*e*e))break}}}return t=j+.5*e,n*t*t}function _u(r,n,e={}){let t=cn(e);return F(r,()=>T(n,t))}function Rt(r){return!Number.isFinite(r)||r<0?NaN:T(r/2,2)}function Du(r,n){if(!Number.isFinite(r)||!Number.isFinite(n)||r<0||n<0)return NaN;if(n===0)return r===0?0:T(r/2,2);let e=Nt(n/2);return e>0&&(e=Rt(2*e)),r>0&&(e+=T(r/2,2)),e}function et(r,n,e={}){let{ncp:t}=e;return t===void 0?F(r,()=>Rt(n)):F(r,()=>Du(n,t))}function Ou(r,n,e={}){let{ncp:t}=e;if(t===void 0)return F(r,()=>Number.isNaN(n)||n<=0?NaN:Number.isFinite(n)?ft()/Math.sqrt(Rt(n)/n):ft());if(Number.isNaN(t))return F(r,()=>NaN);let i=F(r,()=>qn(t,1)),o=et(r,n);return i.map((u,s)=>u/Math.sqrt(o[s]/n))}function Qu(r,n,e,t={}){let{ncp:i}=t;if(i===void 0)return F(r,()=>{if(Number.isNaN(n)||Number.isNaN(e)||n<=0||e<=0)return NaN;let s=Number.isFinite(n)?Rt(n)/n:1,f=Number.isFinite(e)?Rt(e)/e:1;return s/f});let o=et(r,n,{ncp:i}),u=et(r,e);return o.map((s,f)=>s/n/(u[f]/e))}var Bu=1024*Math.LN2,At=0,ie=0,tn=0,oe=0,ue=0,se=-1,fe=-1;function rn(r,n){let e=At*Math.log(r/(1-r));if(e<=Bu){let t=n*Math.exp(e);return Number.isFinite(t)||(t=Number.MAX_VALUE),[e,t]}return[e,Number.MAX_VALUE]}function Gu(r,n){if(Number.isNaN(r)||Number.isNaN(n)||r<0||n<0)return NaN;if(!Number.isFinite(r)&&!Number.isFinite(n))return .5;if(r===0&&n===0)return g()<.5?0:1;if(!Number.isFinite(r)||n===0)return 1;if(!Number.isFinite(n)||r===0)return 0;let e=se===r&&fe===n;e||(se=r,fe=n);let t=Math.min(r,n),i=Math.max(r,n),o=t+i,u,s;if(t<=1){for(e||(At=1/t,tn=1+i-t,oe=tn*(.0138889+.0416667*t)/(i*At-.777778),ue=.25+(.5+.25/tn)*t);;){let a=g(),c=g(),m;if(a<.5){let p=a*c;if(m=a*p,.25*c+m-p>=oe)continue}else{if(m=a*a*c,m<=.25){[u,s]=rn(a,i);break}if(m>=ue)continue}if([u,s]=rn(a,i),o*(Math.log(o/(t+s))+u)-1.3862944>=Math.log(m))break}return r===t?t/(t+s):s/(t+s)}e||(At=Math.sqrt((o-2)/(2*t*i-o)),ie=t+1/At);let f,N;do{let a=g(),c=g();[u,s]=rn(a,t);let m=a*a*c;f=ie*u-1.3862944;let p=t+f-s;if(p+2.609438>=5*m||(N=Math.log(m),p>N))break}while(f+o*Math.log(o/(i+s))<N);return r!==t?i/(i+s):s/(i+s)}function Xu(r,n,e,t={}){let{ncp:i}=t;if(i===void 0)return F(r,()=>Gu(n,e));let o=et(r,2*n,{ncp:i}),u=et(r,2*e);return o.map((s,f)=>s/(s+u[f]))}var Cu=2147483647,it=0,Lt=0,mt=0,nt=0,Wt=0,Zt=0,ae=0,Ne=0,St=0,Tt=0,Pt=0,pt=0,tr=0,nn=-1,ce=-1,U=0;function rr(r){let n=r*r;return(13860-(462-(132-(99-140/n)/n)/n)/n)/r/166320}function nr(r,n){if(!Number.isFinite(r))return NaN;let e=Math.round(r);if(e!==r)return NaN;if(!Number.isFinite(n)||e<0||n<0||n>1)return NaN;if(e===0||n===0)return 0;if(n===1)return e;if(e>=Cu)return gt(g(),e,n,{lowerTail:!1});let t=e,i=Math.min(n,1-n),o=1-i,u=t*i,s=i/o,f=s*(t+1),N;if(n!==nn||t!==ce)if(nn=n,ce=t,u<30)Ne=In(o,t),N=!0;else{N=!1,Lt=u+i,U=Math.trunc(Lt),mt=u*o,nt=Math.trunc(2.195*Math.sqrt(mt)-4.6*o)+.5,pt=U+.5,St=pt-nt,tr=pt+nt,it=.134+20.5/(15.3+U);let c=(Lt-St)/(Lt-St*i);Tt=c*(1+.5*c),c=(tr-Lt)/(tr*o),Pt=c*(1+.5*c),Wt=nt*(1+it+it),Zt=Wt+it/Tt,ae=Zt+it/Pt}else N=u<30;let a;if(N)t:for(;;){a=0;let c=Ne,m=g();for(;;){if(m<c)break t;if(a>110)break;m-=c,a++,c*=f/a-s}}else for(;;){let c=g()*ae,m=g();if(c<=nt){a=Math.trunc(pt-nt*m+c);break}if(c<=Wt){let h=St+(c-nt)/it;if(m=m*it+1-Math.abs(pt-h)/nt,m>1||m<=0)continue;a=Math.trunc(h)}else if(c>Zt){if(a=Math.trunc(tr-Math.log(m)/Pt),a>t)continue;m=m*(c-Zt)*Pt}else{if(a=Math.trunc(St+Math.log(m)/Tt),a<0)continue;m=m*(c-Wt)*Tt}let p=Math.abs(a-U);if(p<=20||p>=mt/2-1){let h=1;if(U<a)for(let l=U+1;l<=a;l++)h*=f/l-s;else if(U>a)for(let l=a+1;l<=U;l++)h/=f/l-s;if(m<=h)break}else{let h=p/mt*((p*(p/3+.625)+.1666666666666)/mt+.5),l=-p*p/(2*mt),y=Math.log(m);if(y<l-h)break;if(y<=l+h){let ot=a+1,Mt=U+1,ht=t+1-U,tt=t-a+1;if(y<=pt*Math.log(Mt/ot)+(t-U+.5)*Math.log(ht/tt)+(a-U)*Math.log(tt*i/(ot*o))+rr(Mt)+rr(ht)+rr(ot)+rr(tt))break}}}return nn>.5&&(a=t-a),a}function ju(r,n,e){return F(r,()=>nr(n,e))}function Uu(r,n,e){if(!Number.isFinite(n)||n<0||Math.round(n)!==n)throw new RangeError("size must be a non-negative integer");let t=0;for(let s of e){if(!Number.isFinite(s)||s<0)throw new RangeError("prob must contain non-negative finite numbers");t+=s}if(t===0)throw new RangeError("prob must contain at least one positive value");let i=e.map(s=>s/t),o=i.length,u=()=>{let s=new Array(o).fill(0),f=n,N=1;for(let a=0;a<o-1;a++){if(i[a]){let c=i[a]/N;s[a]=c<1?nr(f,c):f,f-=s[a]}if(f<=0)return s;N-=i[a]}return s[o-1]=f,s};if(!Number.isFinite(r)||r<0)throw new RangeError("n must be a non-negative finite number");return Array.from({length:Math.trunc(r)},u)}function Vu(r,n){return F(r,()=>{if(Number.isNaN(n))return NaN;let e=Math.round(n);if(e<0)return NaN;if(e===0)return 0;let t=0;for(let i=1;i<=e;i++)t+=i*Math.floor(g()+.5);return t})}function Hu(r,n,e){return F(r,()=>{if(Number.isNaN(n)||Number.isNaN(e))return NaN;let t=Math.round(n),i=Math.round(e);if(t<0||i<0)return NaN;if(t===0||i===0)return 0;let o=t+i,u=new Int32Array(o);for(let f=0;f<o;f++)u[f]=f;let s=0;for(let f=0;f<i;f++){let N=Fn(o);s+=u[N],u[N]=u[--o]}return s-i*(i-1)/2})}var en=2147483647,Ku=.9189385332046728,Yu=.0078,$u=.0034,zu=1e25,Ju=57.564627324851145,Wu=[0,0,.6931471805599453,1.791759469228055,3.1780538303479458,4.787491742782046,6.579251212010101,8.525161361065415];function k(r){if(r<0)return 0;if(r<=7)return Wu[r];let n=r,e=n*n;return(n+.5)*Math.log(n)-n+Ku+(.0833333333333333-.00277777777777778/e)/n}var me=-1,pe=-1,Me=-1,_=0,Et=0,_t=0,x=0,S=0,A=0,P=0,he=0,sr=0,Dt=0,K=0,Y=0,le=0,de=0,er=0,ir=0,or=0,ur=0,be=0;function Zu(r,n,e){if(!Number.isFinite(r)||!Number.isFinite(n)||!Number.isFinite(e))return NaN;if(r=Math.round(r),n=Math.round(n),e=Math.round(e),r<0||n<0||e<0||e>r+n)return NaN;if(r>=en||n>=en||e>=en)return e===1?nr(e,r/(r+n)):gn(g(),r,n,e,!1,!1);let t=r,i=n,o=e,u,s;t!==pe||i!==Me?(u=!0,s=!0):o!==me?(u=!1,s=!0):(u=!1,s=!1),u&&(pe=t,Me=i,P=t+i,t<=i?(S=t,A=i):(S=i,A=t)),s&&(me=o,x=o+o>=P?Math.trunc(P-o):o),(u||s)&&(_=Math.trunc((x+1)*(S+1)/(P+2)),Et=Math.max(0,x-A),_t=Math.min(S,x));let f;if(Et===_t)f=_t;else if(_-Et<10){if(u||s){let N;x<A?N=k(A)+k(S+A-x)-k(A-x)-k(S+A):N=k(S)+k(x)-k(x-A)-k(S+A),he=Math.exp(N+Ju)}t:for(;;){f=Et;let N=g()*zu,a=he;for(;N>a;)if(N-=a,a*=(S-f)*(x-f),f++,a=a/f/(A-x+f),f>_t)continue t;break}}else{if(u||s){let a=Math.sqrt((P-x)*x*S*A/(P-1)/P/P);Dt=Math.trunc(1.5*a)+.5,K=_-Dt+.5,Y=_+Dt+.5,sr=k(_)+k(S-_)+k(x-_)+k(A-x+_),le=Math.exp(sr-k(Math.trunc(K))-k(Math.trunc(S-K))-k(Math.trunc(x-K))-k(Math.trunc(A-x+K))),de=Math.exp(sr-k(Math.trunc(Y-1))-k(Math.trunc(S-Y+1))-k(Math.trunc(x-Y+1))-k(Math.trunc(A-x+Y-1))),er=-Math.log(K*(A-x+K)/(S-K+1)/(x-K+1)),ir=-Math.log((S-Y+1)*(x-Y+1)/Y/(A-x+Y)),or=Dt+Dt,ur=or+le/er,be=ur+de/ir}let N=0;for(;;){let a=g()*be,c=g();if(++N>=1e4)return NaN;if(a<or)f=Math.trunc(K+a);else if(a<=ur){if(f=Math.trunc(K+Math.log(c)/er),f<Et)continue;c=c*(a-or)*er}else{if(f=Math.trunc(Y-Math.log(c)/ir),f>_t)continue;c=c*(a-ur)*ir}if(Tu(f,c))break}}return o+o>=P?f=t>i?o-i+f:t-f:t>i&&(f=o-f),f}function Tu(r,n){if(_<100||r<=50){let V=1;if(_<r)for(let L=_+1;L<=r;L++)V=V*(S-L+1)*(x-L+1)/(A-x+L)/L;else if(_>r)for(let L=r+1;L<=_;L++)V=V*L*(A-x+L)/(S-L+1)/(x-L+1);return n<=V}let e=r,t=e+1,i=e-_,o=S-e+1,u=x-e+1,s=A-x+t,f=-i/t,N=i/o,a=i/u,c=-i/s,m=o*u/(t*s)-1,p=m<0?1+m:1,h=m*(1+m*(-.5+m/3)),l=h-.25*(m*m*m*m)/p,y=_+.5,ot=S-_+.5,Mt=x-_+.5,ht=A-x+y,tt=V=>V*(1+V*(-.5+V/3)),on=e*h-_*l+$u+y*tt(f)+ot*tt(N)+Mt*tt(a)+ht*tt(c),fr=Math.log(n);if(fr>on)return!1;let Ot=(V,L)=>{let un=V*(L*L*L*L);return L<0?un/(1+L):un},ge=Ot(y,f),xe=Ot(ot,N),ye=Ot(Mt,a),Fe=Ot(ht,c);return fr<on-.25*(ge+xe+ye+Fe)+(e+_)*(l-h)-Yu?!0:fr<=sr-k(r)-k(S-r)-k(x-r)-k(A-x+r)}function Pu(r,n,e,t){return F(r,()=>Zu(n,e,t))}function ts(r,n,e={}){let{beta:t=1}=e;return F(r,()=>n>0&&t>0&&Number.isFinite(n)&&Number.isFinite(t)?1/T(n,1/t):NaN)}function rs(r,n,e){return F(r,()=>n>0&&e>0&&Number.isFinite(n)&&Number.isFinite(e)?Ft(1-g(),n,e,!0,!1):NaN)}function ns(r,n={}){let{a:e=1,b:t=1}=n;return F(r,()=>e>0&&t>0&&Number.isFinite(e)&&Number.isFinite(t)?Vr(1-g(),e,t,!0,!1):NaN)}function es(r,n={}){let{a:e=-1,b:t=1}=n,i=n.c??(e+t)/2;return F(r,()=>{if(!(Number.isFinite(e)&&Number.isFinite(t)&&e<t&&e<=i&&i<=t))return NaN;let o=g(),u=g(),s=(i-e)/(t-e);return e+(t-e)*((1-s)*Math.min(o,u)+s*Math.max(o,u))})}function is(r,n={}){let{mu:e=0,sigma:t=1}=n;return F(r,()=>{if(!(Number.isFinite(e)&&t>0&&Number.isFinite(t)))return NaN;let i=J(),o=g()>.5?1:-1;return e+t*o*i})}function os(r,n={}){let{a:e=0,b:t=1}=n;return F(r,()=>Number.isFinite(e)&&Number.isFinite(t)&&e<t?Wr(g(),e,t,!0,!1):NaN)}export{ti as RNGkind,Vo as darcsine,Ee as dbeta,De as dbinom,Xe as dcauchy,ve as dchisq,wi as dexp,Le as df,qe as dgamma,ro as dgeom,Ue as dhyper,lo as dinvgamma,Yo as distSummary,yo as dkumar,Oo as dlaplace,Bi as dlnorm,Hi as dlogis,pi as dmultinom,co as dnbinom,Ie as dnorm,wo as dpareto,Re as dpois,He as dsignrank,Qe as dt,Lo as dtriang,di as dunif,Ji as dweibull,$e as dwilcox,ri as getRandomSeed,tu as nextRNGStream,ru as nextRNGSubStream,Ho as parcsine,_e as pbeta,Oe as pbinom,Te as pbvnorm,Ce as pcauchy,ke as pchisq,vi as pexp,Se as pf,we as pgamma,no as pgeom,Ve as phyper,bo as pinvgamma,Fo as pkumar,Qo as plaplace,Gi as plnorm,Ki as plogis,mo as pnbinom,lt as pnorm,vo as ppareto,Ae as ppois,Ke as psignrank,Be as pt,So as ptriang,We as ptukey,bi as punif,Wi as pweibull,ze as pwilcox,Zr as qarcsine,lr as qbeta,gt as qbinom,je as qcauchy,cr as qchisq,ki as qexp,pr as qf,Nr as qgamma,Rr as qgeom,dr as qhyper,Or as qinvgamma,jr as qkumar,Bo as qlaplace,Xi as qlnorm,Yi as qlogis,_r as qnbinom,ut as qnorm,ko as qpareto,mr as qpois,Ye as qsignrank,Ge as qt,Yr as qtriang,Ze as qtukey,gi as qunif,wr as qweibull,Je as qwilcox,mi as r2dtable,os as rarcsine,Xu as rbeta,ju as rbinom,fi as rcauchy,et as rchisq,oi as rexp,Qu as rf,_u as rgamma,hu as rgeom,Pu as rhyper,ts as rinvgamma,rs as rkumar,is as rlaplace,ui as rlnorm,si as rlogis,Uu as rmultinom,lu as rnbinom,ii as rnorm,ns as rpareto,Mu as rpois,Vu as rsignrank,Ou as rt,es as rtriang,ei as runif,ai as rweibull,Hu as rwilcox,ci as sample,Ni as sampleInt,ni as setRandomSeed,Pe as setSeed};
|
|
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{B as li,a as Le,b as _e,c as lr,f as Fn,g as Ye,h as $e,i as Ir,l as ze,m as Je,n as We,r as Ze,s as Te,t as Pe,u as ti,v as ri,w as ni,x as hi,y as pi}from"./chunks/chunk-UOE57JGT.js";import{a as I,b as kn,c as si,d as Rn,e as fi,f as ai,g as Ni,h as ci,i as mi,j as Mi}from"./chunks/chunk-USPEBXSR.js";import{a as Fr,b as qn}from"./chunks/chunk-ZIX7NYQF.js";import{a as vn,b as ei,c as ii,d as oi,e as ui,f as g,h as wn,i as at,j as W}from"./chunks/chunk-IUULP3LE.js";import{D as Ve,E as He,F as Ke,d as dn,g as bn,h as gn,i as Se,j as Ee,k as dr,n as De,o as Oe,p as br,q as gr,r as xr,s as Qe,t as Ge,u as yr,x as Be,y as Xe,z as yt}from"./chunks/chunk-5NRFU6F6.js";import{A as je,B as Ue,a as v,b as S,c as d,d as q,e as Ct,g as pn,h as ft,i as hr,j as ln,l as Ht,m as Re,n as Ae,o as pr,q as yn,t as In,z as Ce}from"./chunks/chunk-FCNVTIPJ.js";import{a as xt}from"./chunks/chunk-FKAKALOZ.js";import{B as O,C,D as jt,E as gt,F as B,G as nt,H as X,I as Ut,J as Vt,N as xn,d as Xt,e as h,f as ke,g as bt,h as st,l as Mn,n as Mr,s as rt,u as hn}from"./chunks/chunk-3TSWYE5L.js";import{b as Q,c as mn,d as F,f as D,g as G,h as J,i as Y,j as Bt,k as b}from"./chunks/chunk-KT66SB7R.js";function di(r,n,e={}){let t=e.log??!1,i=n.length;if(r.length!==i)throw new RangeError("x and prob must have the same length");if(n.some(a=>!Number.isFinite(a)||a<0))throw new RangeError("probabilities must be finite and non-negative");if(!n.some(a=>a>0))throw new RangeError("probabilities must not all be 0");if(r.some(a=>!(a>=0)||!Number.isFinite(a)||a!==Math.round(a)))throw new RangeError("x must be non-negative integers");let o=r.reduce((a,c)=>a+c,0);if(e.size!==void 0&&e.size!==o)throw new RangeError("size must equal the sum of x");for(let a=0;a<i;a++)if(n[a]===0&&r[a]>0)return t?-1/0:0;let u=new Array(i+1).fill([0,0]),s=new Array(i+1).fill(0);for(let a=i-1;a>=0;a--)u[a]=F(u[a+1],[n[a],0]),s[a]=s[a+1]+r[a];let f=0,N=1;for(let a=0;a<i;a++){if(n[a]===0)continue;let c=u[a+1];if(c[0]===0)break;let m=Y([n[a],0],u[a]),M=Y(c,u[a]),p=r[a],l=s[a+1];t?f+=rt(p,l,m,M,!0):N*=rt(p,l,m,M,!1)}return t?f:N}function qr(r,n){return Number.isFinite(n-r)?1:.5}function bi(r,n,e,t){if(Number.isNaN(r)||Number.isNaN(n)||Number.isNaN(e))return NaN;if(!(e>n))return NaN;if(r<n||r>e)return d(t);let i=qr(n,e),o=e*i-n*i;return t?-Math.log(o)+Math.log(i):i/o}function gi(r,n,e,t,i){if(Number.isNaN(r)||Number.isNaN(n)||Number.isNaN(e))return NaN;if(e<n||!Number.isFinite(n)||!Number.isFinite(e))return NaN;if(r>=e)return S(t,i);if(r<=n)return v(t,i);let o=qr(n,e),u=e*o-n*o,s=t?(r*o-n*o)/u:(e*o-r*o)/u;return i?Math.log(s):s}function xi(r,n,e,t,i){if(Number.isNaN(r)||Number.isNaN(n)||Number.isNaN(e))return NaN;if(e<n||!Number.isFinite(n)||!Number.isFinite(e))return NaN;let o=q(r,n,e,t,i);if(Number.isNaN(o))return NaN;if(e===n)return n;if(o!==void 0)return o;let u=qr(n,e)!==1,s=N=>u?(1-N)*n+N*e:n+N*(e-n),f=i?Math.exp(r):r;return t?s(f):f<.5?u?f*n+(1-f)*e:e-f*(e-n):s(i?-Math.expm1(r):.5-r+.5)}function yi(r,n={}){let{min:e=0,max:t=1,log:i=!1}=n;return h(r,o=>bi(o,e,t,i))}function Ii(r,n={}){let{min:e=0,max:t=1,lowerTail:i=!0,logP:o=!1}=n;return h(r,u=>gi(u,e,t,i,o))}function Fi(r,n={}){let{min:e=0,max:t=1,lowerTail:i=!0,logP:o=!1}=n;return h(r,u=>xi(u,e,t,i,o))}var qi=2**-1022,vi=-1022*Math.LN2;function wi(r,n,e){if(Number.isNaN(r)||Number.isNaN(n))return NaN;if(n<0||n===1/0)return NaN;if(r<0)return d(e);let t=gt(n,r);if(Number.isNaN(t[0]))return NaN;if(e)return Math.log(n)-t[0]-t[1];let i=B(t);if(i<qi&&n>1&&t[0]<1500){let o=D(b([n,0]),t);return o[0]<-746?0:O(o)[0]}return n*i}function ki(r,n,e){if(!n)return e?-r[0]-r[1]:B(r);let t=r[0]+r[1];return e?Ut(r):-Math.expm1(-t)}function Ri(r,n,e,t){if(Number.isNaN(r)||Number.isNaN(n))return NaN;if(n<0)return NaN;if(r<=0)return v(e,t);let i=gt(n,r);return Number.isNaN(i[0])?NaN:i[0]===1/0?S(e,t):ki(i,e,t)}function Ai(r,n,e,t){if(Number.isNaN(r)||Number.isNaN(n))return NaN;if(n<0)return NaN;let i=q(r,0,1/0,e,t);if(Number.isNaN(i)||i===0)return i;if(t&&e&&r<vi&&n>0)return nt([-r,0],n);let o;return t?o=e?X(r):r:o=e?Math.log1p(-r):Math.log(r),-o/n}function Li(r,n={}){let{rate:e=1,log:t=!1}=n;return h(r,i=>wi(i,e,t))}function _i(r,n={}){let{rate:e=1,lowerTail:t=!0,logP:i=!1}=n;return h(r,o=>Ri(o,e,t,i))}function Si(r,n={}){let{rate:e=1,lowerTail:t=!0,logP:i=!1}=n;return h(r,o=>Ai(o,e,t,i))}var Ei=.9189385332046728,Di=.3989422804014327,Oi=2**-1022,Qi=[.9189385332046728,-38782941580672414e-33];function Ln(r,n,e){let t=D(b([r,0]),[n,0]);if(e===1)return t;let i=t[0]/e;if(!(Number.isFinite(i)&&Math.abs(i)<1e300))return[i,0];if(e<1e300)return Y(t,[e,0]);let o=2**-64;return Y([t[0]*o,t[1]*o],[e*o,0])}function Kt(r){if(Math.abs(r[0])>1e150)return[r[0]*r[0]/2,0];let n=G(r,r);return[n[0]/2,n[1]/2]}function Gi(r,n){if(r[0]>-Math.SQRT2){if(r[0]<Math.SQRT2)return bt(r[0]+r[1],{logP:n});let e=An(r[0],[r[0],r[1]],!1);return n?Math.log1p(-e):1-e}return An(-r[0],[-r[0],-r[1]],n)}function An(r,n,e){let t=.5*Xt(r*Math.SQRT1_2),i=Kt(n);return e?Math.log(t)-i[0]-i[1]:t*B(i)}var vr=2.5066282746310007;function Bi(r,n,e,t){let i=e?r:-r,o,u=(s,f,N)=>-f[0]-N[0]+(-f[1]-N[1])+Math.log(s);if(i<=-Math.SQRT2){let s=.5*Xt(-i*Math.SQRT1_2),f=t?[n,0]:b([n,0]);o=-u(s,Kt([-i,0]),f)*vr*s}else if(i>=Math.SQRT2){let s=.5*Xt(i*Math.SQRT1_2),f=t?-Math.expm1(n):1-n;o=u(s,Kt([i,0]),b([f,0]))*vr*s}else{let s=bt(i),f=Math.exp(-i*i/2)/vr;o=((t?Math.exp(n):n)-s)/f}return Number.isFinite(o)?Q(r,e?o:-o):[r,0]}function Xi(r,n,e,t){if(Number.isNaN(r)||Number.isNaN(n)||Number.isNaN(e))return NaN;if(e<0)return NaN;if(r<=0)return d(t);if(e===0)return Math.log(r)===n?1/0:d(t);if(!Number.isFinite(r)||!Number.isFinite(n)||!Number.isFinite(e)){let f=(Math.log(r)-n)/e;return Number.isNaN(f)?NaN:d(t)}let i=Ln(r,n,e),o=Kt(i),u=()=>F(F(o,Qi),F(b([r,0]),b([e,0])));if(t){if(!(o[0]<1e300))return-(Ei+o[0]+o[1]+Math.log(e)+Math.log(r));let f=u();return-(f[0]+f[1])}let s=B(o);if(s===0)return 0;if(s<Oi){let f=u();return f[0]>746?0:O([-f[0],-f[1]])[0]}return Di*s/e/r}function Ci(r,n,e,t,i){if(Number.isNaN(r)||Number.isNaN(n)||Number.isNaN(e))return NaN;if(e<0)return NaN;if(r<=0)return v(t,i);if(e===0||!Number.isFinite(r)||!Number.isFinite(n)||!Number.isFinite(e))return bt(Math.log(r),{mean:n,sd:e,lowerTail:t,logP:i});let o=Ln(r,n,e);return Gi(t?o:[-o[0],-o[1]],i)}function ji(r,n,e,t,i){if(Number.isNaN(r)||Number.isNaN(n)||Number.isNaN(e))return NaN;let o=st(r,{lowerTail:t,logP:i});if(!Number.isFinite(o)||!(e>0)||!Number.isFinite(e)||!Number.isFinite(n))return Math.exp(st(r,{mean:n,sd:e,lowerTail:t,logP:i}));let u=Bi(o,r,t,i);if(e>=1e300)return Math.exp(n+e*u[0]);let s=F(F(gt(e,u[0]),[e*u[1],0]),[n,0]);return Math.abs(s[0])<750?Math.exp(s[0])*(1+s[1]):Math.exp(s[0])}function Ui(r,n={}){let{meanlog:e=0,sdlog:t=1,log:i=!1}=n;return h(r,o=>Xi(o,e,t,i))}function Vi(r,n={}){let{meanlog:e=0,sdlog:t=1,lowerTail:i=!0,logP:o=!1}=n;return h(r,u=>Ci(u,e,t,i,o))}function Hi(r,n={}){let{meanlog:e=0,sdlog:t=1,lowerTail:i=!0,logP:o=!1}=n;return h(r,u=>ji(u,e,t,i,o))}var _n=2**-1022;function Ki(r,n,e,t){if(Number.isNaN(r)||Number.isNaN(n)||Number.isNaN(e))return NaN;if(!(e>0))return NaN;let i=C(r,n,e);if(Number.isNaN(i[0]))return NaN;let o=i[0]<0?[-i[0],-i[1]]:[i[0],i[1]],u=B(o);return t?-o[0]-o[1]-Math.log(e)-2*Math.log1p(u):u<_n?nt(o,e):e>=_n?u/(e*(1+u)*(1+u)):u/((1+u)*(1+u))/e}function Yi(r,n,e,t,i){if(Number.isNaN(r)||Number.isNaN(n)||Number.isNaN(e))return NaN;if(!(e>0))return NaN;let o=C(r,n,e);if(Number.isNaN(o[0]))return NaN;let u=o[0]<0?[-o[0],-o[1]]:[o[0],o[1]],s=B(u);return t===o[0]>=0?i?-Math.log1p(s):1/(1+s):i?-u[0]-u[1]-Math.log1p(s):s/(1+s)}function $i(r,n){return n?r-X(r):r<.25?Math.log(r/(1-r)):Math.log1p((2*r-1)/(1-r))}function zi(r,n,e,t,i){if(Number.isNaN(r)||Number.isNaN(n)||Number.isNaN(e))return NaN;let o=q(r,-1/0,1/0,t,i);if(o!==void 0)return o;if(e<0)return NaN;if(e===0)return n;let u=$i(r,i);return Vt(n,e,t?u:-u)}function Ji(r,n={}){let{location:e=0,scale:t=1,log:i=!1}=n;return h(r,o=>Ki(o,e,t,i))}function Wi(r,n={}){let{location:e=0,scale:t=1,lowerTail:i=!0,logP:o=!1}=n;return h(r,u=>Yi(u,e,t,i,o))}function Zi(r,n={}){let{location:e=0,scale:t=1,lowerTail:i=!0,logP:o=!1}=n;return h(r,u=>zi(u,e,t,i,o))}function kr(r,n){return r===1?1:Math.pow(r,n)}var Nt=2**-1022,Ti=-1022*Math.LN2;function En(r,n){if(n===1)return b([r,0]);let e=r/n;return e>=Nt&&e<1/0&&r<1e300?b(C(r,0,n)):D(b([r,0]),b([n,0]))}function wr(r,n){let e=r[0]*n;return n<1e300&&Number.isFinite(e)?J(r,n):[e,0]}function Sn(r,n){let e=r/n;return e>=Nt&&e<1/0?Math.log(e):Math.log(r)-Math.log(n)}function Yt(...r){return r.every(Number.isFinite)}function Rr(r,n,e,t){if(Number.isNaN(r)||Number.isNaN(n)||Number.isNaN(e))return NaN;if(!(n>0)||!(e>0))return NaN;if(r<0||r===1/0)return d(t);if(r===0&&n<1)return 1/0;if(!Yt(n,e)){let N=kr(r/e,n-1),a=N*(r/e);return t?-a+Math.log(n*N/e):n*N*Math.exp(-a)/e}if(r===0)return n>1?d(t):t?-Math.log(e):1/e;let i=En(r,e),o=O(wr(i,n));if(o[0]===1/0)return d(t);let u=n===1?[0,0]:wr(i,n-1),s=u[0]===-1/0?u:D(u,o),f=n/e;return t?Sn(n,e)+s[0]+s[1]:s[0]<-2500?0:f>=Nt&&f<1/0&&s[0]>-708?f*Math.exp(s[0])*(1+s[1]):Math.exp(Sn(n,e)+s[0])*(1+s[1])}function Pi(r,n,e,t,i){if(Number.isNaN(r)||Number.isNaN(n)||Number.isNaN(e))return NaN;if(!(n>0)||!(e>0))return NaN;if(r<=0)return v(t,i);let o;if(Yt(r,n,e)){let s=wr(En(r,e),n);if(o=O(s),t&&i&&s[0]<-700)return o[0]===0?-1/0:s[0]+s[1]}else if(o=[kr(r/e,n),0],Number.isNaN(o[0]))return NaN;if(!t)return i?-o[0]-o[1]:B(o);let u=o[0]+o[1];return i?Ut(o):-Math.expm1(-u)}function to(r,n,e,t,i){if(Number.isNaN(r)||Number.isNaN(n)||Number.isNaN(e))return NaN;if(!(n>0)||!(e>0))return NaN;let o=q(r,0,1/0,t,i);if(o!==void 0)return o;if(i&&t&&r<Ti&&Yt(n,e)){let f=n<1e300&&Math.abs(r/n)<1e300?Bt([r,0],n):[r/n,0],N=O(f),a=N[0]+N[1];if(a>=Nt&&a<1/0)return e*a;let c=1/e;return c>=Nt&&c<1/0&&f[0]<0?nt([-f[0],-f[1]],c):Math.exp(Math.log(e)+f[0])}let u;i?u=t?X(r):r:u=t?Math.log1p(-r):Math.log(r);let s=kr(-u,1/n);return s>=Nt&&s<1/0||!Yt(n,e)||s===1?e*s:Math.exp(Math.log(e)+Math.log(-u)/n)}function ro(r,n,e={}){let{scale:t=1,log:i=!1}=e;return h(r,o=>Rr(o,n,t,i))}function no(r,n,e={}){let{scale:t=1,lowerTail:i=!0,logP:o=!1}=e;return h(r,u=>Pi(u,n,t,i,o))}function Ar(r,n,e={}){let{scale:t=1,lowerTail:i=!0,logP:o=!1}=e;return h(r,u=>to(u,n,t,i,o))}function $t(r){return r<=.5?{pd:[r,0],qd:Q(1,-r)}:{pd:Q(1,-(1-r)),qd:[1-r,0]}}function Dn(r,n,e,t){if(r<1e290)return rt(0,r,n,e,t);let i=e[0]===1?[-n[0],-(n[0]*n[0])/2]:b(e),o=G([r/2**64,0],J(i,2**64));return o[0]>-1/0?t?o[0]+o[1]:Math.exp(o[0])*(1+o[1]):t?-1/0:0}function _r(r){return!(r>0)||r>1}function eo(r,n,e){if(Number.isNaN(r)||Number.isNaN(n))return NaN;if(_r(n))return NaN;if(xt(r)||r<0||!Number.isFinite(r))return d(e);let t=Math.round(r),{pd:i,qd:o}=$t(n),u=Dn(t,i,o,e);return e?Math.log(n)+u:n*u}function Lr(r,n,e){let{pd:t,qd:i}=$t(n);return Dn(r+1,t,i,e)}function io(r,n,e,t){if(!e)return Lr(r,n,t);let i=Lr(r,n,!0);return t?i<-Math.LN2?Math.log1p(-Lr(r,n,!1)):Math.log(-Math.expm1(i)):-Math.expm1(i)}function oo(r,n,e,t){return Number.isNaN(r)||Number.isNaN(n)?NaN:_r(n)?NaN:r<0?v(e,t):!Number.isFinite(r)||n===1?S(e,t):io(Math.floor(r+1e-7),n,e,t)}function uo(r,n,e,t){if(Number.isNaN(r)||Number.isNaN(n))return NaN;if(_r(n))return NaN;let i=q(r,0,1/0,e,t);if(Number.isNaN(i))return NaN;if(n===1)return 0;if(i!==void 0)return i;let o;return t?o=e?X(r):r:o=e?Math.log1p(-r):Math.log(r),Math.max(0,Math.ceil(o/Math.log1p(-n)-1-1e-12))}function so(r,n,e={}){let t=e.log??!1;return h(r,i=>eo(i,n,t))}function fo(r,n,e={}){let{lowerTail:t=!0,logP:i=!1}=e;return h(r,o=>oo(o,n,t,i))}function Sr(r,n,e={}){let{lowerTail:t=!0,logP:i=!1}=e;return h(r,o=>uo(o,n,t,i))}function Er(r,n){let e=Q(r,n);return{size:r,pd:Y([r,0],e),qd:Y([n,0],e)}}function Dr(r,n){return{size:r,...$t(n)}}function Or(r,n,e){let{size:t,pd:i,qd:o}=n,u=rt(t,r,i,o,e);if(r===0)return u;let s=t/(t+r);return s>=ao?e?u+Math.log(s):u*s:e?u+(Math.log(t)-Math.log(t+r)):u/(t+r)*t}var ao=2**-1022;function It(r,n,e,t){let i=No(r,n);return i!==void 0?e?t?Math.log1p(-i):1-i:t?Math.log(i):i:In(n.size,r+1,n.pd,n.qd,e,t)}function No(r,n){let{size:e,pd:t,qd:i}=n,o=i[0]+i[1],u=t[0]+t[1];if(!(e<=1)||!(o>=.95)||u<1e-4)return;let s=r+1,f=e,N=yn(s,f,i,t),a=N!==void 0?N[0]*(Math.exp(N[1][0])*(1+N[1][1]))/s:rt(s,f,i,t,!1)*f/(s+f);if(!(a>1e-290))return;let c=Q(s,f),m=[1,0],M=[1,0];for(let p=0;p<1e6;p++){let l=Y(F(c,[p,0]),[s+1+p,0]);if(m=G(G(m,l),i),M=F(M,m),m[0]<1e-18*M[0]*u){let y=a*(M[0]+M[1]);return y<=.5?y:void 0}}}function On(r,n,e,t){let i=n.pd[0]+n.pd[1],o=1/i,u=(n.qd[0]+n.qd[1])*o,s=n.size*u,f=Math.sqrt(n.size*u*o),N=(o+u)/f,a;if(i<.05){let m=Ht(r,n.size,1,e,t);if(a=m/Math.log1p(i/(n.qd[0]+n.qd[1])),a===1/0&&m>0&&Number.isFinite(m))return 1/0}else{let m=st(r,{lowerTail:e,logP:t});a=s+f*(m+N*(m*m-1)/6)}let c=Number.isFinite(a)?Math.max(a,0):Number.isFinite(s)?s:0;return c>1e4&&(c=co(c,r,n,e,t)),dn({p:r,lowerTail:e,logP:t,cdf:(m,M,p)=>It(m,n,M,p),y0:c,lo:0,hi:1/0})}function co(r,n,e,t,i){let o=Number.EPSILON,u=n;i?u=t?n*(1+2*o):n*(1-2*o):t?u=n*(1-8*o):1-n>32*o&&(u=n*(1+8*o));let s=i?u:Math.log(u),f=s<=-Math.LN2?t:!t,N=s<=-Math.LN2?s:i?Math.log(-Math.expm1(u)):Math.log1p(-u),a=r,c=It(a,e,f,!0)-N,m=NaN,M=NaN;for(let p=0;p<8&&c!==0;p++){let l;if(Number.isNaN(m)||c===M){let y=(f?1:-1)*Math.exp(Or(a,e,!0)-(c+N));l=a-c/y}else l=a-c*(a-m)/(c-M);if(!Number.isFinite(l)||l<=0)break;if(Math.abs(l-a)<.5)return l;m=a,M=c,a=l,c=It(a,e,f,!0)-N}return a}function mo(r,n,e,t){if(Number.isNaN(r)||Number.isNaN(n)||Number.isNaN(e))return NaN;if(n<0||!(e>0)||e>1)return NaN;if(xt(r)||r<0||!Number.isFinite(r))return d(t);let i=Math.round(r);return n===0||e===1?i===0?t?0:1:d(t):n===1/0?d(t):Or(i,Dr(n,e),t)}function Mo(r,n,e,t,i){return Number.isNaN(r)||Number.isNaN(n)||Number.isNaN(e)?NaN:n<0||!(e>0)||e>1||n===1/0?NaN:r<0?v(t,i):n===0||e===1||!Number.isFinite(r)?S(t,i):It(Math.floor(r+1e-7),Dr(n,e),t,i)}function ho(r,n,e,t,i){if(Number.isNaN(r)||Number.isNaN(n)||Number.isNaN(e))return NaN;if(n<0||e<0||e>1)return NaN;if(e===1||n===0)return 0;if(e===0)return NaN;let o=q(r,0,1/0,t,i);return o!==void 0?o:n===1/0?1/0:On(r,Dr(n,e),t,i)}function po(r,n,e,t){if(Number.isNaN(r)||Number.isNaN(n)||Number.isNaN(e))return NaN;if(n<0||e<0)return NaN;if(xt(r)||r<0||!Number.isFinite(r))return d(t);let i=Math.round(r);return n===0?i===0?t?0:1:e===0?NaN:d(t):e===1/0?d(t):n===1/0?hn(i,e,t):e===0?i===0?t?0:1:d(t):Or(i,Er(n,e),t)}function lo(r,n,e,t,i){return Number.isNaN(r)||Number.isNaN(n)||Number.isNaN(e)?NaN:n<0||e<0||e===1/0?NaN:r<0?v(t,i):n===0||e===0||!Number.isFinite(r)?S(t,i):n===1/0?bn(r,e,t,i):It(Math.floor(r+1e-7),Er(n,e),t,i)}function bo(r,n,e,t,i){if(Number.isNaN(r)||Number.isNaN(n)||Number.isNaN(e))return NaN;if(n===1/0)return gn(r,e,t,i);if(n===0||e===0)return 0;if(n<0||e<0)return NaN;if(e===1/0)return q(r,0,1/0,t,i)??NaN;let o=q(r,0,1/0,t,i);return o!==void 0?o:On(r,Er(n,e),t,i)}function Qr(r){let{prob:n,mu:e}=r;if(n!==void 0&&e!==void 0)throw new TypeError("specify exactly one of prob and mu");if(n!==void 0)return{kind:"prob",v:n};if(e!==void 0)return{kind:"mu",v:e};throw new TypeError("specify exactly one of prob and mu")}function go(r,n,e){let t=e.log??!1,i=Qr(e);return i.kind==="prob"?h(r,o=>mo(o,n,i.v,t)):h(r,o=>po(o,n,i.v,t))}function xo(r,n,e){let{lowerTail:t=!0,logP:i=!1}=e,o=Qr(e);return o.kind==="prob"?h(r,u=>Mo(u,n,o.v,t,i)):h(r,u=>lo(u,n,o.v,t,i))}function Gr(r,n,e){let{lowerTail:t=!0,logP:i=!1}=e,o=Qr(e);return o.kind==="prob"?h(r,u=>ho(u,n,o.v,t,i)):h(r,u=>bo(u,n,o.v,t,i))}var Br=(r,n)=>r>0&&n>0&&Number.isFinite(n),Ft=2**-1022,Qn=1e15;function yo(r,n,e,t){if(Number.isNaN(r)||!Br(n,e))return NaN;if(r<=0||r===1/0)return d(t);if(n===1/0)return NaN;let[i,o]=C(e,0,r);if(i===1/0)return d(t);if(i<Ft){let N=jt(e,r);if(!(Math.abs(N[0]*n)<1/0)||Mr(n)===1/0)return d(t);let a=F(D(n<1e300?J(N,n):[N[0]*n,0],b([r,0])),[-Mr(n),0]);return t?a[0]+a[1]:a[0]<-746?0:O(a)[0]}let u=Number.isFinite(o)&&n<=Qn?n*(o/i)-o:0,s=()=>{let N=ft(i,n,1,!1),a=N*i;return N>=Ft&&a>=Ft?a/r:void 0};if(t){let N=ft(i,n,1,!0),a=N+Math.log(i)-Math.log(r)+u;if(!(Math.abs(a)<.5*Math.abs(N)))return a;let c=s();return c!==void 0&&c>=Ft&&c<1/0?Math.log(c)+u:a}let f=s();return f===void 0?Math.exp(ft(i,n,1,!0)+Math.log(i)-Math.log(r)+u):f*(1+u)}function Io(r,n,e,t,i){if(Number.isNaN(r)||!Br(n,e))return NaN;if(r<=0)return v(t,i);if(r===1/0||n===1/0)return S(t,i);let[o,u]=C(e,0,r);if(o<Ft)return hr(e,n,r,!t,i);let s=hr(o,n,1,!t,i);if(!(u!==0&&Number.isFinite(u)&&Number.isFinite(o)&&n<=Qn))return s;let f=t?-1:1;if(!i)return s+f*ft(o,n,1,!1)*u;if(!(Math.abs(s)<1e8))return s;let N=f*Math.exp(ft(o,n,1,!0)-s)*u;return Number.isFinite(N)?s+N:s}function Fo(r,n,e,t,i){if(Number.isNaN(r)||!Br(n,e))return NaN;let o=q(r,0,1/0,t,i);if(o!==void 0)return o;if(n===1/0)return 0;let{lower:u,logTarget:s,linearTarget:f}=Ct(r,!t,i),N=ln(s,u,n,f);return N!==void 0?Math.log(e)-N[0]>710?1/0:O(D(b([e,0]),N))[0]:e/Ht(r,n,1,!t,i)}function qo(r,n,e={}){let{beta:t=1,log:i=!1}=e;return h(r,o=>yo(o,n,t,i))}function vo(r,n,e={}){let{beta:t=1,lowerTail:i=!0,logP:o=!1}=e;return h(r,u=>Io(u,n,t,i,o))}function Xr(r,n,e={}){let{beta:t=1,lowerTail:i=!0,logP:o=!1}=e;return h(r,u=>Fo(u,n,t,i,o))}var Ur=(r,n)=>r>0&&n>0&&Number.isFinite(n),U=22250738585072014e-324,wo=-1022*Math.LN2,Gn=(r,n,e)=>-Math.sign(e)*Math.exp(Math.log(Math.abs(e))+n*Math.log(r)),Vr=(r,n)=>r<1&&-(n*Math.log(r))<U;function Cr(r,n){let e=Math.pow(r,n);return e<.5?Math.log1p(-e):Vr(r,n)?Math.log(n)+Math.log(-Math.log(r)):Math.log(-Math.expm1(n*Math.log(r)))}function jr(r,n,e){let t=Math.pow(r,n);if(t>=.5){if(!Vr(r,n))return Math.pow(-Math.expm1(n*Math.log(r)),e);let s=Math.pow(n*2**600*-Math.log(r),e)*Math.pow(2,-600*e);return s>=U&&s<1/0?s:Math.exp(e*(Math.log(n)+Math.log(-Math.log(r))))}let i=1-t,o=1-i-t,u=e*o/i;return Math.abs(u)<1e-8?Math.pow(i,e)*(1+u):Math.exp(e*Math.log1p(-t))}var ko=(r,n)=>r===0?0:r*Math.log(n);function Ro(r,n,e,t,i){if(r===0||!(n<1e300)||!(e<1e300))return Math.log(n)+Math.log(e)+ko(n-1,r)+t;let o=b([r,0]),u=F(b([n,0]),b([e,0]));if(n!==1&&(u=F(u,G(o,Q(n,-1)))),e===1||r===1||i<U){if(!Number.isFinite(t))return u[0]+t;let N=F(u,[t,0]);return N[0]+N[1]}let s=i<=1e-10?[Math.log1p(-i),0]:Vr(r,n)?F(b([n,0]),b([-o[0],-o[1]])):b(D([1,0],O(G(o,[n,0])))),f=F(u,G(s,Q(e,-1)));return f[0]+f[1]}function Hr(r,n,e,t){if(Number.isNaN(r)||!Ur(n,e))return NaN;if(r<0||r>1)return d(t);if(n===1/0)return r===1?1/0:d(t);let i=Math.pow(r,n),o=r>0&&i<U,u=r===1?-1/0:Cr(r,n),s=e===1?0:o?Gn(r,n,e-1):(e-1)*u,f=Ro(r,n,e,s,i);if(t)return f;let N=n===1?1:i>1e-290?i/r:Math.pow(r,n-1);if(r>0&&N<U)return Math.exp(f);let a=n*e,c=a*N,m=e===1||r===0?1:o?Math.exp(s):jr(r,n,e-1),M=c*m;return a>=U&&c>=U&&m>=U&&M>U&&M<1/0?M:Math.exp(f)}function Kr(r,n,e,t,i){if(Number.isNaN(r)||!Ur(n,e))return NaN;if(r<=0)return v(t,i);if(r>=1)return S(t,i);if(n===1/0)return v(t,i);let o=Math.pow(r,n),u=o<U,s=u?Gn(r,n,e):e*Cr(r,n);return t?i?Math.max(e,1)*o<1e-10?Math.log(e)+n*Math.log(r)+Math.log1p(-(e-1)*o/2):-s<U?Math.log(e)+Math.log(-Cr(r,n)):s<-Math.LN2&&!u?Math.log1p(-jr(r,n,e)):X(s):-Math.expm1(s):i?s:u?Math.exp(s):jr(r,n,e)}function qt(r,n,e,t,i){if(Number.isNaN(r)||!Ur(n,e))return NaN;let o=q(r,0,1,t,i);if(o!==void 0)return o;if(n===1/0)return 1;let u=t?i?X(r):Math.log1p(-r):i?r:Math.log(r),s=u/e;if(!(s<=-U)){let m=i&&t&&r<wo?r:Math.log(-u),M=D([m,0],b([e,0])),p=M[0]/n;if(!(n<1e300&&Math.abs(p)<1e300))return Math.exp(p);let l=O(Bt(M,n));return l[0]+l[1]}if(s<-Math.LN2)return Math.exp(Math.log1p(-Math.exp(s))/n);let f=-Math.expm1(s),N=1/n;if(!(n<1e300)||!(N<1e300))return Math.pow(f,N);let[a,c]=mn(n,N);return Math.pow(f,N)*(1+Math.log(f)*(1-a-c)/n)}function Ao(r,n,e,t={}){let{log:i=!1}=t;return h(r,o=>Hr(o,n,e,i))}function Lo(r,n,e,t={}){let{lowerTail:i=!0,logP:o=!1}=t;return h(r,u=>Kr(u,n,e,i,o))}function Yr(r,n,e,t={}){let{lowerTail:i=!0,logP:o=!1}=t;return h(r,u=>qt(u,n,e,i,o))}var $r=(r,n)=>r>0&&n>0&&Number.isFinite(n),$=2**-1022;function Xn(r,n){if(r<1e308){let[t,i]=C(r,0,n);if(t<1/0){let o=i/t;return[t,o,Math.log(t)+o]}}let e=jt(r,n);return[1/0,0,e[0]+e[1]]}function Bn(r,n,[e,t,i],o){let u=o*t;if(Math.abs(u)<1e-8){let s=e<1/0?Math.pow(e,-o):Math.pow(r,-o),f=e<1/0?1:Math.pow(n,o);if(s>=$&&f>=$&&f<1/0&&s*f>=$)return s*f*(1-u)}return Math.exp(-o*i)}function _o(r,n,e,t){if(Number.isNaN(r)||!$r(n,e))return NaN;if(r<e||r===1/0)return d(t);if(n===1/0)return r===e?1/0:d(t);let[i,o,u]=Xn(r,e),s=n/e,f=s>=$&&s<1/0?Math.log(s):Math.log(n)-Math.log(e),N=f-(n+1)*u,a=()=>{if(!(s<1/0&&Math.abs(n*o)<1e-8))return 0;let m=Math.pow(i,-n),M=m>=$?0:Math.pow(i,-n/2);return m>=$?s*m/i:M>=$?s*M/i*M:0};if(t){if(!(Math.abs(N)<.5*Math.abs(f)))return N;let m=a();return m>=$&&m<1/0?Math.log(m)+Math.log1p(-(n+1)*o):N}let c=a();return c>=$&&c<1/0?c*(1-(n+1)*o):Math.exp(N)}function So(r,n,e,t,i){if(Number.isNaN(r)||!$r(n,e))return NaN;if(r<=e)return v(t,i);if(r===1/0||n===1/0)return S(t,i);let o=Xn(r,e),u=-n*o[2];return t?i?-u<$?Math.log(n)+Math.log(o[2]):u<-Math.LN2?Math.log1p(-Bn(r,e,o,n)):X(u):-Math.expm1(u):i?u:Bn(r,e,o,n)}function zr(r,n,e,t,i){if(Number.isNaN(r)||!$r(n,e))return NaN;let o=q(r,e,1/0,t,i);if(o!==void 0)return o;if(n===1/0)return e;let s=-(t?i?X(r):Math.log1p(-r):i?r:Math.log(r))/n,f=Math.exp(s);return f<1/0?e*f:Math.exp(Math.log(e)+s)}function Eo(r,n={}){let{a:e=1,b:t=1,log:i=!1}=n;return h(r,o=>_o(o,e,t,i))}function Do(r,n={}){let{a:e=1,b:t=1,lowerTail:i=!0,logP:o=!1}=n;return h(r,u=>So(u,e,t,i,o))}function Oo(r,n={}){let{a:e=1,b:t=1,lowerTail:i=!0,logP:o=!1}=n;return h(r,u=>zr(u,e,t,i,o))}var zt=2**-1022,Jr=(r,n,e)=>Number.isFinite(r)&&Number.isFinite(n)&&r<n&&r<=e&&e<=n,Wr=(r,n)=>Number.isFinite(n-r)?1:.5;function Cn(r,n,e,t,i){if(Number.isNaN(r)||!Jr(n,e,t))return NaN;if(r<n||r>e)return d(i);let o=Wr(n,e);if(o!==1){let a=Cn(r*o,n*o,e*o,t*o,i);return i?a+Math.log(o):a*o}let u=e-n,s=r===t?0:r<t?(t-r)/(t-n):(r-t)/(e-t);if(s<.5)return i?Math.LN2-Math.log(u)+Math.log1p(-s):2*(1-s)/u;let f=r<t?(r-n)/(t-n):(e-r)/(e-t);if(f>=zt)return i?Math.LN2-Math.log(u)+Math.log(f):2*f/u;let N=Math.LN2-Math.log(u)+(r<t?Math.log(r-n)-Math.log(t-n):Math.log(e-r)-Math.log(e-t));return i?N:Math.exp(N)}function Qo(r,n,e,t){let i=e-n,o=(f,N,a,c)=>f>=zt&&N>=zt?Math.log(f)+Math.log(N):2*Math.log(a)-Math.log(c)-Math.log(i);if(r<=t){let[f,N]=[(r-n)/(t-n),(r-n)/i];return[f*N,(e-t)/i+(t-r)/(t-n)*(N+(t-n)/i),o(f,N,r-n,t-n)]}let[u,s]=[(e-r)/(e-t),(e-r)/i];return[(t-n)/i+(r-t)/(e-t)*(s+(e-t)/i),u*s,o(u,s,e-r,e-t)]}function Go(r,n,e,t){let i=e-n,[o,u,s,f,N]=r<=t?[e-t,t-r,t-n,(r-n)/i,(t-n)/i]:[t-n,r-t,e-t,(e-r)/i,(e-t)/i],a=Math.log(u)-Math.log(s)+Math.log(f+N);if(!(o>0))return a;let c=Math.log(o)-Math.log(i),m=Math.max(c,a);return m+Math.log(Math.exp(c-m)+Math.exp(a-m))}function Bo(r,n,e,t,i,o){if(Number.isNaN(r)||!Jr(n,e,t))return NaN;if(r<=n)return v(i,o);if(r>=e)return S(i,o);let u=Wr(n,e),[s,f,N]=Qo(r*u,n*u,e*u,t*u),a=Math.min(i?s:f,1);return o?a>.5?Math.log1p(-(i?f:s)):a>=zt?Math.log(a):i===r<=t?N:Go(r*u,n*u,e*u,t*u):a}function jn(r,n,e,t,i,o){if(Number.isNaN(r)||!Jr(n,e,t))return NaN;let u=q(r,n,e,i,o);if(u!==void 0)return u;let s=Wr(n,e);if(s!==1)return jn(r,n*s,e*s,t*s,i,o)/s;let f=e-n,N=o?Math.exp(r):r,a=o&&N<2**-1022?Math.exp(r/2):Math.sqrt(N),c=i?N:o?-Math.expm1(r):1-r,m=i?o?-Math.expm1(r):1-r:N,M=(t-n)/f,p=(e-t)/f,l;if(M>0&&c<=M){let y=c/M;l=y<=.5?n+(i?a:Math.sqrt(c))*Math.sqrt(f)*Math.sqrt(t-n):t-(t-n)*((m-p)/M)/(1+Math.sqrt(y))}else{let y=m/p;l=y<=.5?e-(i?Math.sqrt(m):a)*Math.sqrt(f)*Math.sqrt(e-t):t+(e-t)*((c-M)/p)/(1+Math.sqrt(y))}return Math.min(Math.max(l,n),e)}function Xo(r,n={}){let{a:e=-1,b:t=1,log:i=!1}=n,o=n.c??(e+t)/2;return h(r,u=>Cn(u,e,t,o,i))}function Co(r,n={}){let{a:e=-1,b:t=1,lowerTail:i=!0,logP:o=!1}=n,u=n.c??(e+t)/2;return h(r,s=>Bo(s,e,t,u,i,o))}function Zr(r,n={}){let{a:e=-1,b:t=1,lowerTail:i=!0,logP:o=!1}=n,u=n.c??(e+t)/2;return h(r,s=>jn(s,e,t,u,i,o))}var jo=2**-1022,Tr=(r,n)=>!Number.isNaN(r)&&n>0&&Number.isFinite(n);function Uo(r,n,e,t){if(Number.isNaN(r)||!Tr(n,e))return NaN;if(!Number.isFinite(n))return t?-1/0:0;let i=C(r,n,e),o=i[0]<0?[-i[0],-i[1]]:[i[0],i[1]];if(t)return-o[0]-o[1]-Math.log(2*e);let u=B(o);return u>=jo?u/(2*e):nt(o,2*e)}function Vo(r,n,e,t,i){if(Number.isNaN(r)||!Tr(n,e))return NaN;if(!Number.isFinite(n)){let f=n===1/0?0:1,N=t?f:1-f;return i?Math.log(N):N}let o=C(r,n,e),u=o[0]<0?[-o[0],-o[1]]:[o[0],o[1]],s=B(u)/2;return t===o[0]<0?i?-u[0]-u[1]-Math.LN2:s:i?Math.log1p(-s):1-s}function Ho(r,n,e,t,i){if(Number.isNaN(r)||!Tr(n,e))return NaN;let o=q(r,-1/0,1/0,t,i);if(o!==void 0)return o;if(!Number.isFinite(n))return n;let{lower:u,logTarget:s,linearTarget:f}=Ct(r,t,i),N=f!==void 0?Math.log(2*f):Math.LN2+s;return Vt(n,e,u?N:-N)}function Ko(r,n={}){let{mu:e=0,sigma:t=1,log:i=!1}=n;return h(r,o=>Uo(o,e,t,i))}function Yo(r,n={}){let{mu:e=0,sigma:t=1,lowerTail:i=!0,logP:o=!1}=n;return h(r,u=>Vo(u,e,t,i,o))}function $o(r,n={}){let{mu:e=0,sigma:t=1,lowerTail:i=!0,logP:o=!1}=n;return h(r,u=>Ho(u,e,t,i,o))}var tn=(r,n)=>Number.isFinite(r)&&Number.isFinite(n)&&r<n;function zo(r,n,e,t){if(Number.isNaN(r)||!tn(n,e))return NaN;if(r<n||r>e)return d(t);if(r===n||r===e)return 1/0;if(!t)return 1/(Math.PI*Math.sqrt(r-n)*Math.sqrt(e-r));let i=F(b(Q(r,-n)),b(Q(e,-r)));return-Jt[0]-.5*i[0]-(Jt[1]+.5*i[1])}var Jt=[1.1447298858494002,10265951162707826e-33],Pr=[Math.LN2-Jt[0],23190468138462996e-33-Jt[1]],Jo=[-Pr[0],-Pr[1]],Wo=1e-20,Zo=2**-1022;function To(r,n,e,t,i){if(Number.isNaN(r)||!tn(n,e))return NaN;if(r<=n)return v(t,i);if(r>=e)return S(t,i);let o=e-n,u=r-n<=e-r,s=u?r-n:e-r,f=s/o;if(f<Wo){let N=F(Pr,J(D(b([s,0]),b([o,0])),.5)),a=Math.sqrt(s)/Math.sqrt(o)*(2/Math.PI),c=a>=Zo?a:Math.exp(N[0]);return t===u?i?N[0]+N[1]:c:i?Math.log1p(-c):1-c}return u?gr(f,.5,.5,t,i):gr(f,.5,.5,!t,i)}function rn(r,n,e,t,i){if(Number.isNaN(r)||!tn(n,e))return NaN;let o=q(r,n,e,t,i);if(o!==void 0)return o;let u=i?[r,0]:b([r,0]),s=i?r>-Math.LN2?b([-Math.expm1(r),0]):[Math.log1p(-Math.exp(r)),0]:r>=.5?b([1-r,0]):[Math.log1p(-r),0],[f,N]=t?[u,s]:[s,u];for(let[c,m]of[[f,!0],[N,!1]]){if(!(c[0]<-40))continue;let M=F(J(F(c,Jo),2),b([e-n,0])),p=M[0]<-746?0:O(M)[0];return m?Math.min(n+p,e):Math.max(e-p,n)}let a=xr(r,.5,.5,t,i);return a<=.5?n+(e-n)*a:e-(e-n)*xr(r,.5,.5,!t,i)}function Po(r,n={}){let{a:e=0,b:t=1,log:i=!1}=n;return h(r,o=>zo(o,e,t,i))}function tu(r,n={}){let{a:e=0,b:t=1,lowerTail:i=!0,logP:o=!1}=n;return h(r,u=>To(u,e,t,i,o))}function nn(r,n={}){let{a:e=0,b:t=1,lowerTail:i=!0,logP:o=!1}=n;return h(r,u=>rn(u,e,t,i,o))}var w={mean:NaN,variance:NaN,sd:NaN,median:NaN,mode:NaN,skewness:NaN,kurtosis:NaN};function R(r,n,e,t,i,o){return{mean:r,variance:n,sd:Math.sqrt(n),median:e,mode:t,skewness:i,kurtosis:o}}function Un(r,n,e,t){return Hn(i=>i,r,n,n,e,t)}function Hn(r,n,e,t,i,o){let u=50*Number.EPSILON,s=[2,3,4].map(N=>{let a=M=>(r(M)-e)**N*n(M),c=Fr(a,i,t,0,u,200).result,m=o===1/0?qn(a,t,1,0,u,200).result:Fr(a,t,o,0,u,200).result;return c+m}),f=s[0];return{variance:f,skewness:s[1]/f**1.5,kurtosis:s[2]/(f*f)-3}}function ru(r,n){let[e,t]=G([r,0],[n,0]),i=Math.floor(e);return e===i&&t<0?i-1:i}function Vn(r,n,e){let t=D(G(r,[n,0]),[e,0]);return t[0]+t[1]<=0}var Wt=(r,n)=>r[n]!==void 0;function nu(r,n={}){let e=n;switch(r){case"norm":{let{mean:t=0,sd:i=1}=e;return Number.isFinite(t)&&i>0&&Number.isFinite(i)?R(t,i*i,t,t,0,0):w}case"lnorm":{let{meanlog:t=0,sdlog:i=1}=e;if(!(Number.isFinite(t)&&i>0&&Number.isFinite(i)))return w;let o=i*i,u=Math.expm1(o),s=Math.exp(o);return R(Math.exp(t+o/2),u*Math.exp(2*t+o),Math.exp(t),Math.exp(t-o),(s+2)*Math.sqrt(u),u*(16+u*(15+u*(6+u))))}case"unif":{let{min:t=0,max:i=1}=e;if(!(Number.isFinite(t)&&Number.isFinite(i)&&t<i))return w;let o=t+(i-t)/2;return R(o,(i-t)**2/12,o,NaN,0,-1.2)}case"exp":{let{rate:t=1}=e;return t>0&&Number.isFinite(t)?R(1/t,1/(t*t),Math.LN2/t,0,2,6):w}case"gamma":{let t=e.shape??NaN,i=Wt(e,"scale")?e.scale:1/(e.rate??1);return t>0&&Number.isFinite(t)&&i>0&&Number.isFinite(i)?R(t*i,t*i*i,pr(.5,t,{scale:i}),t>=1?(t-1)*i:0,2/Math.sqrt(t),6/t):w}case"chisq":{let t=e.df??NaN;return t>0&&Number.isFinite(t)?R(t,2*t,lr(.5,t),Math.max(t-2,0),Math.sqrt(8/t),12/t):w}case"beta":{let t=e.shape1??NaN,i=e.shape2??NaN;if(!(t>0&&i>0&&Number.isFinite(t)&&Number.isFinite(i)))return w;let o=t+i,u;return t>1&&i>1?u=(t-1)/(o-2):t===1&&i===1||t<1&&i<1?u=NaN:u=t<=1&&i>=1?0:1,R(t/o,t*i/(o*o*(o+1)),yr(.5,t,i),u,2*(i-t)*Math.sqrt(o+1)/((o+2)*Math.sqrt(t*i)),6*((t-i)**2*(o+1)-t*i*(o+2))/(t*i*(o+2)*(o+3)))}case"t":{let t=e.df??NaN;if(!(t>0))return w;let i=t>2?t===1/0?1:t/(t-2):t>1?1/0:NaN,o=t>4?t===1/0?0:6/(t-4):t>2?1/0:NaN;return R(t>1?0:NaN,i,0,0,t>3?0:NaN,o)}case"f":{let t=e.df1??NaN,i=e.df2??NaN;if(!(t>0&&i>0&&Number.isFinite(t)&&Number.isFinite(i)))return w;let o=i>2?i/(i-2):NaN,u=i>4?2*i*i*(t+i-2)/(t*(i-2)**2*(i-4)):i>2?1/0:NaN,s=i>6?(2*t+i-2)*Math.sqrt(8*(i-4))/((i-6)*Math.sqrt(t*(t+i-2))):NaN,f=i>8?12*(t*(5*i-22)*(t+i-2)+(i-4)*(i-2)**2)/(t*(i-6)*(i-8)*(t+i-2)):NaN;return R(o,u,br(.5,t,i),t>2?(t-2)/t*(i/(i+2)):0,s,f)}case"cauchy":{let{location:t=0,scale:i=1}=e;return Number.isFinite(t)&&i>0&&Number.isFinite(i)?R(NaN,NaN,t,t,NaN,NaN):w}case"weibull":{let t=e.shape??NaN,i=e.scale??1;if(!(t>0&&Number.isFinite(t)&&i>0&&Number.isFinite(i)))return w;let o=Mn(1+1/t),u=Un(s=>Rr(s,t,1,!1),o,0,1/0);return R(i*o,i*i*u.variance,Ar(.5,t,{scale:i}),t>1?i*Math.pow((t-1)/t,1/t):0,u.skewness,u.kurtosis)}case"logis":{let{location:t=0,scale:i=1}=e;return Number.isFinite(t)&&i>0&&Number.isFinite(i)?R(t,i*i*Math.PI*Math.PI/3,t,t,0,1.2):w}case"binom":{let t=e.size??NaN,i=e.prob??NaN;if(!(Number.isInteger(t)&&t>=0&&i>=0&&i<=1))return w;let o=1-i;return R(t*i,t*i*o,yt(.5,t,i),Math.min(t,ru(t+1,i)),(o-i)/Math.sqrt(t*i*o),(1-6*i*o)/(t*i*o))}case"pois":{let t=e.lambda??NaN;return t>0&&Number.isFinite(t)?R(t,t,dr(.5,t),Math.floor(t),1/Math.sqrt(t),1/t):w}case"geom":{let t=e.prob??NaN;if(!(t>0&&t<=1))return w;let i=1-t;return R(i/t,i/(t*t),Sr(.5,t),0,(2-t)/Math.sqrt(i),6+t*t/i)}case"nbinom":{let t=e.size??NaN;if(!(t>0&&Number.isFinite(t)))return w;let i=Wt(e,"mu")?t/(t+e.mu):e.prob??NaN;if(!(i>0&&i<=1))return w;let o=1-i,u=Wt(e,"mu")?{mu:e.mu}:{prob:i},s=N=>Wt(e,"mu")?Vn([N,0],t,(t-1)*e.mu):Vn(F([t-1,0],[N,0]),i,t-1),f=0;if(t>1){for(f=Math.max(0,Math.floor((t-1)*o/i)-1);s(f+1);)f++;for(;f>0&&!s(f);)f--}return R(t*o/i,t*o/(i*i),Gr(.5,t,u),f,(2-i)/Math.sqrt(t*o),6/t+i*i/(t*o))}case"hyper":{let t=e.m??NaN,i=e.n??NaN,o=e.k??NaN;if(!([t,i,o].every(N=>Number.isInteger(N)&&N>=0)&&o<=t+i))return w;let u=t+i,s=Math.floor((o+1)*(t+1)/(u+2)),f=((u-1)*u*u*(u*(u+1)-6*t*i-6*o*(u-o))+6*o*t*i*(u-o)*(5*u-6))/(o*t*i*(u-o)*(u-2)*(u-3));return R(o*t/u,o*t/u*(i/u)*(u-o)/(u-1),Ir(.5,t,i,o),s,(u-2*t)*Math.sqrt(u-1)*(u-2*o)/(Math.sqrt(o*t*i*(u-o))*(u-2)),f)}case"invgamma":{let t=e.alpha??NaN,i=e.beta??1;return t>0&&Number.isFinite(t)&&i>0&&Number.isFinite(i)?R(t>1?i/(t-1):1/0,t>2?i*i/((t-1)**2*(t-2)):t>1?1/0:NaN,Xr(.5,t,{beta:i}),i/(t+1),t>3?4*Math.sqrt(t-2)/(t-3):NaN,t>4?(30*t-66)/((t-3)*(t-4)):NaN):w}case"kumar":{let t=e.a??NaN,i=e.b??NaN;if(!(t>0&&i>0&&Number.isFinite(t)&&Number.isFinite(i)))return w;let o=i*Math.exp(xn(1+1/t,i)),u=i<1?Hn(f=>qt(f,t,i,!0,!1),()=>1,o,Kr(o,t,i,!0,!1),0,1):Un(f=>Hr(f,t,i,!1),o,0,1),s;return t>=1&&i>=1?s=t===1&&i===1?NaN:Math.pow((t-1)/(t*i-1),1/t):t<1&&i<1?s=NaN:s=t<1?0:1,R(o,u.variance,Yr(.5,t,i),s,u.skewness,u.kurtosis)}case"pareto":{let{a:t=1,b:i=1}=e;return t>0&&Number.isFinite(t)&&i>0&&Number.isFinite(i)?R(t>1?t*i/(t-1):1/0,t>2?i*i*t/((t-1)**2*(t-2)):t>1?1/0:NaN,i*Math.pow(2,1/t),i,t>3?2*(1+t)/(t-3)*Math.sqrt((t-2)/t):NaN,t>4?6*(t**3+t*t-6*t-2)/(t*(t-3)*(t-4)):NaN):w}case"triang":{let{a:t=-1,b:i=1}=e,o=e.c??(t+i)/2;if(!(Number.isFinite(t)&&Number.isFinite(i)&&t<i&&t<=o&&o<=i))return w;let u=t*t+i*i+o*o-t*i-t*o-i*o;return R((t+i+o)/3,u/18,Zr(.5,{a:t,b:i,c:o}),o,Math.SQRT2*(t+i-2*o)*(2*t-i-o)*(t-2*i+o)/(5*u**1.5),-.6)}case"laplace":{let{mu:t=0,sigma:i=1}=e;return Number.isFinite(t)&&i>0&&Number.isFinite(i)?R(t,2*i*i,t,t,0,3):w}case"arcsine":{let{a:t=0,b:i=1}=e;return Number.isFinite(t)&&Number.isFinite(i)&&t<i?R(t+(i-t)/2,(i-t)**2/8,nn(.5,{a:t,b:i}),NaN,0,-1.5):w}}throw new RangeError(`unknown distribution '${String(r)}'`)}var ou=[82758667,1871391091,4127413238,3672831523,69195019,1871391091,3672091415,3528743235,69195019],uu=[1511326704,3759209742,1610795712,4292754251,1511326704,3889917532,3859662829,4292754251,3708466080],su=[2427906178,3580155704,949770784,226153695,1230515664,3580155704,1988835001,986791581,1230515664],fu=[1464411153,277697599,1610723613,32183930,1464411153,1022607788,2824425944,32183930,2093834863];function au(r,n,e){let t=Math.floor(n/65536);return(r*t%e*65536+r*(n-t*65536))%e}function Kn(r,n,e){let t=r[0];if(!Number.isInteger(t)||t%100!==7)throw new RangeError("the state must be a .Random.seed of L'Ecuyer-CMRG (kind code ending in 07)");let i=vn(r),o=new Int32Array(7);o[0]=t;for(let u=0;u<2;u++){let s=u===0?n:e,f=u===0?4294967087:4294944443;for(let N=0;N<3;N++){let a=0;for(let c=0;c<3;c++)a=(a+au(s[3*N+c],i[3*u+c],f))%f;o[1+3*u+N]=a|0}}return o}function Nu(r){return Kn(r,su,fu)}function cu(r){return Kn(r,ou,uu)}var mu=-.5,Mu=.3333333,hu=-.2500068,pu=.2000118,lu=-.1661269,du=.1421878,bu=-.1384794,gu=.125006,xu=1/7,yu=1/12,Iu=1/24,Yn=.3989422804014327,Fu=[1,1,2,6,24,120,720,5040,40320,362880],Z=0,$n=0,zn=new Float64Array(36),Zt=0,Jn=0,en=0,Tt=0,Wn=0,vt=0,Zn=0,Tn=0,Pn=0,ct=0,wt=0,te=0,re=0,ne=0,ee=0,kt=0;function mt(r){if(!Number.isFinite(r)||r<0)return NaN;if(r<=0)return 0;let n=r>=10,e=!1;if(!(n&&r===Zt))if(n)e=!0,Zt=r,vt=Math.sqrt(r),Zn=6*r*r,Pn=Math.floor(r-1.1484);else for(r!==Zt&&(Zt=r,$n=Math.max(1,Math.trunc(r)),Z=0,Tt=Wn=en=Math.exp(-r));;){let M=g();if(M<=Wn)return 0;if(Z>0){let p=M>.458?Math.min(Z,$n):1;for(let l=p;l<=Z;l++)if(M<=zn[l])return l;if(Z===35)continue}Z++;for(let p=Z;p<=35;p++)if(en*=r/p,Tt+=en,zn[p]=Tt,M<=Tt)return Z=p,p;Z=35}let t=-1,i=0,o=0,u=0,s=r+vt*at();if(s>=0&&(t=Math.floor(s),t>=Pn||(i=t,o=r-i,u=g(),Zn*u>=o*o*o)))return t;(e||r!==Jn)&&(Jn=r,Tn=Yn/vt,ct=Iu/r,wt=.3*ct*ct,kt=xu*ct*wt,ee=wt-15*kt,ne=ct-6*wt+45*kt,re=1-ct+3*wt-15*kt,te=.1069/r);let f=0,N=0,a=0,c=0,m=()=>{if(t<10)f=-r,N=Math.pow(r,t)/Fu[t];else{let l=yu/i;l=l*(1-4.8*l*l);let y=o/i;Math.abs(y)<=.25?f=i*y*y*(((((((gu*y+bu)*y+du)*y+lu)*y+pu)*y+hu)*y+Mu)*y+mu)-l:f=i*Math.log(1+y)-o-l,N=Yn/Math.sqrt(i)}let M=(.5-o)/vt,p=M*M;a=-.5*p,c=Tn*(((kt*p+ee)*p+ne)*p+re)};if(s>=0&&(m(),c-u*c<=N*Math.exp(f-a)))return t;for(;;){let M=W();u=2*g()-1;let p=1.8+(u>=0?M:-M);if(p>-.6744&&(t=Math.floor(r+vt*p),i=t,o=r-i,m(),te*Math.abs(u)<=N*Math.exp(f+M)-c*Math.exp(a+M)))break}return t}function qu(r,n){return I(r,()=>mt(n))}function vu(r,n){return I(r,()=>!Number.isFinite(n)||n<=0||n>1?NaN:mt(W()*((1-n)/n)))}function wu(r,n,e){let{prob:t,mu:i}=e;if(t===void 0==(i===void 0))throw new TypeError("specify exactly one of prob and mu");let o=Number.isFinite(n)?n:Number.MAX_VALUE/2;if(i!==void 0)return I(r,()=>!Number.isFinite(i)||Number.isNaN(n)||n<=0||i<0?NaN:i===0?0:mt(T(o,i/o)));let u=t;return I(r,()=>!Number.isFinite(u)||Number.isNaN(n)||n<=0||u<=0||u>1?NaN:u===1?0:mt(T(o,(1-u)/u)))}var ku=5.656854,Ru=.36787944117144233,Au=.04166669,Lu=.02083148,_u=.00801191,Su=.00144121,Eu=-7388e-8,Du=24511e-8,Ou=2424e-7,Qu=.3333333,Gu=-.250003,Bu=.2000062,Xu=-.1662921,Cu=.1423657,ju=-.1367177,Uu=.1233795,ie=0,oe=0,j=0,Mt=0,ue=0,on=0,Rt=0,At=0,Pt=0;function se(r){let n=r/(j+j);return Math.abs(n)<=.25?on+.5*r*r*((((((Uu*n+ju)*n+Cu)*n+Xu)*n+Bu)*n+Gu)*n+Qu)*n:on-j*r+.25*r*r+(Mt+Mt)*Math.log(1+n)}function T(r,n){if(Number.isNaN(r)||Number.isNaN(n))return NaN;if(r<=0||n<=0)return n===0||r===0?0:NaN;if(!Number.isFinite(r)||!Number.isFinite(n))return 1/0;if(r<1){let u=1+Ru*r,s;for(;;){let f=u*g();if(f>=1){if(s=-Math.log((u-f)/r),W()>=(1-r)*Math.log(s))break}else if(s=Math.exp(Math.log(f)/r),W()>=s)break}return n*s}r!==ie&&(ie=r,Mt=r-.5,j=Math.sqrt(Mt),ue=ku-j*12);let e=at(),t=j+.5*e,i=t*t;if(e>=0)return n*i;let o=g();if(ue*o<=e*e*e)return n*i;if(r!==oe){oe=r;let u=1/r;on=((((((Ou*u+Du)*u+Eu)*u+Su)*u+_u)*u+Lu)*u+Au)*u,r<=3.686?(Rt=.463+j+.178*Mt,At=1.235,Pt=.195/j-.079+.16*j):r<=13.022?(Rt=1.654+.0076*Mt,At=1.68/j+.275,Pt=.062/j+.024):(Rt=1.77,At=.75,Pt=.1515/j)}if(t>0){let u=se(e);if(Math.log(1-o)<=u)return n*i}for(;;){let u=W();if(o=g(),o=o+o-1,e=o<0?Rt-At*u:Rt+At*u,e>=-.71874483771719){let s=se(e);if(s>0){let f=Math.expm1(s);if(Pt*Math.abs(o)<=f*Math.exp(u-.5*e*e))break}}}return t=j+.5*e,n*t*t}function Vu(r,n,e={}){let t=pn(e);return I(r,()=>T(n,t))}function Lt(r){return!Number.isFinite(r)||r<0?NaN:T(r/2,2)}function Hu(r,n){if(!Number.isFinite(r)||!Number.isFinite(n)||r<0||n<0)return NaN;if(n===0)return r===0?0:T(r/2,2);let e=mt(n/2);return e>0&&(e=Lt(2*e)),r>0&&(e+=T(r/2,2)),e}function it(r,n,e={}){let{ncp:t}=e;return t===void 0?I(r,()=>Lt(n)):I(r,()=>Hu(n,t))}function Ku(r,n,e={}){let{ncp:t}=e;if(t===void 0)return I(r,()=>Number.isNaN(n)||n<=0?NaN:Number.isFinite(n)?at()/Math.sqrt(Lt(n)/n):at());if(Number.isNaN(t))return I(r,()=>NaN);let i=I(r,()=>Rn(t,1)),o=it(r,n);return i.map((u,s)=>u/Math.sqrt(o[s]/n))}function Yu(r,n,e,t={}){let{ncp:i}=t;if(i===void 0)return I(r,()=>{if(Number.isNaN(n)||Number.isNaN(e)||n<=0||e<=0)return NaN;let s=Number.isFinite(n)?Lt(n)/n:1,f=Number.isFinite(e)?Lt(e)/e:1;return s/f});let o=it(r,n,{ncp:i}),u=it(r,e);return o.map((s,f)=>s/n/(u[f]/e))}var $u=1024*Math.LN2,_t=0,fe=0,un=0,ae=0,Ne=0,ce=-1,me=-1;function sn(r,n){let e=_t*Math.log(r/(1-r));if(e<=$u){let t=n*Math.exp(e);return Number.isFinite(t)||(t=Number.MAX_VALUE),[e,t]}return[e,Number.MAX_VALUE]}function zu(r,n){if(Number.isNaN(r)||Number.isNaN(n)||r<0||n<0)return NaN;if(!Number.isFinite(r)&&!Number.isFinite(n))return .5;if(r===0&&n===0)return g()<.5?0:1;if(!Number.isFinite(r)||n===0)return 1;if(!Number.isFinite(n)||r===0)return 0;let e=ce===r&&me===n;e||(ce=r,me=n);let t=Math.min(r,n),i=Math.max(r,n),o=t+i,u,s;if(t<=1){for(e||(_t=1/t,un=1+i-t,ae=un*(.0138889+.0416667*t)/(i*_t-.777778),Ne=.25+(.5+.25/un)*t);;){let a=g(),c=g(),m;if(a<.5){let M=a*c;if(m=a*M,.25*c+m-M>=ae)continue}else{if(m=a*a*c,m<=.25){[u,s]=sn(a,i);break}if(m>=Ne)continue}if([u,s]=sn(a,i),o*(Math.log(o/(t+s))+u)-1.3862944>=Math.log(m))break}return r===t?t/(t+s):s/(t+s)}e||(_t=Math.sqrt((o-2)/(2*t*i-o)),fe=t+1/_t);let f,N;do{let a=g(),c=g();[u,s]=sn(a,t);let m=a*a*c;f=fe*u-1.3862944;let M=t+f-s;if(M+2.609438>=5*m||(N=Math.log(m),M>N))break}while(f+o*Math.log(o/(i+s))<N);return r!==t?i/(i+s):s/(i+s)}function Ju(r,n,e,t={}){let{ncp:i}=t;if(i===void 0)return I(r,()=>zu(n,e));let o=it(r,2*n,{ncp:i}),u=it(r,2*e);return o.map((s,f)=>s/(s+u[f]))}var Wu=2147483647,ot=0,St=0,ht=0,et=0,tr=0,rr=0,Me=0,he=0,Et=0,nr=0,er=0,pt=0,ir=0,fn=-1,pe=-1,V=0;function or(r){let n=r*r;return(13860-(462-(132-(99-140/n)/n)/n)/n)/r/166320}function ur(r,n){if(!Number.isFinite(r))return NaN;let e=Math.round(r);if(e!==r)return NaN;if(!Number.isFinite(n)||e<0||n<0||n>1)return NaN;if(e===0||n===0)return 0;if(n===1)return e;if(e>=Wu)return yt(g(),e,n,{lowerTail:!1});let t=e,i=Math.min(n,1-n),o=1-i,u=t*i,s=i/o,f=s*(t+1),N;if(n!==fn||t!==pe)if(fn=n,pe=t,u<30)he=kn(o,t),N=!0;else{N=!1,St=u+i,V=Math.trunc(St),ht=u*o,et=Math.trunc(2.195*Math.sqrt(ht)-4.6*o)+.5,pt=V+.5,Et=pt-et,ir=pt+et,ot=.134+20.5/(15.3+V);let c=(St-Et)/(St-Et*i);nr=c*(1+.5*c),c=(ir-St)/(ir*o),er=c*(1+.5*c),tr=et*(1+ot+ot),rr=tr+ot/nr,Me=rr+ot/er}else N=u<30;let a;if(N)t:for(;;){a=0;let c=he,m=g();for(;;){if(m<c)break t;if(a>110)break;m-=c,a++,c*=f/a-s}}else for(;;){let c=g()*Me,m=g();if(c<=et){a=Math.trunc(pt-et*m+c);break}if(c<=tr){let p=Et+(c-et)/ot;if(m=m*ot+1-Math.abs(pt-p)/et,m>1||m<=0)continue;a=Math.trunc(p)}else if(c>rr){if(a=Math.trunc(ir-Math.log(m)/er),a>t)continue;m=m*(c-rr)*er}else{if(a=Math.trunc(Et+Math.log(m)/nr),a<0)continue;m=m*(c-tr)*nr}let M=Math.abs(a-V);if(M<=20||M>=ht/2-1){let p=1;if(V<a)for(let l=V+1;l<=a;l++)p*=f/l-s;else if(V>a)for(let l=a+1;l<=V;l++)p/=f/l-s;if(m<=p)break}else{let p=M/ht*((M*(M/3+.625)+.1666666666666)/ht+.5),l=-M*M/(2*ht),y=Math.log(m);if(y<l-p)break;if(y<=l+p){let ut=a+1,lt=V+1,dt=t+1-V,tt=t-a+1;if(y<=pt*Math.log(lt/ut)+(t-V+.5)*Math.log(dt/tt)+(a-V)*Math.log(tt*i/(ut*o))+or(lt)+or(dt)+or(ut)+or(tt))break}}}return fn>.5&&(a=t-a),a}function Zu(r,n,e){return I(r,()=>ur(n,e))}function Tu(r,n,e){if(!Number.isFinite(n)||n<0||Math.round(n)!==n)throw new RangeError("size must be a non-negative integer");let t=0;for(let s of e){if(!Number.isFinite(s)||s<0)throw new RangeError("prob must contain non-negative finite numbers");t+=s}if(t===0)throw new RangeError("prob must contain at least one positive value");let i=e.map(s=>s/t),o=i.length,u=()=>{let s=new Array(o).fill(0),f=n,N=1;for(let a=0;a<o-1;a++){if(i[a]){let c=i[a]/N;s[a]=c<1?ur(f,c):f,f-=s[a]}if(f<=0)return s;N-=i[a]}return s[o-1]=f,s};if(!Number.isFinite(r)||r<0)throw new RangeError("n must be a non-negative finite number");return Array.from({length:Math.trunc(r)},u)}function Pu(r,n){return I(r,()=>{if(Number.isNaN(n))return NaN;let e=Math.round(n);if(e<0)return NaN;if(e===0)return 0;let t=0;for(let i=1;i<=e;i++)t+=i*Math.floor(g()+.5);return t})}function ts(r,n,e){return I(r,()=>{if(Number.isNaN(n)||Number.isNaN(e))return NaN;let t=Math.round(n),i=Math.round(e);if(t<0||i<0)return NaN;if(t===0||i===0)return 0;let o=t+i,u=new Int32Array(o);for(let f=0;f<o;f++)u[f]=f;let s=0;for(let f=0;f<i;f++){let N=wn(o);s+=u[N],u[N]=u[--o]}return s-i*(i-1)/2})}var an=2147483647,rs=.9189385332046728,ns=.0078,es=.0034,is=1e25,os=57.564627324851145,us=[0,0,.6931471805599453,1.791759469228055,3.1780538303479458,4.787491742782046,6.579251212010101,8.525161361065415];function k(r){if(r<0)return 0;if(r<=7)return us[r];let n=r,e=n*n;return(n+.5)*Math.log(n)-n+rs+(.0833333333333333-.00277777777777778/e)/n}var le=-1,de=-1,be=-1,E=0,Dt=0,Ot=0,x=0,_=0,A=0,P=0,ge=0,cr=0,Qt=0,K=0,z=0,xe=0,ye=0,sr=0,fr=0,ar=0,Nr=0,Ie=0;function ss(r,n,e){if(!Number.isFinite(r)||!Number.isFinite(n)||!Number.isFinite(e))return NaN;if(r=Math.round(r),n=Math.round(n),e=Math.round(e),r<0||n<0||e<0||e>r+n)return NaN;if(r>=an||n>=an||e>=an)return e===1?ur(e,r/(r+n)):Fn(g(),r,n,e,!1,!1);let t=r,i=n,o=e,u,s;t!==de||i!==be?(u=!0,s=!0):o!==le?(u=!1,s=!0):(u=!1,s=!1),u&&(de=t,be=i,P=t+i,t<=i?(_=t,A=i):(_=i,A=t)),s&&(le=o,x=o+o>=P?Math.trunc(P-o):o),(u||s)&&(E=Math.trunc((x+1)*(_+1)/(P+2)),Dt=Math.max(0,x-A),Ot=Math.min(_,x));let f;if(Dt===Ot)f=Ot;else if(E-Dt<10){if(u||s){let N;x<A?N=k(A)+k(_+A-x)-k(A-x)-k(_+A):N=k(_)+k(x)-k(x-A)-k(_+A),ge=Math.exp(N+os)}t:for(;;){f=Dt;let N=g()*is,a=ge;for(;N>a;)if(N-=a,a*=(_-f)*(x-f),f++,a=a/f/(A-x+f),f>Ot)continue t;break}}else{if(u||s){let a=Math.sqrt((P-x)*x*_*A/(P-1)/P/P);Qt=Math.trunc(1.5*a)+.5,K=E-Qt+.5,z=E+Qt+.5,cr=k(E)+k(_-E)+k(x-E)+k(A-x+E),xe=Math.exp(cr-k(Math.trunc(K))-k(Math.trunc(_-K))-k(Math.trunc(x-K))-k(Math.trunc(A-x+K))),ye=Math.exp(cr-k(Math.trunc(z-1))-k(Math.trunc(_-z+1))-k(Math.trunc(x-z+1))-k(Math.trunc(A-x+z-1))),sr=-Math.log(K*(A-x+K)/(_-K+1)/(x-K+1)),fr=-Math.log((_-z+1)*(x-z+1)/z/(A-x+z)),ar=Qt+Qt,Nr=ar+xe/sr,Ie=Nr+ye/fr}let N=0;for(;;){let a=g()*Ie,c=g();if(++N>=1e4)return NaN;if(a<ar)f=Math.trunc(K+a);else if(a<=Nr){if(f=Math.trunc(K+Math.log(c)/sr),f<Dt)continue;c=c*(a-ar)*sr}else{if(f=Math.trunc(z-Math.log(c)/fr),f>Ot)continue;c=c*(a-Nr)*fr}if(fs(f,c))break}}return o+o>=P?f=t>i?o-i+f:t-f:t>i&&(f=o-f),f}function fs(r,n){if(E<100||r<=50){let H=1;if(E<r)for(let L=E+1;L<=r;L++)H=H*(_-L+1)*(x-L+1)/(A-x+L)/L;else if(E>r)for(let L=r+1;L<=E;L++)H=H*L*(A-x+L)/(_-L+1)/(x-L+1);return n<=H}let e=r,t=e+1,i=e-E,o=_-e+1,u=x-e+1,s=A-x+t,f=-i/t,N=i/o,a=i/u,c=-i/s,m=o*u/(t*s)-1,M=m<0?1+m:1,p=m*(1+m*(-.5+m/3)),l=p-.25*(m*m*m*m)/M,y=E+.5,ut=_-E+.5,lt=x-E+.5,dt=A-x+y,tt=H=>H*(1+H*(-.5+H/3)),Nn=e*p-E*l+es+y*tt(f)+ut*tt(N)+lt*tt(a)+dt*tt(c),mr=Math.log(n);if(mr>Nn)return!1;let Gt=(H,L)=>{let cn=H*(L*L*L*L);return L<0?cn/(1+L):cn},Fe=Gt(y,f),qe=Gt(ut,N),ve=Gt(lt,a),we=Gt(dt,c);return mr<Nn-.25*(Fe+qe+ve+we)+(e+E)*(l-p)-ns?!0:mr<=cr-k(r)-k(_-r)-k(x-r)-k(A-x+r)}function as(r,n,e,t){return I(r,()=>ss(n,e,t))}function Ns(r,n,e={}){let{beta:t=1}=e;return I(r,()=>n>0&&t>0&&Number.isFinite(n)&&Number.isFinite(t)?1/T(n,1/t):NaN)}function cs(r,n,e){return I(r,()=>n>0&&e>0&&Number.isFinite(n)&&Number.isFinite(e)?qt(1-g(),n,e,!0,!1):NaN)}function ms(r,n={}){let{a:e=1,b:t=1}=n;return I(r,()=>e>0&&t>0&&Number.isFinite(e)&&Number.isFinite(t)?zr(1-g(),e,t,!0,!1):NaN)}function Ms(r,n={}){let{a:e=-1,b:t=1}=n,i=n.c??(e+t)/2;return I(r,()=>{if(!(Number.isFinite(e)&&Number.isFinite(t)&&e<t&&e<=i&&i<=t))return NaN;let o=g(),u=g(),s=(i-e)/(t-e);return e+(t-e)*((1-s)*Math.min(o,u)+s*Math.max(o,u))})}function hs(r,n={}){let{mu:e=0,sigma:t=1}=n;return I(r,()=>{if(!(Number.isFinite(e)&&t>0&&Number.isFinite(t)))return NaN;let i=W(),o=g()>.5?1:-1;return e+t*o*i})}function ps(r,n={}){let{a:e=0,b:t=1}=n;return I(r,()=>Number.isFinite(e)&&Number.isFinite(t)&&e<t?rn(g(),e,t,!0,!1):NaN)}export{ii as RNGkind,Po as darcsine,Qe as dbeta,Be as dbinom,Ve as dcauchy,Le as dchisq,Li as dexp,De as df,Re as dgamma,so as dgeom,Ye as dhyper,qo as dinvgamma,nu as distSummary,Ao as dkumar,Ko as dlaplace,Ui as dlnorm,Ji as dlogis,di as dmultinom,go as dnbinom,ke as dnorm,Eo as dpareto,Se as dpois,ze as dsignrank,Ce as dt,Xo as dtriang,yi as dunif,ro as dweibull,Ze as dwilcox,oi as getRandomSeed,Nu as nextRNGStream,cu as nextRNGSubStream,tu as parcsine,Ge as pbeta,Xe as pbinom,ni as pbvnorm,He as pcauchy,_e as pchisq,_i as pexp,Oe as pf,Ae as pgamma,fo as pgeom,$e as phyper,vo as pinvgamma,Lo as pkumar,Yo as plaplace,Vi as plnorm,Wi as plogis,xo as pnbinom,bt as pnorm,Do as ppareto,Ee as ppois,Je as psignrank,je as pt,Co as ptriang,ti as ptukey,Ii as punif,no as pweibull,Te as pwilcox,nn as qarcsine,yr as qbeta,yt as qbinom,Ke as qcauchy,lr as qchisq,Si as qexp,br as qf,pr as qgamma,Sr as qgeom,Ir as qhyper,Xr as qinvgamma,Yr as qkumar,$o as qlaplace,Hi as qlnorm,Zi as qlogis,Gr as qnbinom,st as qnorm,Oo as qpareto,dr as qpois,We as qsignrank,Ue as qt,Zr as qtriang,ri as qtukey,Fi as qunif,Ar as qweibull,Pe as qwilcox,li as r2dtable,ps as rarcsine,Ju as rbeta,Zu as rbinom,mi as rcauchy,it as rchisq,ai as rexp,Yu as rf,Vu as rgamma,vu as rgeom,as as rhyper,Ns as rinvgamma,cs as rkumar,hs as rlaplace,Ni as rlnorm,ci as rlogis,Tu as rmultinom,wu as rnbinom,fi as rnorm,ms as rpareto,qu as rpois,Pu as rsignrank,Ku as rt,Ms as rtriang,si as runif,Mi as rweibull,ts as rwilcox,pi as sample,hi as sampleInt,ui as setRandomSeed,ei as setSeed};
|
package/dist/internal/ddexp.d.ts
CHANGED
|
@@ -16,6 +16,14 @@ export declare function logRatioDD(a: number, b: number): DD;
|
|
|
16
16
|
export declare function mulDD(a: number, b: number): DD;
|
|
17
17
|
/** exp(-t) (t is double-double). The low-order part of t enters to first order */
|
|
18
18
|
export declare function expNeg(t: DD): number;
|
|
19
|
+
/**
|
|
20
|
+
* exp(-t) / s (t double-double, s > 0) where exp(-t) is below the normal range and s small enough to bring the quotient
|
|
21
|
+
* back into it: exp(-t) itself would be rounded on the subnormal grid (a density formed so had lost digits:
|
|
22
|
+
* dlaplace(9.4863e-158, { mu: 9.4863e-158 + 4.5e-167, sigma: 6.04e-171 }) was 6e-4 off). With k = round(t / log 2) and
|
|
23
|
+
* s = f 2^j (f in [1, 2)), it is exp(-(t - k log 2)) / f times 2^(-k - j), the power of two applied last (in two
|
|
24
|
+
* steps, the first within the normal range), so that the only rounding into the subnormal range is the final one
|
|
25
|
+
*/
|
|
26
|
+
export declare function expNegOver(t: DD, s: number): number;
|
|
19
27
|
/** log(1 - exp(x)) (x <= 0). Switches method by the size of x to avoid cancellation */
|
|
20
28
|
export declare function log1mExp(x: number): number;
|
|
21
29
|
/** Log of the lower probability 1 - exp(-t) (t double-double, t > 0). For large t, exp(-t) includes the low-order part of t */
|
package/dist/internal/ddexp.js
CHANGED
|
@@ -101,6 +101,33 @@ export function expNeg(t) {
|
|
|
101
101
|
}
|
|
102
102
|
return Math.exp(-t[0]) * (1 - t[1]);
|
|
103
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* exp(-t) / s (t double-double, s > 0) where exp(-t) is below the normal range and s small enough to bring the quotient
|
|
106
|
+
* back into it: exp(-t) itself would be rounded on the subnormal grid (a density formed so had lost digits:
|
|
107
|
+
* dlaplace(9.4863e-158, { mu: 9.4863e-158 + 4.5e-167, sigma: 6.04e-171 }) was 6e-4 off). With k = round(t / log 2) and
|
|
108
|
+
* s = f 2^j (f in [1, 2)), it is exp(-(t - k log 2)) / f times 2^(-k - j), the power of two applied last (in two
|
|
109
|
+
* steps, the first within the normal range), so that the only rounding into the subnormal range is the final one
|
|
110
|
+
*/
|
|
111
|
+
export function expNegOver(t, s) {
|
|
112
|
+
// (beyond t = 2000 the quotient is below e^-1255 even for the smallest s)
|
|
113
|
+
if (!(t[0] < 2000) || s === Infinity)
|
|
114
|
+
return 0;
|
|
115
|
+
let j = 0;
|
|
116
|
+
let f = s;
|
|
117
|
+
if (f < 2 ** -1000) {
|
|
118
|
+
f *= 2 ** 600;
|
|
119
|
+
j = -600;
|
|
120
|
+
}
|
|
121
|
+
const e = Math.floor(Math.log2(f));
|
|
122
|
+
f *= 2 ** -e;
|
|
123
|
+
j += e;
|
|
124
|
+
const k = Math.round(t[0] / LN2[0]);
|
|
125
|
+
const r = ddSub(t, ddMulNum(LN2, k));
|
|
126
|
+
const v = (Math.exp(-r[0]) * (1 - r[1])) / f;
|
|
127
|
+
const n = -k - j;
|
|
128
|
+
const h = Math.trunc(n / 2);
|
|
129
|
+
return v * 2 ** h * 2 ** (n - h);
|
|
130
|
+
}
|
|
104
131
|
/** log(1 - exp(x)) (x <= 0). Switches method by the size of x to avoid cancellation */
|
|
105
132
|
export function log1mExp(x) {
|
|
106
133
|
return x > -Math.LN2 ? Math.log(-Math.expm1(x)) : Math.log1p(-Math.exp(x));
|
|
@@ -32,5 +32,10 @@ export interface InvertProblem {
|
|
|
32
32
|
*/
|
|
33
33
|
positive?: boolean;
|
|
34
34
|
maxIter?: number;
|
|
35
|
+
/**
|
|
36
|
+
* (Optional) The noise of log F (absolute): a point whose residual is within it is returned as it is (where the
|
|
37
|
+
* distribution function is an integral accurate to about 1e-13, the steps would otherwise wander over a few ulps of x)
|
|
38
|
+
*/
|
|
39
|
+
residualTolerance?: number;
|
|
35
40
|
}
|
|
36
41
|
export declare function invertContinuous(problem: InvertProblem): number;
|
package/dist/internal/invert.js
CHANGED
|
@@ -9,7 +9,7 @@ export function invertContinuous(problem) {
|
|
|
9
9
|
const residual = (x, lF) => {
|
|
10
10
|
if (linearTarget !== undefined && cdf !== undefined && lF > -700) {
|
|
11
11
|
const F = cdf(x, lower);
|
|
12
|
-
if (F > 0)
|
|
12
|
+
if (F > 0 && F / linearTarget < Infinity)
|
|
13
13
|
return Math.log(F / linearTarget);
|
|
14
14
|
}
|
|
15
15
|
return lF - logTarget;
|
|
@@ -21,7 +21,9 @@ export function invertContinuous(problem) {
|
|
|
21
21
|
return [lF, residual(x, lF)];
|
|
22
22
|
}
|
|
23
23
|
const [lF, F] = cdfBoth(x, lower);
|
|
24
|
-
|
|
24
|
+
// (F / target overflows for a subnormal target; the residual was then Infinity and the steps went astray:
|
|
25
|
+
// qgamma(7.2e-317, 3.3e126, { scale: 0.136, lowerTail: false }) was 8.2e146, 1e21 times the mean)
|
|
26
|
+
if (linearTarget !== undefined && lF > -700 && F > 0 && F / linearTarget < Infinity)
|
|
25
27
|
return [lF, Math.log(F / linearTarget)];
|
|
26
28
|
return [lF, lF - logTarget];
|
|
27
29
|
};
|
|
@@ -43,7 +45,7 @@ export function invertContinuous(problem) {
|
|
|
43
45
|
bestResid = Math.abs(resid);
|
|
44
46
|
best = u;
|
|
45
47
|
}
|
|
46
|
-
if (resid === 0)
|
|
48
|
+
if (resid === 0 || Math.abs(resid) <= (problem.residualTolerance ?? 0))
|
|
47
49
|
return x;
|
|
48
50
|
// The lower probability is increasing in x, the upper decreasing
|
|
49
51
|
if (resid < 0 === lower)
|
|
@@ -94,8 +96,11 @@ export function invertContinuous(problem) {
|
|
|
94
96
|
let x = x0;
|
|
95
97
|
let [lF, r] = evaluate(x);
|
|
96
98
|
for (let k = 0; k < 4 && r !== 0; k++) {
|
|
97
|
-
const
|
|
98
|
-
const
|
|
99
|
+
const lf = pdfLog(x) - lF;
|
|
100
|
+
const slope = (lower ? 1 : -1) * Math.exp(lf);
|
|
101
|
+
// (where f/F overflows, as at a subnormal x, the step relative to x: qbeta(3.8e-277, 27.9, 1.5e299) is 9.6e-309,
|
|
102
|
+
// and the step there was 0, which left the answer 5e-14 off)
|
|
103
|
+
const xn = Number.isFinite(slope) ? x - r / slope : x - (lower ? 1 : -1) * r * x * Math.exp(-(lf + Math.log(x)));
|
|
99
104
|
if (!(xn > 0) || !Number.isFinite(xn) || xn === x)
|
|
100
105
|
break;
|
|
101
106
|
const [lFn, rn] = evaluate(xn);
|
|
@@ -46,3 +46,10 @@ export declare function quadratureControl(tol?: number, maxBisections?: number):
|
|
|
46
46
|
* would otherwise be bisected to the full depth (2^40 intervals)
|
|
47
47
|
*/
|
|
48
48
|
export declare function kronrodAdaptive(f: (u: number) => number, a: number, b: number, total: number, depth: number, control: QuadratureControl): number;
|
|
49
|
+
/**
|
|
50
|
+
* Whether a noncentral density equals the central one to the double: it is e^-μ Σ_j μ^j/j! f_j, and f_1/f_0 is r
|
|
51
|
+
* (x (a + b)/a for the beta, x/k for χ² with k df), with the ratios of later terms smaller still, so the terms from
|
|
52
|
+
* j = 1 on and the factor e^-μ change it by less than 2 μ max(1, r) relative. Below 1e-20 that is the central density
|
|
53
|
+
* itself (at a tiny or subnormal λ the mixture's weights were NaN: dbeta(1.05e-231, 0.19, 141, { ncp: 1.4e-303 }))
|
|
54
|
+
*/
|
|
55
|
+
export declare function negligibleNcp(mu: number, r: number): boolean;
|
|
@@ -113,3 +113,12 @@ export function kronrodAdaptive(f, a, b, total, depth, control) {
|
|
|
113
113
|
return k;
|
|
114
114
|
return kronrodAdaptive(f, a, m, total, depth + 1, control) + kronrodAdaptive(f, m, b, total, depth + 1, control);
|
|
115
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Whether a noncentral density equals the central one to the double: it is e^-μ Σ_j μ^j/j! f_j, and f_1/f_0 is r
|
|
118
|
+
* (x (a + b)/a for the beta, x/k for χ² with k df), with the ratios of later terms smaller still, so the terms from
|
|
119
|
+
* j = 1 on and the factor e^-μ change it by less than 2 μ max(1, r) relative. Below 1e-20 that is the central density
|
|
120
|
+
* itself (at a tiny or subnormal λ the mixture's weights were NaN: dbeta(1.05e-231, 0.19, 141, { ncp: 1.4e-303 }))
|
|
121
|
+
*/
|
|
122
|
+
export function negligibleNcp(mu, r) {
|
|
123
|
+
return mu * Math.max(1, r) < 1e-20;
|
|
124
|
+
}
|
|
@@ -84,7 +84,12 @@ export function dpoisLogDD(x, lambda) {
|
|
|
84
84
|
if (x === 0)
|
|
85
85
|
return [-lambda, 0];
|
|
86
86
|
const DBL_MIN = 2.2250738585072014e-308;
|
|
87
|
-
|
|
87
|
+
// (λ < x DBL_MIN not for x in [1, 1e10], where lgamma1p(x) in double would put an absolute error of eps log Γ(x + 1)
|
|
88
|
+
// into a log that is not much larger: pchisq(1e-310, 1.2e-51, { ncp: 197 }) was 3.8e-15 off, and 1.4e-15 at x = 1e-307;
|
|
89
|
+
// bd0dd takes the logs of x and λ apart for such ratios. Below 1 log Γ(x + 1) is small, while stirlerr(x) and log x
|
|
90
|
+
// cancel in Loader's form; above 1e10 the error is below eps of x log λ)
|
|
91
|
+
const moderate = x >= 1 && x <= 1e10;
|
|
92
|
+
if (x <= lambda * DBL_MIN || (lambda < x * DBL_MIN && !moderate) || !Number.isFinite(x)) {
|
|
88
93
|
const l = ddAdd(ddMul(ddLog([lambda, 0]), [x, 0]), [-lambda - lgamma1p(x), 0]);
|
|
89
94
|
return l;
|
|
90
95
|
}
|
|
@@ -298,6 +303,21 @@ function logRatio(a, b) {
|
|
|
298
303
|
return Infinity;
|
|
299
304
|
return Math.log(a.h / b.h) + (a.l / a.h - b.l / b.h) + (a.k - b.k) * LN_UNIT;
|
|
300
305
|
}
|
|
306
|
+
/**
|
|
307
|
+
* w_j = w_(j-1) μ / j. Where μ is beyond 1e290 the splitting of the quotient in ddDivNum overflows (the noncentral χ²
|
|
308
|
+
* at λ = 1e302 and x = 1e-300 was NaN), so μ is multiplied in as a scaled number instead. (R 4.5.2 gives
|
|
309
|
+
* -1.0243631212370614e307 for dchisq(1e-308, 294.4, ncp = 2.9e304, log = TRUE), which is -λ/2 = -1.45e304 to the double)
|
|
310
|
+
*/
|
|
311
|
+
function weightUp(w, mu, j) {
|
|
312
|
+
return mu < 1e290 ? mulDD(w, ddDivNum([mu, 0], j)) : divDD(mulDD(w, [mu, 0]), [j, 0]);
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* w_(j-1) = w_j j / μ, with μ split off as a scaled number where the splitting in ddDivNum would overflow: for a tiny
|
|
316
|
+
* μ (of j / μ; the densities at λ = 1.4e-303 were NaN) and for a huge one (of μ)
|
|
317
|
+
*/
|
|
318
|
+
function weightDown(w, j, mu) {
|
|
319
|
+
return mu > 1e-290 && mu < 1e290 ? mulDD(w, ddDivNum([j, 0], mu)) : divDD(mulDD(w, [j, 0]), [mu, 0]);
|
|
320
|
+
}
|
|
301
321
|
function weight(j, mu) {
|
|
302
322
|
return fromValue(dpoisRaw(j, mu, false), () => dpoisLogDD(j, mu));
|
|
303
323
|
}
|
|
@@ -389,7 +409,7 @@ function sumLower(mu, k) {
|
|
|
389
409
|
break;
|
|
390
410
|
// P_{j-1} = P_j + d_{j-1}, w_{j-1} = w_j j/μ, d_{j-2} = d_{j-1} / (d_{j-1}/d_{j-2})
|
|
391
411
|
p = add(p, d);
|
|
392
|
-
w = refresh(
|
|
412
|
+
w = refresh(weightDown(w, j, mu), () => weight(j - 1, mu));
|
|
393
413
|
if (j >= 2)
|
|
394
414
|
d = d.h === 0 ? increment(k, j - 2) : refresh(divRatio(d, k, j - 1), () => increment(k, j - 2));
|
|
395
415
|
}
|
|
@@ -430,7 +450,7 @@ function sumUpper(mu, k) {
|
|
|
430
450
|
prev = t;
|
|
431
451
|
// Q_{j+1} = Q_j + d_j, w_{j+1} = w_j μ/(j+1), d_{j+1} = d_j (d_{j+1}/d_j)
|
|
432
452
|
q = add(q, d);
|
|
433
|
-
w = refresh(
|
|
453
|
+
w = refresh(weightUp(w, mu, j + 1), () => weight(j + 1, mu));
|
|
434
454
|
d = d.h === 0 ? increment(k, j + 1) : refresh(mulRatio(d, k, j + 1), () => increment(k, j + 1));
|
|
435
455
|
}
|
|
436
456
|
if (restart < 0)
|
|
@@ -445,7 +465,10 @@ function sumUpper(mu, k) {
|
|
|
445
465
|
* Returns the sum divided by divisor (as a log if log).
|
|
446
466
|
*/
|
|
447
467
|
export function mixtureDensity(mu, kernel, coef, jStar, divisor, log) {
|
|
448
|
-
|
|
468
|
+
// (μ = 0 where λ/2 underflows, at λ = 5e-324: the j = 0 term alone, as for the central distribution, whose weight is
|
|
469
|
+
// the only one not 0; the terms from j = 1 on are of relative size μ times the ratio of the densities of components 1
|
|
470
|
+
// and 0, negligible unless that ratio is above 1e300)
|
|
471
|
+
const j0 = Number.isFinite(jStar) && mu > 0 ? Math.max(0, Math.round(jStar)) : 0;
|
|
449
472
|
const sum = new ScaledSum();
|
|
450
473
|
const w0 = weight(j0, mu);
|
|
451
474
|
const d0 = increment(kernel, j0);
|
|
@@ -461,7 +484,7 @@ export function mixtureDensity(mu, kernel, coef, jStar, divisor, log) {
|
|
|
461
484
|
if (t.h === 0 && j > mu + 50 && j > j0 + 50)
|
|
462
485
|
break; // all later terms are 0 too
|
|
463
486
|
prev = t;
|
|
464
|
-
w = refresh(
|
|
487
|
+
w = refresh(weightUp(w, mu, j + 1), () => weight(j + 1, mu));
|
|
465
488
|
d = d.h === 0 ? increment(kernel, j + 1) : refresh(mulRatio(d, kernel, j + 1), () => increment(kernel, j + 1));
|
|
466
489
|
}
|
|
467
490
|
// Downward
|
|
@@ -469,7 +492,7 @@ export function mixtureDensity(mu, kernel, coef, jStar, divisor, log) {
|
|
|
469
492
|
d = d0;
|
|
470
493
|
prev = ZERO;
|
|
471
494
|
for (let j = j0 - 1; j >= 0; j--) {
|
|
472
|
-
w = refresh(
|
|
495
|
+
w = refresh(weightDown(w, j + 1, mu), () => weight(j, mu));
|
|
473
496
|
d = d.h === 0 ? increment(kernel, j) : refresh(divRatio(d, kernel, j + 1), () => increment(kernel, j));
|
|
474
497
|
const t = mulDD(mul(w, d), [coef(j), 0]);
|
|
475
498
|
sum.add(t);
|
package/dist/linalg.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! rStats.js 0.15.
|
|
2
|
-
import{F as rt,h as tt,i as nt}from"./chunks/chunk-Q4PGYESP.js";import"./chunks/chunk-IBPWRQIF.js";import{a as Ft,b as St}from"./chunks/chunk-YVREYVI2.js";import{B as xt,D as L,E as Rt,F as Y,G as Z,a as q,b as K,c as R,d as T,e as k,g as j,h as mt,i as ht,j as dt,k as pt,l as gt,m as wt,n as Mt,o as bt,p as yt,q as vt,r as $,s as kt,t as U,u as W,v as H,w as Et,x as qt,y as At,z as Nt}from"./chunks/chunk-XNPU54NH.js";import"./chunks/chunk-HBMHR5SS.js";import"./chunks/chunk-PWVQVJTP.js";import"./chunks/chunk-LG74QY5U.js";function Tt(r,n){let t=T(r),e=n===void 0?t:T(n);if(t.nrow!==e.nrow)throw new TypeError(`non-conformable arguments (${t.nrow} and ${e.nrow} rows)`);let u=t.nrow,a=q(t.ncol,e.ncol);for(let c=0;c<e.ncol;c++)for(let i=0;i<t.ncol;i++){if(n===void 0&&i>c)continue;let f=0;for(let o=0;o<u;o++)f+=t.data[o+i*u]*e.data[o+c*u];a.data[i+c*t.ncol]=f}return n===void 0&&et(a),k(a)}function _t(r,n){let t=T(r),e=n===void 0?t:T(n);if(t.ncol!==e.ncol)throw new TypeError(`non-conformable arguments (${t.ncol} and ${e.ncol} columns)`);let u=q(t.nrow,e.nrow);for(let a=0;a<e.nrow;a++)for(let c=0;c<t.nrow;c++){if(n===void 0&&c>a)continue;let i=0;for(let f=0;f<t.ncol;f++)i+=t.data[c+f*t.nrow]*e.data[a+f*e.nrow];u.data[c+a*t.nrow]=i}return n===void 0&&et(u),k(u)}function et(r){let n=r.nrow;for(let t=0;t<n;t++)for(let e=t+1;e<n;e++)r.data[e+t*n]=r.data[t+e*n]}function Pt(r,n,t={}){return ot(r,n,t.k,t.upperTri??!0,t.transpose??!1)}function jt(r,n,t={}){return ot(r,n,t.k,t.upperTri??!1,t.transpose??!1)}function ot(r,n,t,e,u){let a=R(r),c=T(n),i=t??a.ncol;if(!Number.isInteger(i)||i<1||i>a.nrow||i>a.ncol||i>c.nrow)throw new RangeError(`invalid k (got ${i})`);for(let o=0;o<i;o++)if(a.data[o+o*a.nrow]===0)throw new Error(`singular matrix: diagonal element ${o+1} is zero`);let f=q(i,c.ncol);for(let o=0;o<c.ncol;o++)for(let l=0;l<i;l++)f.data[l+o*i]=c.data[l+o*c.nrow];return It(a,i,f,e,u),K(n)?k(f):Array.from(f.data)}function It(r,n,t,e,u){let a=r.nrow,c=r.data,i=t.nrow,f=t.data;for(let o=0;o<t.ncol;o++){let l=o*i;if(!u&&e){for(let h=n-1;h>=0;h--)if(f[l+h]!==0){f[l+h]/=c[h+h*a];let m=f[l+h];for(let s=0;s<h;s++)f[l+s]-=m*c[s+h*a]}}else if(u)if(e)for(let h=0;h<n;h++){let m=f[l+h];for(let s=0;s<h;s++)m-=c[s+h*a]*f[l+s];f[l+h]=m/c[h+h*a]}else for(let h=n-1;h>=0;h--){let m=f[l+h];for(let s=h+1;s<n;s++)m-=c[s+h*a]*f[l+s];f[l+h]=m/c[h+h*a]}else for(let h=0;h<n;h++)if(f[l+h]!==0){f[l+h]/=c[h+h*a];let m=f[l+h];for(let s=h+1;s<n;s++)f[l+s]-=m*c[s+h*a]}}}function Ot(r){let n=R(r);j(n);let t=n.nrow;if(t===0)throw new RangeError("the matrix has zero dimension");for(let s of n.data)if(!Number.isFinite(s))throw new RangeError("the matrix contains NaN or infinite values");let e={nrow:t,ncol:t,data:n.data.slice()},u=q(t,t),a=new Float64Array(t),c=new Float64Array(t);Y(e,u),Z(e,u,a,c,!0);let i=e.data,f=u.data,o=(s,d)=>s+d*t,l=new Uint8Array(t);for(let s=0;s+1<t;s++)c[s]>0&&c[s+1]<0&&(l[s++]=1);for(let s=0;s<t;s++)for(let d=s+1;d<t;d++)d===s+1&&l[s]||(i[o(d,s)]=0);let h=new Array(t),m=new Array(t);for(let s=0;s<t;s++){if(!l[s]){h[s]=i[o(s,s)],m[s]=0;continue}let d=$t(i[o(s,s)],i[o(s,s+1)],i[o(s+1,s)],i[o(s+1,s+1)]);i[o(s,s)]=d.a,i[o(s,s+1)]=d.b,i[o(s+1,s)]=d.c,i[o(s+1,s+1)]=d.d;let{cs:p,sn:w}=d;for(let g=s+2;g<t;g++){let M=i[o(s,g)],b=i[o(s+1,g)];i[o(s,g)]=p*M+w*b,i[o(s+1,g)]=p*b-w*M}for(let g=0;g<s;g++){let M=i[o(g,s)],b=i[o(g,s+1)];i[o(g,s)]=p*M+w*b,i[o(g,s+1)]=p*b-w*M}for(let g=0;g<t;g++){let M=f[o(g,s)],b=f[o(g,s+1)];f[o(g,s)]=p*M+w*b,f[o(g,s+1)]=p*b-w*M}h[s]=d.rt1r,m[s]=d.rt1i,h[s+1]=d.rt2r,m[s+1]=d.rt2i,s++}return{T:k(e),Q:k(u),valuesRe:h,valuesIm:m}}var N=(r,n)=>n>=0&&!Object.is(n,-0)?Math.abs(r):-Math.abs(r);function $t(r,n,t,e){let u=22250738585072014e-324,a=Number.EPSILON,c=4,i=2**Math.trunc(Math.log(u/a)/Math.log(2)/2),f=1/i,o,l;if(t===0)o=1,l=0;else if(n===0){o=0,l=1;let m=e;e=r,r=m,n=-t,t=0}else if(r-e===0&&N(1,n)!==N(1,t))o=1,l=0;else{let m=r-e,s=.5*m,d=Math.max(Math.abs(n),Math.abs(t)),p=Math.min(Math.abs(n),Math.abs(t))*N(1,n)*N(1,t),w=Math.max(Math.abs(s),d),g=s/w*s+d/w*p;if(g>=c*a){g=s+N(Math.sqrt(w)*Math.sqrt(g),s),r=e+g,e=e-d/g*p;let M=Math.hypot(t,g);o=g/M,l=t/M,n=n-t,t=0}else{let M=0,b=n+t;for(;M++,w=Math.max(Math.abs(m),Math.abs(b)),!(!(w>=f&&(b*=i,m*=i,M<=20))&&!(w<=i&&(b*=f,m*=f,M<=20))););s=.5*m;let x=Math.hypot(b,m);o=Math.sqrt(.5*(1+Math.abs(b)/x)),l=-(s/(x*o))*N(1,b);let F=r*o+n*l,S=-r*l+n*o,Q=t*o+e*l,X=-t*l+e*o;if(r=F*o+Q*l,n=S*o+X*l,t=-F*l+Q*o,e=-S*l+X*o,m=.5*(r+e),r=m,e=m,t!==0)if(n!==0){if(N(1,n)===N(1,t)){let B=Math.sqrt(Math.abs(n)),C=Math.sqrt(Math.abs(t));s=N(B*C,t),x=1/Math.sqrt(Math.abs(n+t)),r=m+s,e=m-s,n=n-t,t=0;let G=B*x,J=C*x;m=o*G-l*J,l=o*J+l*G,o=m}}else n=-t,t=0,m=o,o=-l,l=m}}let h=t===0?0:Math.sqrt(Math.abs(n))*Math.sqrt(Math.abs(t));return{a:r,b:n,c:t,d:e,cs:o,sn:l,rt1r:r,rt1i:h,rt2r:e,rt2i:-h}}var Ut=["Higham08.b","Higham08","Pade","Taylor","PadeO","TaylorO"];function Ht(r,n={}){let t=n.method??"Higham08.b";if(!Ut.includes(t))throw new RangeError(`unknown method: ${String(t)}`);let e=n.order??8;if(!Number.isInteger(e)||e<1)throw new RangeError("order must be a positive integer");let u=R(r);j(u);let a=u.nrow;if(a===0)return[];if(a===1)return[[Math.exp(u.data[0])]];if(t==="Taylor"||t==="TaylorO")return k(Dt(u,e));if(t==="Pade"||t==="PadeO")return k(Qt(u,e));let c,i;t==="Higham08.b"&&(c=L("P",u),i=L("S",u));let f=zt(u),o=f.data,l=(h,m)=>h+m*a;if(i){let h=i.scale;for(let m=0;m<a;m++)for(let s=0;s<a;s++)o[l(s,m)]=o[l(s,m)]*h[s]/h[m]}if(c){let h=c.scale,m=s=>{let d=h[s];if(d!==s){for(let p=0;p<a;p++)[o[l(p,s)],o[l(p,d)]]=[o[l(p,d)],o[l(p,s)]];for(let p=0;p<a;p++)[o[l(s,p)],o[l(d,p)]]=[o[l(d,p)],o[l(s,p)]]}};for(let s=c.ilo-1;s>=0;s--)m(s);for(let s=c.ihi+1;s<a;s++)m(s)}return k(f)}var Lt={3:[120,60,12,1],5:[30240,15120,3360,420,30,1],7:[17297280,8648640,1995840,277200,25200,1512,56,1],9:[17643225600,8821612800,2075673600,302702400,30270240,2162160,110880,3960,90,1]},Vt=[6476475253248e4,3238237626624e4,7771770303897600,0x437e459424400,129060195264e3,0x99a917d4d00,670442572800,33522128640,1323241920,40840800,960960,16380,182,1];function zt(r){let n=r.nrow,t=U(r),e=V(n),u,a,c=0;if(t<=2.1){let l=t<=.015?3:t<=.25?5:t<=.95?7:9,h=Lt[l],m=E(r,r),s=I([[h[1],e]]),d=I([[h[0],e]]),p=m;for(let w=1;w<=(l-1)/2;w++)w>1&&(p=E(p,m)),_(s,h[2*w+1],p),_(d,h[2*w],p);u=E(r,s),a=d}else{c=Math.max(0,Math.ceil(Math.log2(t/5.4)));let l=P(r,1/2**c),h=E(l,l),m=E(h,h),s=E(h,m),d=Vt,p=I([[d[13],s],[d[11],m],[d[9],h]]),w=E(s,p);for(let[M,b]of[[7,s],[5,m],[3,h],[1,e]])_(w,d[M],b);u=E(l,w);let g=I([[d[12],s],[d[10],m],[d[8],h]]);a=E(s,g);for(let[M,b]of[[6,s],[4,m],[2,h],[0,e]])_(a,d[M],b)}let i=q(n,n),f=q(n,n);for(let l=0;l<n*n;l++)i.data[l]=a.data[l]-u.data[l],f.data[l]=a.data[l]+u.data[l];let o=R(H(k(i),k(f)));for(let l=0;l<c;l++)o=E(o,o);return o}function st(r){let n=Math.sqrt(U(r)*W(r)),t=1;for(;2**t<n;)t++;return t+4}function ct(r,n){for(let t=0;t<n;t++)r=E(r,r);return r}function it(r){let n=r.nrow;for(let t=0;t<n;t++)r.data[t+t*n]=r.data[t+t*n]+1}function Dt(r,n){let t=st(r),e=2**t,u=V(r.nrow);for(let a=n;a>=1;a--)u=P(E(u,r),1/(a*e)),it(u);return ct(u,t)}function at(r,n,t,e){let u=e===1?r:P(r,-1),a=V(r.nrow);for(let c=n;c>=1;c--){let i=(n-c+1)/(c*(2*n-c+1)*t);a=P(E(a,u),i),it(a)}return a}function Qt(r,n){let t=r.nrow,e=st(r),u=2**e,a=at(r,n,u,1),c=at(r,n,u,-1),i=q(t,t);for(let f=0;f<t;f++)i.data.set(Xt(c,a.data.subarray(f*t,(f+1)*t)),f*t);return ct(i,e)}function Xt(r,n){let t=r.nrow,e=1e-100,u=d=>{let p=new Float64Array(t);for(let w=0;w<t;w++){let g=0;for(let M=0;M<t;M++)g+=r.data[w+M*t]*d[M];p[w]=g}return p},a=(d,p)=>{let w=0;for(let g=0;g<t;g++)w+=d[g]*p[g];return w},c=(d,p,w)=>{let g=new Float64Array(t);for(let M=0;M<t;M++)g[M]=d[M]+p*w[M];return g},i=new Float64Array(t),f=Float64Array.from(n),o=Float64Array.from(n),l=Float64Array.from(n),h=Float64Array.from(n),m=Math.sqrt(a(f,f)),s=a(h,n);if(Math.abs(s)<=e)return i;for(let d=0;d<t;d++){let p=u(o),w=a(h,p);if(Math.abs(w)<=e)return i;let g=s/w;if(Math.abs(g)<=e)return i;let M=c(l,-g,p);p=c(l,1,M);let b=u(p);f=c(f,-g,b);let x=Math.sqrt(a(f,f));if(i=c(i,g,p),Math.abs(x/m)<=1e-30)return i;let F=a(h,f);if(Math.abs(F)<=e)return i;let S=F/s;s=F,l=c(f,S,M),b=c(M,S,o),o=c(l,S,b)}return i}function V(r){let n=q(r,r);for(let t=0;t<r;t++)n.data[t+t*r]=1;return n}function E(r,n){let t=r.nrow,e=r.ncol,u=n.ncol,a=q(t,u);for(let c=0;c<u;c++)for(let i=0;i<t;i++){let f=0;for(let o=0;o<e;o++)f+=r.data[i+o*t]*n.data[o+c*e];a.data[i+c*t]=f}return a}function P(r,n){return{nrow:r.nrow,ncol:r.ncol,data:r.data.map(t=>t*n)}}function _(r,n,t){for(let e=0;e<r.data.length;e++)r.data[e]=r.data[e]+n*t.data[e]}function I(r){let[n,t]=r[0],e=P(t,n);for(let u=1;u<r.length;u++)_(e,r[u][0],r[u][1]);return e}function v(r){return typeof r!="number"&&r.length>0&&Array.isArray(r[0])}function y(r){return typeof r=="number"?[r]:Array.from(r)}function A(r){let n=r[0].length;if(r.some(t=>t.length!==n))throw new TypeError("all rows of the matrix must have the same length");return n}function z(r,n){let t,e;if(v(r)&&v(n))t=r.map(c=>[...c]),e=n.map(c=>[...c]);else if(v(r)){let c=y(n),i=A(r);t=r.map(f=>[...f]),e=i===c.length?c.map(f=>[f]):i===1?[c]:[]}else if(v(n)){let c=y(r);e=n.map(i=>[...i]),t=n.length===c.length?[c]:n.length===1?c.map(i=>[i]):[]}else{let c=y(r),i=y(n);if(c.length===i.length)t=[c],e=i.map(f=>[f]);else if(c.length===1)t=[c],e=[i];else if(i.length===1)t=c.map(f=>[f]),e=[i];else throw new RangeError("non-conformable arguments")}let u=t[0]?.length??0;if(t.length===0||e.length!==u)throw new RangeError("non-conformable arguments");A(t);let a=A(e);return t.map(c=>{let i=new Array(a).fill(0);for(let f=0;f<a;f++){let o=0;for(let l=0;l<u;l++)o+=c[l]*e[l][f];i[f]=o}return i})}function O(r,n,t){let e=v(r),u=v(n);if(e&&u){let f=A(r);if(r.length!==n.length||f!==A(n))throw new RangeError("non-conformable arrays");return r.map((o,l)=>o.map((h,m)=>t(h,n[l][m])))}if(e||u){let f=e?r:n,o=y(e?n:r),l=f.length,h=A(f);if(o.length===0)return f.map(m=>m.map(()=>NaN));if(o.length>l*h)throw new RangeError("dims [product "+l*h+"] do not match the length of object ["+o.length+"]");return f.map((m,s)=>m.map((d,p)=>e?t(d,o[(s+p*l)%o.length]):t(o[(s+p*l)%o.length],d)))}let a=y(r),c=y(n);if(a.length===0||c.length===0)return[];let i=Math.max(a.length,c.length);return Array.from({length:i},(f,o)=>t(a[o%a.length],c[o%c.length]))}function Bt(r,n){return O(r,n,(t,e)=>t+e)}function Ct(r,n){return O(r,n,(t,e)=>t-e)}function Gt(r,n){return O(r,n,(t,e)=>t*e)}function Jt(r,n){return O(r,n,(t,e)=>t/e)}var Kt={"*":(r,n)=>r*n,"+":(r,n)=>r+n,"-":(r,n)=>r-n,"/":(r,n)=>r/n,"^":(r,n)=>r**n};function Wt(r,n,t="*"){let e=typeof t=="function"?t:Kt[t];if(e===void 0)throw new RangeError(`invalid fun "${String(t)}"`);let u=Array.from(r),a=Array.from(n);return u.map(c=>a.map(i=>e(c,i)))}function D(r){if(!v(r))return[y(r)];let n=A(r);return Array.from({length:n},(t,e)=>r.map(u=>u[e]))}function Yt(r,n={}){if(v(r)){let i=A(r);return Array.from({length:Math.min(r.length,i)},(f,o)=>r[o][o])}let t=y(r),e,u;if(t.length===1&&n.nrow===void 0&&n.ncol===void 0){if(u=Math.trunc(t[0]),!(u>=0))throw new RangeError("invalid 'nrow' value (< 0)");e=[1]}else e=t,u=n.nrow??t.length;let a=n.ncol??u,c=Array.from({length:u},()=>new Array(a).fill(0));for(let i=0;i<Math.min(u,a);i++)c[i][i]=e[i%e.length];return u===0?[]:c}function ft(r,n){let t=r.map(a=>v(a)?n?D(a):a.map(c=>[...c]):[y(a)]),e=r.filter(v),u=e.length>0?n?e[0].length:A(e[0]):Math.max(...t.map(a=>a[0].length));return e.forEach((a,c)=>{if((n?a.length:A(a))!==u)throw new RangeError(`number of ${n?"rows":"columns"} of matrices must match (see arg ${c+2})`)}),t.flatMap(a=>a.map(c=>Array.from({length:u},(i,f)=>c[f%c.length])))}function Zt(r){return typeof r=="object"&&!Array.isArray(r)&&!ArrayBuffer.isView(r)}function ut(r){let n=r.filter(Zt);if(n.length!==0){if(n.length<r.length)throw new TypeError("cannot combine data frames with vectors or matrices");return n}}function tn(...r){let n=ut(r);return n===void 0?D(ft(r,!0)):nt(n)}function nn(...r){let n=ut(r);return n===void 0?ft(r,!1):tt(n)}function rn(r,n={}){let t=y(r),e=t.length,{nrow:u,ncol:a}=n;u===void 0&&a===void 0?(u=e,a=1):u===void 0?u=Math.ceil(e/a):a===void 0&&(a=Math.ceil(e/u));let c=n.byrow??!1;return Array.from({length:u},(i,f)=>Array.from({length:a},(o,l)=>e===0?NaN:t[(c?f*a+l:f+l*u)%e]))}function en(r,n){if(!v(r)&&!v(n)){let a=y(r),c=y(n);return a.flatMap(i=>c.map(f=>i*f))}let t=v(r)?r:y(r).map(a=>[a]),e=v(n)?n:y(n).map(a=>[a]),u=[];for(let a of t)for(let c of e)u.push(a.flatMap(i=>c.map(f=>i*f)));return u}function on(r,n,t={}){let{by:e,lengthOut:u}=t;if(n===void 0&&e===void 0&&u===void 0&&r!==void 0){if(!Number.isFinite(r))throw new RangeError("'from' must be a finite number");return lt(1,r)}if(r!==void 0&&!Number.isFinite(r))throw new RangeError("'from' must be a finite number");if(n!==void 0&&!Number.isFinite(n))throw new RangeError("'to' must be a finite number");if(u===void 0){if(e===void 0)return lt(r??1,n??1);let c=r??1,i=n??1,f=i-c;if(f===0&&i===0)return[i];let o=f/e;if(!Number.isFinite(o)){if(e===0&&f===0)return[c];throw new RangeError("invalid '(to - from)/by'")}if(o<0)throw new RangeError("wrong sign in 'by' argument");if(Math.abs(f)/Math.max(Math.abs(i),Math.abs(c))<100*Number.EPSILON)return[c];let l=Math.trunc(o+1e-10);return Array.from({length:l+1},(h,m)=>e>0?Math.min(c+m*e,i):Math.max(c+m*e,i))}if(!Number.isFinite(u)||u<0)throw new RangeError("'length.out' must be a non-negative number");let a=Math.ceil(u);if(a===0)return[];if(e===void 0){let c=n??(r??1)+(a-1),i=r??c-(a-1);if(a<=2)return[i,c].slice(0,a);if(i===c)return new Array(a).fill(i);let f=(c-i)/(a-1);return Array.from({length:a},(o,l)=>l===0?i:l===a-1?c:i+l*f)}if(n===void 0){let c=r??1;return Array.from({length:a},(i,f)=>c+f*e)}if(r===void 0)return Array.from({length:a},(c,i)=>n-(a-1-i)*e);throw new RangeError("too many arguments")}function lt(r,n){let t=Math.trunc(Math.abs(n-r)+1+11920928955078125e-23),e=r<=n?1:-1;return Array.from({length:t},(u,a)=>r+e*a)}var an=22250738585072014e-324;function sn(r){let n=r.length,t=n===0?0:r[0].length,e=r.map(o=>{if(o.length!==t)throw new TypeError("all rows of the matrix must have the same length");return Array.from(o)}),u=Array.from({length:n},(o,l)=>l),a=Math.min(n,t);for(let o=0;o<a;o++){let l=o,h=Math.abs(e[o][o]);for(let d=o+1;d<n;d++){let p=Math.abs(e[d][o]);(p>h||Number.isNaN(h))&&(h=p,l=d)}l!==o&&([e[l],e[o]]=[e[o],e[l]],[u[l],u[o]]=[u[o],u[l]]);let m=e[o][o];if(m===0)continue;let s=Math.abs(m)>=an?1/m:NaN;for(let d=o+1;d<n;d++){let p=Number.isNaN(s)?e[d][o]/m:e[d][o]*s;e[d][o]=p;for(let w=o+1;w<t;w++)e[d][w]=e[d][w]-p*e[o][w]}}let c=Array.from({length:n},(o,l)=>Array.from({length:a},(h,m)=>l===m?1:l>m?e[l][m]:0)),i=Array.from({length:a},(o,l)=>Array.from({length:t},(h,m)=>m>=l?e[l][m]:0)),f=Array.from({length:n},()=>new Array(n).fill(0));return u.forEach((o,l)=>f[o][l]=1),{P:f,L:c,U:i}}function cn(r,n={}){let{rank:t,tol:e}=n;if(t!==void 0){if(!Number.isFinite(t))throw new RangeError("is.finite(rank.) is not TRUE");if(!(Math.trunc(t)>0&&Math.abs(t)<2**31))throw new RangeError("as.integer(rank.) > 0 is not TRUE")}let u=r.map(m=>Array.from(m)),a=rt(u,{center:n.center??!0,scale:n.scale??!1});if(a.scale?.some(m=>m===0))throw new RangeError("cannot rescale a constant/zero column to unit variance");let c=$(a.scaled,{nu:0}),i=u.length,f=c.d.map(m=>m/Math.sqrt(Math.max(1,i-1))),o=t===void 0?f.length:Math.min(Math.trunc(t),f.length);e!==void 0&&(o=Math.min(o,f.filter(m=>m>f[0]*e).length));let l=c.v.map(m=>m.slice(0,o)),h={sdev:f,rotation:l,x:z(a.scaled,c.v).map(m=>m.slice(0,o))};return a.center!==void 0&&(h.center=a.center),a.scale!==void 0&&(h.scale=a.scale),h}export{Bt as add,Pt as backsolve,tn as cbind,Nt as chol,xt as chol2inv,Tt as crossprod,qt as det,Et as determinant,Yt as diag,Jt as divide,Rt as eigen,Ht as expm,jt as forwardsolve,St as ginv,Ft as kappa,en as kronecker,sn as lu,z as matMul,rn as matrix,Gt as multiply,kt as norm,Wt as outer,cn as prcomp,mt as qr,pt as qrCoef,wt as qrFitted,Mt as qrQ,ht as qrQty,dt as qrQy,bt as qrR,gt as qrResid,vt as qrSolve,yt as qrX,nn as rbind,At as rcond,Ot as schur,on as seq,H as solve,Ct as subtract,$ as svd,D as t,_t as tcrossprod};
|
|
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{F as rt,h as tt,i as nt}from"./chunks/chunk-JQG3YQOC.js";import"./chunks/chunk-3WPU6LGK.js";import{a as Ft,b as St}from"./chunks/chunk-MDYE7QP2.js";import{B as xt,D as L,E as Rt,F as Y,G as Z,a as q,b as K,c as R,d as T,e as k,g as j,h as mt,i as ht,j as dt,k as pt,l as gt,m as wt,n as Mt,o as bt,p as yt,q as vt,r as $,s as kt,t as U,u as W,v as H,w as Et,x as qt,y as At,z as Nt}from"./chunks/chunk-E2LCSVQV.js";import"./chunks/chunk-HD73UKPT.js";import"./chunks/chunk-VLUL2HFW.js";import"./chunks/chunk-KT66SB7R.js";function Tt(r,n){let t=T(r),e=n===void 0?t:T(n);if(t.nrow!==e.nrow)throw new TypeError(`non-conformable arguments (${t.nrow} and ${e.nrow} rows)`);let u=t.nrow,a=q(t.ncol,e.ncol);for(let c=0;c<e.ncol;c++)for(let i=0;i<t.ncol;i++){if(n===void 0&&i>c)continue;let f=0;for(let o=0;o<u;o++)f+=t.data[o+i*u]*e.data[o+c*u];a.data[i+c*t.ncol]=f}return n===void 0&&et(a),k(a)}function _t(r,n){let t=T(r),e=n===void 0?t:T(n);if(t.ncol!==e.ncol)throw new TypeError(`non-conformable arguments (${t.ncol} and ${e.ncol} columns)`);let u=q(t.nrow,e.nrow);for(let a=0;a<e.nrow;a++)for(let c=0;c<t.nrow;c++){if(n===void 0&&c>a)continue;let i=0;for(let f=0;f<t.ncol;f++)i+=t.data[c+f*t.nrow]*e.data[a+f*e.nrow];u.data[c+a*t.nrow]=i}return n===void 0&&et(u),k(u)}function et(r){let n=r.nrow;for(let t=0;t<n;t++)for(let e=t+1;e<n;e++)r.data[e+t*n]=r.data[t+e*n]}function Pt(r,n,t={}){return ot(r,n,t.k,t.upperTri??!0,t.transpose??!1)}function jt(r,n,t={}){return ot(r,n,t.k,t.upperTri??!1,t.transpose??!1)}function ot(r,n,t,e,u){let a=R(r),c=T(n),i=t??a.ncol;if(!Number.isInteger(i)||i<1||i>a.nrow||i>a.ncol||i>c.nrow)throw new RangeError(`invalid k (got ${i})`);for(let o=0;o<i;o++)if(a.data[o+o*a.nrow]===0)throw new Error(`singular matrix: diagonal element ${o+1} is zero`);let f=q(i,c.ncol);for(let o=0;o<c.ncol;o++)for(let l=0;l<i;l++)f.data[l+o*i]=c.data[l+o*c.nrow];return It(a,i,f,e,u),K(n)?k(f):Array.from(f.data)}function It(r,n,t,e,u){let a=r.nrow,c=r.data,i=t.nrow,f=t.data;for(let o=0;o<t.ncol;o++){let l=o*i;if(!u&&e){for(let h=n-1;h>=0;h--)if(f[l+h]!==0){f[l+h]/=c[h+h*a];let m=f[l+h];for(let s=0;s<h;s++)f[l+s]-=m*c[s+h*a]}}else if(u)if(e)for(let h=0;h<n;h++){let m=f[l+h];for(let s=0;s<h;s++)m-=c[s+h*a]*f[l+s];f[l+h]=m/c[h+h*a]}else for(let h=n-1;h>=0;h--){let m=f[l+h];for(let s=h+1;s<n;s++)m-=c[s+h*a]*f[l+s];f[l+h]=m/c[h+h*a]}else for(let h=0;h<n;h++)if(f[l+h]!==0){f[l+h]/=c[h+h*a];let m=f[l+h];for(let s=h+1;s<n;s++)f[l+s]-=m*c[s+h*a]}}}function Ot(r){let n=R(r);j(n);let t=n.nrow;if(t===0)throw new RangeError("the matrix has zero dimension");for(let s of n.data)if(!Number.isFinite(s))throw new RangeError("the matrix contains NaN or infinite values");let e={nrow:t,ncol:t,data:n.data.slice()},u=q(t,t),a=new Float64Array(t),c=new Float64Array(t);Y(e,u),Z(e,u,a,c,!0);let i=e.data,f=u.data,o=(s,d)=>s+d*t,l=new Uint8Array(t);for(let s=0;s+1<t;s++)c[s]>0&&c[s+1]<0&&(l[s++]=1);for(let s=0;s<t;s++)for(let d=s+1;d<t;d++)d===s+1&&l[s]||(i[o(d,s)]=0);let h=new Array(t),m=new Array(t);for(let s=0;s<t;s++){if(!l[s]){h[s]=i[o(s,s)],m[s]=0;continue}let d=$t(i[o(s,s)],i[o(s,s+1)],i[o(s+1,s)],i[o(s+1,s+1)]);i[o(s,s)]=d.a,i[o(s,s+1)]=d.b,i[o(s+1,s)]=d.c,i[o(s+1,s+1)]=d.d;let{cs:p,sn:w}=d;for(let g=s+2;g<t;g++){let M=i[o(s,g)],b=i[o(s+1,g)];i[o(s,g)]=p*M+w*b,i[o(s+1,g)]=p*b-w*M}for(let g=0;g<s;g++){let M=i[o(g,s)],b=i[o(g,s+1)];i[o(g,s)]=p*M+w*b,i[o(g,s+1)]=p*b-w*M}for(let g=0;g<t;g++){let M=f[o(g,s)],b=f[o(g,s+1)];f[o(g,s)]=p*M+w*b,f[o(g,s+1)]=p*b-w*M}h[s]=d.rt1r,m[s]=d.rt1i,h[s+1]=d.rt2r,m[s+1]=d.rt2i,s++}return{T:k(e),Q:k(u),valuesRe:h,valuesIm:m}}var N=(r,n)=>n>=0&&!Object.is(n,-0)?Math.abs(r):-Math.abs(r);function $t(r,n,t,e){let u=22250738585072014e-324,a=Number.EPSILON,c=4,i=2**Math.trunc(Math.log(u/a)/Math.log(2)/2),f=1/i,o,l;if(t===0)o=1,l=0;else if(n===0){o=0,l=1;let m=e;e=r,r=m,n=-t,t=0}else if(r-e===0&&N(1,n)!==N(1,t))o=1,l=0;else{let m=r-e,s=.5*m,d=Math.max(Math.abs(n),Math.abs(t)),p=Math.min(Math.abs(n),Math.abs(t))*N(1,n)*N(1,t),w=Math.max(Math.abs(s),d),g=s/w*s+d/w*p;if(g>=c*a){g=s+N(Math.sqrt(w)*Math.sqrt(g),s),r=e+g,e=e-d/g*p;let M=Math.hypot(t,g);o=g/M,l=t/M,n=n-t,t=0}else{let M=0,b=n+t;for(;M++,w=Math.max(Math.abs(m),Math.abs(b)),!(!(w>=f&&(b*=i,m*=i,M<=20))&&!(w<=i&&(b*=f,m*=f,M<=20))););s=.5*m;let x=Math.hypot(b,m);o=Math.sqrt(.5*(1+Math.abs(b)/x)),l=-(s/(x*o))*N(1,b);let F=r*o+n*l,S=-r*l+n*o,Q=t*o+e*l,X=-t*l+e*o;if(r=F*o+Q*l,n=S*o+X*l,t=-F*l+Q*o,e=-S*l+X*o,m=.5*(r+e),r=m,e=m,t!==0)if(n!==0){if(N(1,n)===N(1,t)){let B=Math.sqrt(Math.abs(n)),C=Math.sqrt(Math.abs(t));s=N(B*C,t),x=1/Math.sqrt(Math.abs(n+t)),r=m+s,e=m-s,n=n-t,t=0;let G=B*x,J=C*x;m=o*G-l*J,l=o*J+l*G,o=m}}else n=-t,t=0,m=o,o=-l,l=m}}let h=t===0?0:Math.sqrt(Math.abs(n))*Math.sqrt(Math.abs(t));return{a:r,b:n,c:t,d:e,cs:o,sn:l,rt1r:r,rt1i:h,rt2r:e,rt2i:-h}}var Ut=["Higham08.b","Higham08","Pade","Taylor","PadeO","TaylorO"];function Ht(r,n={}){let t=n.method??"Higham08.b";if(!Ut.includes(t))throw new RangeError(`unknown method: ${String(t)}`);let e=n.order??8;if(!Number.isInteger(e)||e<1)throw new RangeError("order must be a positive integer");let u=R(r);j(u);let a=u.nrow;if(a===0)return[];if(a===1)return[[Math.exp(u.data[0])]];if(t==="Taylor"||t==="TaylorO")return k(Dt(u,e));if(t==="Pade"||t==="PadeO")return k(Qt(u,e));let c,i;t==="Higham08.b"&&(c=L("P",u),i=L("S",u));let f=zt(u),o=f.data,l=(h,m)=>h+m*a;if(i){let h=i.scale;for(let m=0;m<a;m++)for(let s=0;s<a;s++)o[l(s,m)]=o[l(s,m)]*h[s]/h[m]}if(c){let h=c.scale,m=s=>{let d=h[s];if(d!==s){for(let p=0;p<a;p++)[o[l(p,s)],o[l(p,d)]]=[o[l(p,d)],o[l(p,s)]];for(let p=0;p<a;p++)[o[l(s,p)],o[l(d,p)]]=[o[l(d,p)],o[l(s,p)]]}};for(let s=c.ilo-1;s>=0;s--)m(s);for(let s=c.ihi+1;s<a;s++)m(s)}return k(f)}var Lt={3:[120,60,12,1],5:[30240,15120,3360,420,30,1],7:[17297280,8648640,1995840,277200,25200,1512,56,1],9:[17643225600,8821612800,2075673600,302702400,30270240,2162160,110880,3960,90,1]},Vt=[6476475253248e4,3238237626624e4,7771770303897600,0x437e459424400,129060195264e3,0x99a917d4d00,670442572800,33522128640,1323241920,40840800,960960,16380,182,1];function zt(r){let n=r.nrow,t=U(r),e=V(n),u,a,c=0;if(t<=2.1){let l=t<=.015?3:t<=.25?5:t<=.95?7:9,h=Lt[l],m=E(r,r),s=I([[h[1],e]]),d=I([[h[0],e]]),p=m;for(let w=1;w<=(l-1)/2;w++)w>1&&(p=E(p,m)),_(s,h[2*w+1],p),_(d,h[2*w],p);u=E(r,s),a=d}else{c=Math.max(0,Math.ceil(Math.log2(t/5.4)));let l=P(r,1/2**c),h=E(l,l),m=E(h,h),s=E(h,m),d=Vt,p=I([[d[13],s],[d[11],m],[d[9],h]]),w=E(s,p);for(let[M,b]of[[7,s],[5,m],[3,h],[1,e]])_(w,d[M],b);u=E(l,w);let g=I([[d[12],s],[d[10],m],[d[8],h]]);a=E(s,g);for(let[M,b]of[[6,s],[4,m],[2,h],[0,e]])_(a,d[M],b)}let i=q(n,n),f=q(n,n);for(let l=0;l<n*n;l++)i.data[l]=a.data[l]-u.data[l],f.data[l]=a.data[l]+u.data[l];let o=R(H(k(i),k(f)));for(let l=0;l<c;l++)o=E(o,o);return o}function st(r){let n=Math.sqrt(U(r)*W(r)),t=1;for(;2**t<n;)t++;return t+4}function ct(r,n){for(let t=0;t<n;t++)r=E(r,r);return r}function it(r){let n=r.nrow;for(let t=0;t<n;t++)r.data[t+t*n]=r.data[t+t*n]+1}function Dt(r,n){let t=st(r),e=2**t,u=V(r.nrow);for(let a=n;a>=1;a--)u=P(E(u,r),1/(a*e)),it(u);return ct(u,t)}function at(r,n,t,e){let u=e===1?r:P(r,-1),a=V(r.nrow);for(let c=n;c>=1;c--){let i=(n-c+1)/(c*(2*n-c+1)*t);a=P(E(a,u),i),it(a)}return a}function Qt(r,n){let t=r.nrow,e=st(r),u=2**e,a=at(r,n,u,1),c=at(r,n,u,-1),i=q(t,t);for(let f=0;f<t;f++)i.data.set(Xt(c,a.data.subarray(f*t,(f+1)*t)),f*t);return ct(i,e)}function Xt(r,n){let t=r.nrow,e=1e-100,u=d=>{let p=new Float64Array(t);for(let w=0;w<t;w++){let g=0;for(let M=0;M<t;M++)g+=r.data[w+M*t]*d[M];p[w]=g}return p},a=(d,p)=>{let w=0;for(let g=0;g<t;g++)w+=d[g]*p[g];return w},c=(d,p,w)=>{let g=new Float64Array(t);for(let M=0;M<t;M++)g[M]=d[M]+p*w[M];return g},i=new Float64Array(t),f=Float64Array.from(n),o=Float64Array.from(n),l=Float64Array.from(n),h=Float64Array.from(n),m=Math.sqrt(a(f,f)),s=a(h,n);if(Math.abs(s)<=e)return i;for(let d=0;d<t;d++){let p=u(o),w=a(h,p);if(Math.abs(w)<=e)return i;let g=s/w;if(Math.abs(g)<=e)return i;let M=c(l,-g,p);p=c(l,1,M);let b=u(p);f=c(f,-g,b);let x=Math.sqrt(a(f,f));if(i=c(i,g,p),Math.abs(x/m)<=1e-30)return i;let F=a(h,f);if(Math.abs(F)<=e)return i;let S=F/s;s=F,l=c(f,S,M),b=c(M,S,o),o=c(l,S,b)}return i}function V(r){let n=q(r,r);for(let t=0;t<r;t++)n.data[t+t*r]=1;return n}function E(r,n){let t=r.nrow,e=r.ncol,u=n.ncol,a=q(t,u);for(let c=0;c<u;c++)for(let i=0;i<t;i++){let f=0;for(let o=0;o<e;o++)f+=r.data[i+o*t]*n.data[o+c*e];a.data[i+c*t]=f}return a}function P(r,n){return{nrow:r.nrow,ncol:r.ncol,data:r.data.map(t=>t*n)}}function _(r,n,t){for(let e=0;e<r.data.length;e++)r.data[e]=r.data[e]+n*t.data[e]}function I(r){let[n,t]=r[0],e=P(t,n);for(let u=1;u<r.length;u++)_(e,r[u][0],r[u][1]);return e}function v(r){return typeof r!="number"&&r.length>0&&Array.isArray(r[0])}function y(r){return typeof r=="number"?[r]:Array.from(r)}function A(r){let n=r[0].length;if(r.some(t=>t.length!==n))throw new TypeError("all rows of the matrix must have the same length");return n}function z(r,n){let t,e;if(v(r)&&v(n))t=r.map(c=>[...c]),e=n.map(c=>[...c]);else if(v(r)){let c=y(n),i=A(r);t=r.map(f=>[...f]),e=i===c.length?c.map(f=>[f]):i===1?[c]:[]}else if(v(n)){let c=y(r);e=n.map(i=>[...i]),t=n.length===c.length?[c]:n.length===1?c.map(i=>[i]):[]}else{let c=y(r),i=y(n);if(c.length===i.length)t=[c],e=i.map(f=>[f]);else if(c.length===1)t=[c],e=[i];else if(i.length===1)t=c.map(f=>[f]),e=[i];else throw new RangeError("non-conformable arguments")}let u=t[0]?.length??0;if(t.length===0||e.length!==u)throw new RangeError("non-conformable arguments");A(t);let a=A(e);return t.map(c=>{let i=new Array(a).fill(0);for(let f=0;f<a;f++){let o=0;for(let l=0;l<u;l++)o+=c[l]*e[l][f];i[f]=o}return i})}function O(r,n,t){let e=v(r),u=v(n);if(e&&u){let f=A(r);if(r.length!==n.length||f!==A(n))throw new RangeError("non-conformable arrays");return r.map((o,l)=>o.map((h,m)=>t(h,n[l][m])))}if(e||u){let f=e?r:n,o=y(e?n:r),l=f.length,h=A(f);if(o.length===0)return f.map(m=>m.map(()=>NaN));if(o.length>l*h)throw new RangeError("dims [product "+l*h+"] do not match the length of object ["+o.length+"]");return f.map((m,s)=>m.map((d,p)=>e?t(d,o[(s+p*l)%o.length]):t(o[(s+p*l)%o.length],d)))}let a=y(r),c=y(n);if(a.length===0||c.length===0)return[];let i=Math.max(a.length,c.length);return Array.from({length:i},(f,o)=>t(a[o%a.length],c[o%c.length]))}function Bt(r,n){return O(r,n,(t,e)=>t+e)}function Ct(r,n){return O(r,n,(t,e)=>t-e)}function Gt(r,n){return O(r,n,(t,e)=>t*e)}function Jt(r,n){return O(r,n,(t,e)=>t/e)}var Kt={"*":(r,n)=>r*n,"+":(r,n)=>r+n,"-":(r,n)=>r-n,"/":(r,n)=>r/n,"^":(r,n)=>r**n};function Wt(r,n,t="*"){let e=typeof t=="function"?t:Kt[t];if(e===void 0)throw new RangeError(`invalid fun "${String(t)}"`);let u=Array.from(r),a=Array.from(n);return u.map(c=>a.map(i=>e(c,i)))}function D(r){if(!v(r))return[y(r)];let n=A(r);return Array.from({length:n},(t,e)=>r.map(u=>u[e]))}function Yt(r,n={}){if(v(r)){let i=A(r);return Array.from({length:Math.min(r.length,i)},(f,o)=>r[o][o])}let t=y(r),e,u;if(t.length===1&&n.nrow===void 0&&n.ncol===void 0){if(u=Math.trunc(t[0]),!(u>=0))throw new RangeError("invalid 'nrow' value (< 0)");e=[1]}else e=t,u=n.nrow??t.length;let a=n.ncol??u,c=Array.from({length:u},()=>new Array(a).fill(0));for(let i=0;i<Math.min(u,a);i++)c[i][i]=e[i%e.length];return u===0?[]:c}function ft(r,n){let t=r.map(a=>v(a)?n?D(a):a.map(c=>[...c]):[y(a)]),e=r.filter(v),u=e.length>0?n?e[0].length:A(e[0]):Math.max(...t.map(a=>a[0].length));return e.forEach((a,c)=>{if((n?a.length:A(a))!==u)throw new RangeError(`number of ${n?"rows":"columns"} of matrices must match (see arg ${c+2})`)}),t.flatMap(a=>a.map(c=>Array.from({length:u},(i,f)=>c[f%c.length])))}function Zt(r){return typeof r=="object"&&!Array.isArray(r)&&!ArrayBuffer.isView(r)}function ut(r){let n=r.filter(Zt);if(n.length!==0){if(n.length<r.length)throw new TypeError("cannot combine data frames with vectors or matrices");return n}}function tn(...r){let n=ut(r);return n===void 0?D(ft(r,!0)):nt(n)}function nn(...r){let n=ut(r);return n===void 0?ft(r,!1):tt(n)}function rn(r,n={}){let t=y(r),e=t.length,{nrow:u,ncol:a}=n;u===void 0&&a===void 0?(u=e,a=1):u===void 0?u=Math.ceil(e/a):a===void 0&&(a=Math.ceil(e/u));let c=n.byrow??!1;return Array.from({length:u},(i,f)=>Array.from({length:a},(o,l)=>e===0?NaN:t[(c?f*a+l:f+l*u)%e]))}function en(r,n){if(!v(r)&&!v(n)){let a=y(r),c=y(n);return a.flatMap(i=>c.map(f=>i*f))}let t=v(r)?r:y(r).map(a=>[a]),e=v(n)?n:y(n).map(a=>[a]),u=[];for(let a of t)for(let c of e)u.push(a.flatMap(i=>c.map(f=>i*f)));return u}function on(r,n,t={}){let{by:e,lengthOut:u}=t;if(n===void 0&&e===void 0&&u===void 0&&r!==void 0){if(!Number.isFinite(r))throw new RangeError("'from' must be a finite number");return lt(1,r)}if(r!==void 0&&!Number.isFinite(r))throw new RangeError("'from' must be a finite number");if(n!==void 0&&!Number.isFinite(n))throw new RangeError("'to' must be a finite number");if(u===void 0){if(e===void 0)return lt(r??1,n??1);let c=r??1,i=n??1,f=i-c;if(f===0&&i===0)return[i];let o=f/e;if(!Number.isFinite(o)){if(e===0&&f===0)return[c];throw new RangeError("invalid '(to - from)/by'")}if(o<0)throw new RangeError("wrong sign in 'by' argument");if(Math.abs(f)/Math.max(Math.abs(i),Math.abs(c))<100*Number.EPSILON)return[c];let l=Math.trunc(o+1e-10);return Array.from({length:l+1},(h,m)=>e>0?Math.min(c+m*e,i):Math.max(c+m*e,i))}if(!Number.isFinite(u)||u<0)throw new RangeError("'length.out' must be a non-negative number");let a=Math.ceil(u);if(a===0)return[];if(e===void 0){let c=n??(r??1)+(a-1),i=r??c-(a-1);if(a<=2)return[i,c].slice(0,a);if(i===c)return new Array(a).fill(i);let f=(c-i)/(a-1);return Array.from({length:a},(o,l)=>l===0?i:l===a-1?c:i+l*f)}if(n===void 0){let c=r??1;return Array.from({length:a},(i,f)=>c+f*e)}if(r===void 0)return Array.from({length:a},(c,i)=>n-(a-1-i)*e);throw new RangeError("too many arguments")}function lt(r,n){let t=Math.trunc(Math.abs(n-r)+1+11920928955078125e-23),e=r<=n?1:-1;return Array.from({length:t},(u,a)=>r+e*a)}var an=22250738585072014e-324;function sn(r){let n=r.length,t=n===0?0:r[0].length,e=r.map(o=>{if(o.length!==t)throw new TypeError("all rows of the matrix must have the same length");return Array.from(o)}),u=Array.from({length:n},(o,l)=>l),a=Math.min(n,t);for(let o=0;o<a;o++){let l=o,h=Math.abs(e[o][o]);for(let d=o+1;d<n;d++){let p=Math.abs(e[d][o]);(p>h||Number.isNaN(h))&&(h=p,l=d)}l!==o&&([e[l],e[o]]=[e[o],e[l]],[u[l],u[o]]=[u[o],u[l]]);let m=e[o][o];if(m===0)continue;let s=Math.abs(m)>=an?1/m:NaN;for(let d=o+1;d<n;d++){let p=Number.isNaN(s)?e[d][o]/m:e[d][o]*s;e[d][o]=p;for(let w=o+1;w<t;w++)e[d][w]=e[d][w]-p*e[o][w]}}let c=Array.from({length:n},(o,l)=>Array.from({length:a},(h,m)=>l===m?1:l>m?e[l][m]:0)),i=Array.from({length:a},(o,l)=>Array.from({length:t},(h,m)=>m>=l?e[l][m]:0)),f=Array.from({length:n},()=>new Array(n).fill(0));return u.forEach((o,l)=>f[o][l]=1),{P:f,L:c,U:i}}function cn(r,n={}){let{rank:t,tol:e}=n;if(t!==void 0){if(!Number.isFinite(t))throw new RangeError("is.finite(rank.) is not TRUE");if(!(Math.trunc(t)>0&&Math.abs(t)<2**31))throw new RangeError("as.integer(rank.) > 0 is not TRUE")}let u=r.map(m=>Array.from(m)),a=rt(u,{center:n.center??!0,scale:n.scale??!1});if(a.scale?.some(m=>m===0))throw new RangeError("cannot rescale a constant/zero column to unit variance");let c=$(a.scaled,{nu:0}),i=u.length,f=c.d.map(m=>m/Math.sqrt(Math.max(1,i-1))),o=t===void 0?f.length:Math.min(Math.trunc(t),f.length);e!==void 0&&(o=Math.min(o,f.filter(m=>m>f[0]*e).length));let l=c.v.map(m=>m.slice(0,o)),h={sdev:f,rotation:l,x:z(a.scaled,c.v).map(m=>m.slice(0,o))};return a.center!==void 0&&(h.center=a.center),a.scale!==void 0&&(h.scale=a.scale),h}export{Bt as add,Pt as backsolve,tn as cbind,Nt as chol,xt as chol2inv,Tt as crossprod,qt as det,Et as determinant,Yt as diag,Jt as divide,Rt as eigen,Ht as expm,jt as forwardsolve,St as ginv,Ft as kappa,en as kronecker,sn as lu,z as matMul,rn as matrix,Gt as multiply,kt as norm,Wt as outer,cn as prcomp,mt as qr,pt as qrCoef,wt as qrFitted,Mt as qrQ,ht as qrQty,dt as qrQy,bt as qrR,gt as qrResid,vt as qrSolve,yt as qrX,nn as rbind,At as rcond,Ot as schur,on as seq,H as solve,Ct as subtract,$ as svd,D as t,_t as tcrossprod};
|