a �DOg���@s�gd�ZddlZddlZddlZddlmZddlmZddlm Z ddl m Z m Z ddlm Z mZmZmZmZmZmZmZddlmZdd lmZGd d �d e�ZdFd d �Zdd�Zdd�Zdd�Zdd�Zdd�Z dd�Z!dGdd�Z"dd�Z#dd �Z$d!d"�Z%d#d$�Z&d%d&�Z'd'd(�Z(d)d*�Z)dHd,d-�Z*d.d/�Z+d0d1�Z,d2d3d4�d5d6�Z-dId7d8�Z.dJd9d:�Z/dKd;d<�Z0dLd=d>�Z1dMd?d@�Z2dAdB�Z3zddCl4m3Z3Wne5�y�Yn0GdDdE�dE�Z6dS)N)� NormalDist�StatisticsError�fmean�geometric_mean� harmonic_mean�mean�median�median_grouped� median_high� median_low�mode� multimode�pstdev� pvariance� quantiles�stdev�variance�N��Fraction)�Decimal)�groupby)� bisect_left� bisect_right)�hypot�sqrt�fabs�exp�erf�tau�log�fsum)� itemgetter)�Counterc@s eZdZdS)rN)�__name__� __module__� __qualname__�r&r&�"/usr/lib64/python3.9/statistics.pyrusrc Cs�d}t|�\}}||i}|j}ttt|��}t|t�D]@\}} t||�}tt| �D]"\}}|d7}||d�|||<qRq6d|vr�|d} ntdd�t|� ��D��} || |fS)Nr�css|]\}}t||�VqdS�Nr)�.0�d�nr&r&r'� ��z_sum..) � _exact_ratio�get�_coerce�int�typer�map�sum�sorted�items) �data�start�countr,r+ZpartialsZ partials_get�T�typ�values�totalr&r&r'�_sum{s$  r?cCs,z |��WSty&t�|�YS0dSr))Z is_finite�AttributeError�math�isfinite)�xr&r&r'� _isfinite�s  rDcCs�||ur |S|tus|tur |S|tur,|St||�r:|St||�rH|St|t�rV|St|t�rd|St|t�r|t|t�r||St|t�r�t|t�r�|Sd}t||j|jf��dS)Nz"don't know how to coerce %s and %s)r2�bool� issubclassr�float� TypeErrorr#)r;�S�msgr&r&r'r1�s  r1c Cs�znt|�tust|�tur$|��WSz|j|jfWWStyjz|��WYWStydYn0Yn0Wnttfy�|dfYS0d}t |� t|�j ���dS)Nz0can't convert type '{}' to numerator/denominator) r3rGr�as_integer_ratio� numerator� denominatorr@� OverflowError� ValueErrorrH�formatr#)rCrJr&r&r'r/�s   r/cCsnt|�|ur|St|t�r(|jdkr(t}z ||�WStyht|t�rb||j�||j�YS�Yn0dS)Nr()r3rFr2rMrGrHrrL)�valuer;r&r&r'�_convert�s    rRcCs.t||�}|t|�kr&|||kr&|St�dSr))r�lenrO)�arC�ir&r&r'� _find_lteq s rVcCs>t|||d�}|t|�dkr6||d|kr6|dSt�dS)N)�lor()rrSrO)rT�lrCrUr&r&r'� _find_rteqs rY�negative valueccs$|D]}|dkrt|��|VqdS)Nr)r)r=�errmsgrCr&r&r'� _fail_negsr\cCsHt|�|urt|�}t|�}|dkr,td��t|�\}}}t|||�S)Nr(z%mean requires at least one data point)�iter�listrSrr?rR)r8r,r;r>r:r&r&r'r's rcspz t|��Wn.ty:d��fdd�}t||��}Yn 0t|�}z |�WStyjtd�d�Yn0dS)Nrc3s t|dd�D]\�}|Vq dS)Nr()r9)� enumerate)�iterablerC�r,r&r'r:Oszfmean..countz&fmean requires at least one data point)rSrHr �ZeroDivisionErrorr)r8r:r>r&rar'rAs      rcCs6ztttt|���WSty0td�d�Yn0dS)NzGgeometric mean requires a non-empty dataset containing positive numbers)rrr4rrOr)r8r&r&r'r\s  �rcCs�t|�|urt|�}d}t|�}|dkr2td��n<|dkrn|d}t|tjtf�rf|dkrbt|��|Std��z"t dd�t ||�D��\}}}Wnt y�YdS0t |||�S)Nz.harmonic mean does not support negative valuesr(z.harmonic_mean requires at least one data pointrzunsupported typecss|]}d|VqdS)r(Nr&�r*rCr&r&r'r-�r.z harmonic_mean..) r]r^rSr� isinstance�numbersZRealrrHr?r\rbrR)r8r[r,rCr;r>r:r&r&r'ros$  " rcCs\t|�}t|�}|dkr td��|ddkr8||dS|d}||d||dSdS�Nr�no median for empty data�r(�r6rSr)r8r,rUr&r&r'r�s   rcCsLt|�}t|�}|dkr td��|ddkr8||dS||ddSdSrfri�r8r,r&r&r'r �s   r cCs,t|�}t|�}|dkr td��||dS)Nrrgrhrirjr&r&r'r �s r r(c Cs�t|�}t|�}|dkr"td��n|dkr2|dS||d}||fD]}t|ttf�rFtd|��qFz||d}Wn&ty�t|�t|�d}Yn0t||�}t |||�}|}||d} |||d|| S)Nrrgr(rhzexpected number but got %r) r6rSrrd�str�bytesrHrGrVrY) r8�intervalr,rC�obj�L�l1�l2�cf�fr&r&r'r�s&       rcCsBtt|���d�}z|ddWSty<td�d�Yn0dS)Nr(rzno mode for empty data)r"r]� most_common� IndexErrorr)r8�pairsr&r&r'r s  r cCs@tt|����}tt|td�d�dgf�\}}tttd�|��S)Nr()�keyr)r"r]rt�nextrr!r^r4)r8�countsZmaxcountZ mode_itemsr&r&r'r 4s r �� exclusive)r,�methodc CsB|dkrtd��t|�}t|�}|dkr0td��|dkr�|d}g}td|�D]D}t|||�\}}||||||d||} |�| �qN|S|dk�r0|d}g}td|�D]r}|||}|dkr�dn||dkr�|dn|}||||}||d||||||} |�| �q�|Std|����dS)Nr(zn must be at least 1rhz"must have at least two data pointsZ inclusiver{zUnknown method: )rr6rS�range�divmod�appendrO) r8r,r|Zld�m�resultrU�jZdeltaZ interpolatedr&r&r'rks2$   $$ rcs��dur,t�fdd�|D��\}}}||fSt|��t�fdd�|D��\}}}t�fdd�|D��\}}}||dt|�8}||fS)Nc3s|]}|�dVqdS�rhNr&rc��cr&r'r-�r.z_ss..c3s|]}|�dVqdSr�r&rcr�r&r'r-�r.c3s|]}|�VqdSr)r&rcr�r&r'r-�r.rh)r?rrS)r8r�r;r>r:�UZtotal2Zcount2r&r�r'�_ss�sr�cCsLt|�|urt|�}t|�}|dkr,td��t||�\}}t||d|�S)Nrhz*variance requires at least two data pointsr(�r]r^rSrr�rR)r8�xbarr,r;�ssr&r&r'r�s& rcCsHt|�|urt|�}t|�}|dkr,td��t||�\}}t|||�S)Nr(z*pvariance requires at least one data pointr�)r8�mur,r;r�r&r&r'r�s# rcCs6t||�}z |��WSty0t�|�YS0dSr))rrr@rA)r8r��varr&r&r'rs   rcCs6t||�}z |��WSty0t�|�YS0dSr))rrr@rA)r8r�r�r&r&r'r $s   r cCs|d}t|�dkr�d||}d|d|d|d|d|d |d |d |}d |d |d|d|d|d|d|d}||}|||S|dkr�|nd|}tt|� �}|dk�r^|d}d|d|d|d|d|d|d|d}d|d |d!|d"|d#|d$|d%|d}n�|d}d&|d'|d(|d)|d*|d+|d,|d-}d.|d/|d0|d1|d2|d3|d4|d}||}|dk�r�| }|||S)5N��?g333333�?g��Q��?g^�}o)��@g�E.k�R�@g ��Ul�@g*u��>l�@g�N����@g��"]Ξ@gnC���`@gu�� @giK��~j�@gv��|E�@g��d�|1�@gfR��r��@g��u.2�@g����~y�@g�n8(E@��?�g@g�������?g鬷�ZaI?gg�El�D�?g7\�����?g�uS�S�?g�=�. @gj%b�@g���Hw�@gjR��e��?g�9dh? >g('߿��A?g��~z �?g@�3��?gɅ3��?g3fR�x��?gI�F��l@g����t��>g*�Y��n�>gESB\T?g�N;A+�?g�UR1���?gE�F���?gP�n��@g&�>���@g����i�g�tcI,\�>g�ŝ���I?g*F2�v�?g�C4��?g��O�1�?)rrr)�pr��sigma�q�r�numZdenrCr&r&r'�_normal_dist_inv_cdf7sd  ���������������������������  �������������������������� �������������������������� r�)r�c@seZdZddd�Zd9dd�Zedd ��Zd d �d d �Zdd�Zdd�Z dd�Z d:dd�Z dd�Z dd�Z edd��Zedd��Zedd ��Zed!d"��Zed#d$��Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�ZeZd1d2�ZeZd3d4�Zd5d6�Zd7d8�Zd S);rz(Arithmetic mean of a normal distributionz+Standard deviation of a normal distribution)�_mu�_sigmar�r�cCs(|dkrtd��t|�|_t|�|_dS)Nr�zsigma must be non-negative)rrGr�r�)�selfr�r�r&r&r'�__init__�s zNormalDist.__init__cCs.t|ttf�st|�}t|�}||t||��Sr))rdr^�tuplerr)�clsr8r�r&r&r'� from_samples�szNormalDist.from_samplesN)�seedcsB|durtjn t�|�j�|j|j�����fdd�t|�D�S)Ncsg|]}�����qSr&r&�r*rU��gaussr�r�r&r'� �r.z&NormalDist.samples..)�randomr��Randomr�r�r})r�r,r�r&r�r'�samples�szNormalDist.samplescCs<|jd}|std��t||jdd|�tt|�S)N�@z$pdf() not defined when sigma is zerog�)r�rrr�rr)r�rCrr&r&r'�pdf�s zNormalDist.pdfcCs2|jstd��ddt||j|jtd��S)Nz$cdf() not defined when sigma is zeror�r�r�)r�rrr�r�r�rCr&r&r'�cdf�szNormalDist.cdfcCs:|dks|dkrtd��|jdkr*td��t||j|j�S)Nr�r�z$p must be in the range 0.0 < p < 1.0z-cdf() not defined when sigma at or below zero)rr�r�r�)r�r�r&r&r'�inv_cdf�s  zNormalDist.inv_cdfrzcs��fdd�td��D�S)Ncsg|]}��|���qSr&)r�r��r,r�r&r'r��r.z(NormalDist.quantiles..r()r})r�r,r&r�r'r�s zNormalDist.quantilesc Cst|t�std��||}}|j|jf|j|jfkr>||}}|j|j}}|rT|s\td��||}t|j|j�}|s�dt|d|jt d��S|j||j|}|j|jt |d|t ||��} || |} || |} dt|� | �|� | ��t|� | �|� | ��S)Nz$Expected another NormalDist instancez(overlap() not defined when sigma is zeror�r�) rdrrHr�r�rrrrrrr�) r��other�X�YZX_varZY_varZdvZdmrT�b�x1�x2r&r&r'�overlap�s"   (  zNormalDist.overlapcCs|jstd��||j|jS)Nz'zscore() not defined when sigma is zero)r�rr�r�r&r&r'�zscore�szNormalDist.zscorecCs|jSr)�r��r�r&r&r'r�szNormalDist.meancCs|jSr)r�r�r&r&r'rszNormalDist.mediancCs|jSr)r�r�r&r&r'r szNormalDist.modecCs|jSr)�r�r�r&r&r'rszNormalDist.stdevcCs |jdS)Nr�r�r�r&r&r'rszNormalDist.variancecCs8t|t�r&t|j|jt|j|j��St|j||j�Sr)�rdrr�rr��r�r�r&r&r'�__add__s zNormalDist.__add__cCs8t|t�r&t|j|jt|j|j��St|j||j�Sr)r�r�r&r&r'�__sub__'s zNormalDist.__sub__cCst|j||jt|��Sr)�rr�r�rr�r&r&r'�__mul__5szNormalDist.__mul__cCst|j||jt|��Sr)r�r�r&r&r'� __truediv__=szNormalDist.__truediv__cCst|j|j�Sr)�rr�r��r�r&r&r'�__pos__EszNormalDist.__pos__cCst|j |j�Sr)r�r�r&r&r'�__neg__IszNormalDist.__neg__cCs || Sr)r&r�r&r&r'�__rsub__OszNormalDist.__rsub__cCs&t|t�stS|j|jko$|j|jkSr))rdr�NotImplementedr�r�r�r&r&r'�__eq__Us zNormalDist.__eq__cCst|j|jf�Sr))�hashr�r�r�r&r&r'�__hash__[szNormalDist.__hash__cCs t|�j�d|j�d|j�d�S)Nz(mu=z, sigma=�))r3r#r�r�r�r&r&r'�__repr___szNormalDist.__repr__)r�r�)rz) r#r$r%� __slots__r�� classmethodr�r�r�r�r�rr�r��propertyrrr rrr�r�r�r�r�r��__radd__r��__rmul__r�r�r�r&r&r&r'r�sF�   "      r)r)rZ)r()N)N)N)N)N)7�__all__rArer�Z fractionsrZdecimalr� itertoolsr�bisectrrrrrrrrrr �operatorr!� collectionsr"rOrr?rDr1r/rRrVrYr\rrrrrr r rr r rr�rrrr r�Z _statistics� ImportErrorrr&r&r&r'�SsR   (   :  / 778  / ,  K