Qf3UgdZddlZddlZddlZddlZddlmZddlmZddl m Z m Z m Z ddl mZmZddlmZmZmZmZmZmZmZmZmZddlmZdd lmZdd lmZmZm Z ed Z!Gd d e"Z#dZ$dBdZ%dZ&dZ'dZ(dZ)dCdZ*dddddde+e,fdZ-de.de.de.fdZ/dej`jbzdzZ2e.e3d <de.de.de,fd!Z4de.de.defd"Z5d#Z6dBd$Z7d%Z8dBd&Z9d'Z:d(Z;d)Zd,Z?d-d.d/d0Z@dBd1ZAdBd2ZBdBd3ZCdBd4ZDd5ZEd6ZFd7d8d9ZGed:d;ZHdd<d=ZId>ZJ dd?lKmJZJGd@dAZMy#eL$rYwxYw)E) NormalDistStatisticsError correlation covariancefmeangeometric_mean harmonic_meanlinear_regressionmeanmedianmedian_grouped median_high median_lowmode multimodepstdev pvariance quantilesstdevvarianceNFraction)Decimal)countgroupbyrepeat) bisect_left bisect_right) hypotsqrtfabsexperftaulogfsumsumprod)reduce) itemgetter)Counter namedtuple defaultdict@c eZdZy)rN)__name__ __module__ __qualname__1/opt/alt/python312/lib64/python3.12/statistics.pyrrsr3rcp d}t}|j}i}|j}t|tD]9\}}||t t |D]\}} |dz }|| d|z|| <;d|vr|d} n td|jD} tt|t} | | |fS)Nrc3:K|]\}}t||ywNr.0dns r4 z_sum..s@/?tq!HQN/?) setaddgetrtypemap _exact_ratiosumitemsr(_coerceint) datartypes types_addpartials partials_gettypvaluesr<r;totalTs r4_sumrRs> E EE IH<.s.s@,?DAq!Q,?r>c3@K|]\}}t|||zywr8rr9s r4r=z_ss..s"D/Ctq!(1ac"/Cs)rRr?r@r,rHrrBrCrDrrErFr(rG)rIrVrQssdrrJrK sx_partials sxx_partialsrNrOr<sxsxxr;s ` @r4_ssr^sV }B?Bc#DK |D]}|dkr t||yw)Nr)r)rOerrmsgrUs r4 _fail_negrx_s*A  q5!&) )s Faverager6)keyreversetiesstartreturncV |dk7rtd|| t||}tt|t |}|dz }dgt |z}t |tdD]:\}} t| } t | } || dzdz z} | D] \} }| ||< || z }<|S)NryzUnknown tie resolution method: )r{r6r)rz) rorCsortedziprlenrr)list)rIrzr{r|r}val_posiresult_ggroupsizerankrtorig_poss r4_rankrgsH y:4(CDD 3~Suw'9G  AS3w< FZ]31Q5zD1H>!$OE8#F8  % T  4 Mr3r<mcP tj||z}|||z|z|k7zSr8)rbisqrt)r<ras r4_integer_sqrt_of_frac_rtors.P 16A !A r3r_sqrt_bit_widthc |j|jz tz dz}|dk\rt||d|zz|z}d}||z St|d|zz|}d| z}||z S)Nrrr6) bit_lengthrr)r<rqrprqs r4_float_sqrt_of_fracrs; !,,. (? :q@AAv-aa!e<A   { "".a26k1= A2g { ""r3c |dkr|s tdS| | }}t|t|z j}|j\}}|j}|j\}}d|z||zdzz|||z||zzdzzkDr|S|j }|j\} } d|z|| zdzz||| z| |zzdzzkr|S|S)Nrz0.0r)rr rm next_plus next_minus) r<rrootnrdrplusnpdpminusnmdms r4_decimal_sqrt_of_fracrs= Av5> !rA21 AJ # ) ) +D  " " $FB >> D  " " $FB1u2zABB 222 OO E  # # %FB1u2zABB 222 Kr3c` t|\}}}|dkr tdt||z |S)Nr6z%mean requires at least one data point)rRrru)rIrQrPr<s r4r r s<t*KAua1uEFF EAIq !!r3c^ |) t|t|}s td|z St |t t fs t |} t||}t|}|s td||z S#t$rdfd}||}YwxYw#t$r tdwxYw)Nrc3@Kt|dD] \}| yw)Nr6r}) enumerate)iterablerUr<s r4rzfmean..counts!%ha8DAqG9sz&fmean requires at least one data pointz(data and weights must be the same lengthzsum of weights must be non-zero) rrir&r isinstancertupler'ro)rIweightsrrPnumdenr<s @r4rrs D AT !"JK Kqy ge} -w-JdG$ w-C ?@@ 9+ A ;D  JHIIJs A9 B9BBB,c| tttt|S#t$r t ddwxYw)NzGgeometric mean requires a non-empty dataset containing positive numbers)r"rrCr%ror)rIs r4rrsJ G5S$()) G<=BF GGs!%;cz t||ur t|}d}t|}|dkr td|dk(rD|B|d}t |t j tfr|dkr t||Std|td|}|}nQt||ur t|}t||k7r tdtdt||D\}}} t||}tdt||D\}}} |dkr td t||z |S#t$rYywxYw) Nz.harmonic mean does not support negative valuesr6z.harmonic_mean requires at least one data pointrzunsupported typez*Number of weights does not match data sizec3 K|]}|ywr8r2)r:ws r4r=z harmonic_mean..Ns G,Fq,Fs c34K|]\}}|r||z ndyw)rNr2)r:rrUs r4r=z harmonic_mean..Qs"P=OTQq1uq0=OszWeighted sum must be positive)iterrrrrnumbersRealrrirrRrxrZeroDivisionErrorru) rIrrwr<rU sum_weightsrrQrPrs r4rr!sR, DzTDz =F D A1uNOO aGO G a',,0 11u%f--H./ /A, =G #7mG w<1 !"NO O GIgv,F GG;v&PS$=OPP5% z=>> K%' ++ s#,D.. D:9D:c t|}t|}|dk(r td|dzdk(r||dzS|dz}||dz ||zdz SNrno median for empty datarr6rrr)rIr<rs r4r r Ysl  $@@As A>>Bc tt|jd} |ddS#t$r t ddwxYw)Nr6rzno mode for empty data)r*r most_common IndexErrorr)rIpairss r4rrsU, DJ  + +A .EBQx{ B67TABs .Ac tt|}|sgSt|j}|j Dcgc] \}}||k(s |c}}Scc}}wr8)r*rmaxrOrF)rIcountsmaxcountrtrs r4rrsX T$Z F  6==?#H&,lln JnleU8IEn JJ Js  AAr exclusive)r<methodc* |dkr tdt|}t|}|dkr td|dk(rW|dz }g}td|D]?}t ||z|\}}||||z z||dz|zz|z } |j | A|S|dk(rn|dz}g}td|D]V}||z|z}|dkrdn||dz kDr|dz n|}||z||zz }||dz ||z z|||zz|z } |j | X|St d|)Nr6zn must be at least 1rz"must have at least two data points inclusiverUnknown method: )rrrrangedivmodappendro) rIr<rldrrrrdelta interpolateds r4rr9sf 1u455 $>r3c t||\}}}}|dkr td||z }t|tr t |j |j St|j |j S)Nr6z'pstdev requires at least one data pointr)rIrrQrrVr<rs r4rrsldB-KAr1a1uGHH q&C!W$S]]COODD s}}coo >>r3c t|\}}}}|dkr td||dz z } t|t|j|j fS#t $r%t|t|t|z fcYSwxYwr)r^rrhrrprqra)rIrQrrr<rs r4 _mean_stdevrsPYNAr41uGHH A,C4T{/ sOOO 4T{E$K%)3334s*A+BBc t|}t||k7r td|dkr tdt||z t||z tfd|Dfd|D}||dz z S)NzDcovariance requires that both inputs have same number of data pointsrz,covariance requires at least two data pointsc3(K|] }|z  ywr8r2)r:xirs r4r=zcovariance..s)q29qc3(K|] }|z  ywr8r2r:yiybars r4r=zcovariance..s+B"BIrr6)rrr&r')rUyr<sxyrrs @@r4rrs} AA 1v{dee1uLMM 7Q;D 7Q;D )q)+B+B CC !a%=r3linear)rc t|}t||k7r td|dkr td|dvrtd||dk(r#|dz dz }t|| }t|| }n@t ||z }t ||z }|Dcgc]}||z  }}|Dcgc]}||z  }}t ||} t ||} t ||} | t | | zz Scc}wcc}w#t$r td wxYw) NzEcorrelation requires that both inputs have same number of data pointsrz-correlation requires at least two data points>rrankedrrr6rrz&at least one of the inputs is constant)rrrorr&r'r r) rUrrr<r}rrrrrr]syys r4rrs0, AA 1v{eff1uMNN ))+F:677 Q"  !5 ! !5 !Aw{Aw{!" #2R$Y #!" #2R$Y # !Q-C !Q-C !Q-CHT#)_$$ $ # HFGGHs C&" C+C00DLinearRegressionslope intercept) proportionalc t|}t||k7r td|dkr td|s9t||z }t||z |Dcgc]}||z  }} fd|D}t||dz}t||} ||z }|rdn |zz } t || Scc}w#t$r tdwxYw)NzKlinear regression requires that both inputs have same number of data pointsrz3linear regression requires at least two data pointsc3(K|] }|z  ywr8r2rs r4r=z$linear_regression..us #2R$Yrz x is constantr)rrr&r'rr) rUrrr<rrrr]rrrs @r4r r Fs$J AA 1v{kll1uSTT Aw{Aw{!" #2R$Y # # # !Q-# C !Q-C/c $ )l@gN@g"]Ξ@gnC`@gu @giK~j@gv|E@gd|1@gfRr@gu.2@g~y@gn8(E@?rg@g?g鬷ZaI?ggElD?g7\?guSS?g=. @gj%b@gHw@gjRe?g9dh? >g('߿A?g~z ?g@3?gɅ3?g3fRx?gIFl@gt>g*Yn>gESB\T?gN;A+?gUR1?gEF?gPn@g&>@gigtcI,\>gŝI?g*F2v?gC4?gO1?)r!r r%)prsigmarrrrrUs r4_normal_dist_inv_cdfrs CA Aw% q1u 0140145601456115661 156 6 1 1 56 6 1 1 56 6115661140145601456115661 156 6 1 1 56 6 1 1 56 6 #IQY #X37A c!fW ACx G1A51256712567226772 267 7 2 2 67 7 2 2 67 7222A51256712567226772 267 7 2 2 67 7 2 2 67 7 G1A51256712567226772 267 7 2 2 67 7 2 2 67 7223Q61256712567226772 267 7 2 2 67 7 2 2 67 7 c A3w B U r3)rceZdZ dddZd dZedZdddZd Zd Z d Z d!d Z d Z dZ edZedZedZedZedZdZdZdZdZdZdZeZdZeZdZdZdZdZ dZ!y)"rz(Arithmetic mean of a normal distributionz+Standard deviation of a normal distribution_mu_sigmacf |dkr tdt||_t||_y)Nrzsigma must be non-negative)rrhr r )selfrrs r4__init__zNormalDist.__init__s.N 3;!">? ?9El r3c |t|Sr8)r)clsrIs r4 from_sampleszNormalDist.from_sampless?K%&&r3N)seedc |tjntj|j}|j|j}}t d|Dcgc] }||| c}Scc}wr8)randomgaussRandomr r r)rr<rrrrrs r4sampleszNormalDist.samplessYG $  &--2E2K2KHHdkkE*0q/:/Qb% /:::sA,c |j|jz}|s td||jz }t||zd|zz t t |zz S)Nz$pdf() not defined when sigma is zerog)r rr r"r r$)rrUrdiffs r4pdfzNormalDist.pdfsY>;;,!"HI I488|4$;$/23d3>6JJJr3c |js tdddt||jz |jtzz zzS)Nz$cdf() not defined when sigma is zerorr)r rr#r _SQRT2rrUs r4cdfzNormalDist.cdfsC6{{!"HI IcCTXX$++2F GHHIIr3cp |dks|dk\r tdt||j|jS)Nrrz$p must be in the range 0.0 < p < 1.0)rrr r )rrs r4inv_cdfzNormalDist.inv_cdfs9  8qCx!"HI I#Atxx==r3cf td|Dcgc]}|j||z c}Scc}wrs)rr!)rr<rs r4rzNormalDist.quantiles s4 .31a[9[ QU#[999s.c   t|ts td||}}|j|jf|j|jfkr||}}|j |j }}|r|s t d||z }t|j|jz }|s%dt|d|jztzz z S|j|z|j|zz }|j|jzt||z|t||z zzz} || z|z } || z |z } dt|j| |j| z t|j| |j| z zz S)Nz$Expected another NormalDist instancez(overlap() not defined when sigma is zerorr-) rrrir r rrr!r#rr r%r) rotherXYX_varY_vardvrrbx1x2s r4overlapzNormalDist.overlapsd %,BC CU1 HHaee !%%0 0aqAzz1::uE!"LM M U] !%%!%%- R3>F#:;<< < EEEMAEEEM ) HHqxx $rBwc%%-6H1H'H"I I!er\!er\d1559quuRy01DrQUU2Y9N4OOPPr3cj |js td||jz |jz S)Nz'zscore() not defined when sigma is zero)r rr rs r4zscorezNormalDist.zscore9s3 {{!"KL LDHH  ++r3c |jSr8r rs r4r zNormalDist.meanDs5xxr3c |jSr8r1r2s r4r zNormalDist.medianIs6xxr3c |jSr8r1r2s r4rzNormalDist.modeNs xxr3c |jSr8r r2s r4rzNormalDist.stdevWs8{{r3c6 |j|jzSr8r6r2s r4rzNormalDist.variance\s+{{T[[((r3c t|trAt|j|jzt|j|jSt|j|z|jSr8rrr rr r+r,s r4__add__zNormalDist.__add__aT  b* %bffrvvouRYY /JK K"&&2+ryy11r3c t|trAt|j|jz t|j|jSt|j|z |jSr8r9r:s r4__sub__zNormalDist.__sub__or<r3cb t|j|z|jt|zSr8rr r r!r:s r4__mul__zNormalDist.__mul__}+ "&&2+ryy48';<rArDrHrJ__radd__rL__rmul__rOrRrUrWrZr2r3r4rrs. :?I #''"&; KJ > : QD ,)) 2 2==-.HH; -P%&r3rr8)znegative value)r)N__all__rbrrsys fractionsrdecimalr itertoolsrrrbisectrrrr r!r"r#r$r%r&r' functoolsr(operatorr) collectionsr*r+r,rrorrRr^rdrGrDrurxrrhrrHr float_infomant_digr__annotations__rrr rrrr rr r rrrrrrrrrrrr r _statistics ImportErrorrr2r3r4rnshT .  ,,,EEE88 c j 3l&R 4>+\$IQ34PU;3l3>>222Q66 #3 #3 #5 #SSW<",!HG&5,p+0 ,&E+PB<Kr;(4b)%X&R?$?$ 4(8$,-H`02HI057>zGV 0 Z&Z&   s/EEE