Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
statistics.cpython-314.pyc933 linesDownload Raw Back to __pycache__
1+
2��i&���Za�R`th0tRt.RaOt^RIt^RIt^RIt^RIt^RIHt^RI	H3t4^RIHtH
t
Ht^RIHtHt^RIHtHtHtHtHtHtHtHtHt^R	IHtHtHtHtHtH t H!t!H"t"H#t#H$t$^R5I%H&t&^RI'H(t(^RI)H*t*H+t+H,t,]!R
4t-]t.!RR]/4t0Rt1RbRlt2Rt3RbRlt4Rt5Rt6Rt7RcRlt8Rt9Rt:RbRlt;RbRlt<RbRlt=RbRlt>Rt?RR/R lt@]+!R!Rd4tAR"R#/R$ltB/tCR%tD]D!R&R'4R(4tE]D!R)4R*4tF]D!R+4R,4tG]D!R-R.4R/4tH]D!R04R14tI]D!R2R34R44tJReR5ltKR6tL]D!R7R84R94tMR:tN]D!R;4R<4tO]D!R=4R>4tPADAEAFAGAHAIAJAMAOAPRfR?R#/R@lltQRfRAR/RBlltRRC^RRD/REltS!RFR4tTRGtURbRHltVRItWRJtXRKtYRLtZRgRMlt[RNRROR#RPRQRR^/RSRTllt\RURVlt]^]P�P�,^,t`]^kRWRXltaRYRZltbR[tcR\R]ltdR^te^R_IfHeteR# ]gdR#i;i)ha�
6Basic statistics module.7 8This module provides functions for calculating statistics of data, including9averages, variance, and standard deviation.10 11Calculating averages12--------------------13 14==================  ==================================================15Function            Description16==================  ==================================================17mean                Arithmetic mean (average) of data.18fmean               Fast, floating-point arithmetic mean.19geometric_mean      Geometric mean of data.20harmonic_mean       Harmonic mean of data.21median              Median (middle value) of data.22median_low          Low median of data.23median_high         High median of data.24median_grouped      Median, or 50th percentile, of grouped data.25mode                Mode (most common value) of data.26multimode           List of modes (most common values of data).27quantiles           Divide data into intervals with equal probability.28==================  ==================================================29 30Calculate the arithmetic mean ("the average") of data:31 32>>> mean([-1.0, 2.5, 3.25, 5.75])332.62534 35 36Calculate the standard median of discrete data:37 38>>> median([2, 3, 4, 5])393.540 41 42Calculate the median, or 50th percentile, of data grouped into class intervals43centred on the data values provided. E.g. if your data points are rounded to44the nearest whole number:45 46>>> median_grouped([2, 2, 3, 3, 3, 4])  #doctest: +ELLIPSIS472.8333333333...48 49This should be interpreted in this way: you have two data points in the class50interval 1.5-2.5, three data points in the class interval 2.5-3.5, and one in51the class interval 3.5-4.5. The median of these data points is 2.8333...52 53 54Calculating variability or spread55---------------------------------56 57==================  =============================================58Function            Description59==================  =============================================60pvariance           Population variance of data.61variance            Sample variance of data.62pstdev              Population standard deviation of data.63stdev               Sample standard deviation of data.64==================  =============================================65 66Calculate the standard deviation of sample data:67 68>>> stdev([2.5, 3.25, 5.5, 11.25, 11.75])  #doctest: +ELLIPSIS694.38961843444...70 71If you have previously calculated the mean, you can pass it as the optional72second argument to the four "spread" functions to avoid recalculating it:73 74>>> data = [1, 2, 2, 4, 4, 4, 5, 6]75>>> mu = mean(data)76>>> pvariance(data, mu)772.578 79 80Statistics for relations between two inputs81-------------------------------------------82 83==================  ====================================================84Function            Description85==================  ====================================================86covariance          Sample covariance for two variables.87correlation         Pearson's correlation coefficient for two variables.88linear_regression   Intercept and slope for simple linear regression.89==================  ====================================================90 91Calculate covariance, Pearson's correlation, and simple linear regression92for two inputs:93 94>>> x = [1, 2, 3, 4, 5, 6, 7, 8, 9]95>>> y = [1, 2, 3, 1, 2, 3, 1, 2, 3]96>>> covariance(x, y)970.7598>>> correlation(x, y)  #doctest: +ELLIPSIS990.31622776601...100>>> linear_regression(x, y)  #doctest:101LinearRegression(slope=0.1, intercept=1.5)102 103 104Exceptions105----------106 107A single exception is defined: StatisticsError is a subclass of ValueError.108 109�110NormalDist�StatisticsErrorN��Fraction)�Decimal)�count�groupby�repeat)�bisect_left�bisect_right)	�hypot�sqrt�fabs�exp�erfc�tau�log�fsum�sumprod)111�isfinite�isinf�pi�cos�sin�tan�cosh�asin�atan�acos)�reduce)�112itemgetter)�Counter�113namedtuple�defaultdict�@c��]tRt^�tRtR#)r�N)�__name__�114__module__�__qualname__�__firstlineno__�__static_attributes__r&��Lib\statistics.pyrr�s��r,c�f�\V4wrpV^8d\R4h\W#,V4#)a\Return the sample arithmetic mean of data.115 116>>> mean([1, 2, 3, 4, 4])1172.8118 119>>> from fractions import Fraction as F120>>> mean([F(3, 7), F(1, 21), F(5, 3), F(1, 3)])121Fraction(13, 21)122 123>>> from decimal import Decimal as D124>>> mean([D("0.5"), D("0.75"), D("0.625"), D("0.375")])125Decimal('0.5625')126 127If ``data`` is empty, StatisticsError will be raised.128 129z%mean requires at least one data point)�_sumr�_convert)�data�T�total�ns&   r-�meanr5�s3��"�t�*�K�A�a��1�u��E�F�F��E�I�q�!�!r,c130���Vf3\V4p\V4pV'g\R4hW2,#\V\\34'g\V4p\W4p\T4pT'g\R4hYV,# \d@\4p\\	\^4\
Y444p\T4pL�i;i \d
\R4hi;i)z�Convert data to floats and compute the arithmetic mean.131 132This runs faster than the mean() function and it always returns a float.133If the input dataset is empty, it raises a StatisticsError.134 135>>> fmean([3.5, 4.0, 5.25])1364.25137 138z&fmean requires at least one data pointz(data and weights must be the same lengthzsum of weights must be non-zero)�lenr�	TypeErrorr�mapr �zip�nextr�139isinstance�list�tupler�140ValueError)r1�weightsr4r3�counter�num�dens&&     r-�fmeanrD�s�����	��D�	�A���J�E��!�"J�K�K��y���g��e�}�-�-��w�-��J��d�$���w�-�C���?�@�@��9���5�	��g�G���Z��]�C��,>�?�@�E��W�
�A�		��$�J��H�I�I�J�s�B�C�AC�C�C4c�Zaa�^oRoVV3Rlp\\\V!V444pS'g\R4h\P141!V4'd\P#S'd(V\P8Xd\P#R#\VS,4#)aVConvert data to floats and compute the geometric mean.142 143Raises a StatisticsError if the input dataset is empty144or if it contains a negative value.145 146Returns zero if the product of inputs is zero.147 148No special efforts are made to achieve exact results.149(However, this may change in the future.)150 151>>> round(geometric_mean([54, 24, 36]), 9)15236.0153 154Fc3�<"�\V^R7FDwopVR8�g\P!V4'dVx�K/VR8XdRoK:\RV4h	R#5i)���start�TzNo negative inputs allowedN)�	enumerate�math�isnanr)�iterable�x�155found_zeror4s& ��r-�count_positive�&geometric_mean.<locals>.count_positive�sM�����h�a�0�D�A�q��3�w�$�*�*�Q�-�-����c��!�156�%�&B�A�F�F�
1�s157�6A�!AzMust have a non-empty datasetrJ)	rr9rrrLrM�nan�infr)r1rQr3rPr4s&  @@r-�geometric_meanrU�s���	158�A��J�G�
��S�.��.�/�0�E���=�>�>��z�z�%����x�x��� �D�H�H�,�t�x�x�5�#�5��u�q�y�>�r,c��\V4VJd\V4pRp\V4pV^8d\R4hV^8XdSVfOV^,p\	V\159P\34'dV^8d\V4hV#\R4hVf\^V4pTpMS\V4VJd\V4p\V4V8wd\R4h\R\W444wrep\W4p\R\W444wrxp	T^8:d\R4h\YX,T4# \d^#i;i)a�Return the harmonic mean of data.160 161The harmonic mean is the reciprocal of the arithmetic mean of the162reciprocals of the data.  It can be used for averaging ratios or163rates, for example speeds.164 165Suppose a car travels 40 km/hr for 5 km and then speeds-up to16660 km/hr for another 5 km. What is the average speed?167 168    >>> harmonic_mean([40, 60])169    48.0170 171Suppose a car travels 40 km/hr for 5 km, and when traffic clears,172speeds-up to 60 km/hr for the remaining 30 km of the journey. What173is the average speed?174 175    >>> harmonic_mean([40, 60], weights=[5, 30])176    56.0177 178If ``data`` is empty, or any element is less than zero,179``harmonic_mean`` will raise ``StatisticsError``.180 181z.harmonic mean does not support negative valuesz.harmonic_mean requires at least one data pointzunsupported typez*Number of weights does not match data sizec3�$"�TFqx�K	R#5i�Nr&)�.0�ws& r-�	<genexpr>� harmonic_mean.<locals>.<genexpr>9s��� G�,F�q��,F�s�c3�J"�TFwrV'd	W,M^x�K	R#5i)�Nr&)rYrZrOs&  r-r[r\=s���P�=O�T�Q��q�u�q�0�=O���!#zWeighted sum must be positive)�iterr=r7rr<�numbers�Realrr8r	r/�	_fail_negr:�ZeroDivisionErrorr0)182r1r@�errmsgr4rO�sum_weights�_r2r3rs183&&        r-�
harmonic_meanrhsD��0�D�z�T���D�z��
=�F��D�	�A��1�u��N�O�O�	184�a��G�O���G���a�'�,�,��0�1�1��1�u�%�f�-�-��H��.�/�/�����A�,������=�G�#��7�m�G��w�<�1��!�"N�O�O� � G�I�g�,F� G�G�������&���P�S��=O�P�P���%�
��z��=�>�>��K�'��+�+��
����s�:)E�E�Ec���\V4p\V4pV^8Xd\R4hV^,^8XdW^,,#V^,pW^,185,W,,^,#)a"Return the median (middle value) of numeric data.186 187When the number of data points is odd, return the middle data point.188When the number of data points is even, the median is interpolated by189taking the average of the two middle values:190 191>>> median([1, 3, 5])1923193>>> median([1, 3, 5, 7])1944.0195 196�no median for empty data��sortedr7r)r1r4�is&  r-�medianrnGsa���$�<�D��D�	�A��A�v��8�9�9��1�u��z���F�|��
��F����U��d�g�%��*�*r,c��\V4p\V4pV^8Xd\R4hV^,^8XdW^,,#W^,^,197,#)z�Return the low median of numeric data.198 199When the number of data points is odd, the middle value is returned.200When it is even, the smaller of the two middle values is returned.201 202>>> median_low([1, 3, 5])2033204>>> median_low([1, 3, 5, 7])2053206 207rjrk�r1r4s& r-�208median_lowrq_sQ���$�<�D��D�	�A��A�v��8�9�9��1�u��z���F�|����F�Q�J��r,c�p�\V4p\V4pV^8Xd\R4hW^,,#)z�Return the high median of data.209 210When the number of data points is odd, the middle value is returned.211When it is even, the larger of the two middle values is returned.212 213>>> median_high([1, 3, 5])2143215>>> median_high([1, 3, 5, 7])2165217 218rjrkrps& r-�median_highrsxs5���$�<�D��D�	�A��A�v��8�9�9��Q��<�r,c�~�\V4p\V4pV'g\R4hW^,,p\W4p\	WVR7p\V4p\V4pY1R,,219pTpYT,220pYaT^,T,221,T,,# \d
\R4hi;i)aEstimates the median for numeric data binned around the midpoints222of consecutive, fixed-width intervals.223 224The *data* can be any iterable of numeric data with each value being225exactly the midpoint of a bin.  At least one value must be present.226 227The *interval* is width of each bin.228 229For example, demographic information may have been summarized into230consecutive ten-year age groups with each group being represented231by the 5-year midpoints of the intervals:232 233    >>> demographics = Counter({234    ...    25: 172,   # 20 to 30 years old235    ...    35: 484,   # 30 to 40 years old236    ...    45: 387,   # 40 to 50 years old237    ...    55:  22,   # 50 to 60 years old238    ...    65:   6,   # 60 to 70 years old239    ... })240 241The 50th percentile (median) is the 536th person out of the 1071242member cohort.  That person is in the 30 to 40 year old age group.243 244The regular median() function would assume that everyone in the245tricenarian age group was exactly 35 years old.  A more tenable246assumption is that the 484 members of that age group are evenly247distributed between 30 and 40.  For that, we use median_grouped().248 249    >>> data = list(demographics.elements())250    >>> median(data)251    35252    >>> round(median_grouped(data, interval=10), 1)253    37.5254 255The caller is responsible for making sure the data points are separated256by exact multiples of *interval*.  This is essential for getting a257correct result.  The function does not check this precondition.258 259Inputs may be any numeric type that can be coerced to a float during260the interpolation step.261 262rj)�loz$Value cannot be converted to a floatr$)rlr7rr263r�floatr?r8)	r1�intervalr4rOrm�j�L�cf�fs	&&       r-�median_groupedr|�s���V�$�<�D��D�	�A���8�9�9�	
�!�V��A�	�D��A��T��#�A�A���?���!�H��	264�s�N��A�	265�B�	��A��1�q�5�2�:�&��*�*�*���A��>�@�@�A�s�B%�%B<c��\\V44P^4pV^,^,# \d\	R4Rhi;i)aDReturn the most common data point from discrete or nominal data.266 267``mode`` assumes discrete data, and returns a single value. This is the268standard treatment of the mode as commonly taught in schools:269 270    >>> mode([1, 1, 2, 3, 3, 3, 3, 4])271    3272 273This also works with nominal (non-numeric) data:274 275    >>> mode(["red", "blue", "blue", "red", "green", "red", "red"])276    'red'277 278If there are multiple modes with same frequency, return the first one279encountered:280 281    >>> mode(['red', 'red', 'green', 'blue', 'blue'])282    'red'283 284If *data* is empty, ``mode``, raises StatisticsError.285 286zno mode for empty dataN)r!r`�most_common�287IndexErrorr)r1�pairss& r-�moder��sP��.
�D��J��+�+�A�.�E�B��Q�x��{����B��6�7�T�A�B�s	�5�A
c���\\V44pV'g.#\VP44pVP	4UUu.uFwr4WB8XgK
VNK	upp#uuppi)aReturn a list of the most frequently occurring values.288 289Will return more than one result if there are multiple modes290or an empty list if *data* is empty.291 292>>> multimode('aabbbbbbbbcc')293['b']294>>> multimode('aabbbbccddddeeffffgg')295['b', 'd', 'f']296>>> multimode('')297[]298 299)r!r`�max�values�items)r1�counts�maxcount�valuers&    r-�	multimoder��sQ���T�$�Z�
 �F���	��6�=�=�?�#�H�&,�l�l�n�J�n�l�e��8I�E�E�n�J�J��Js�300A$�A$c�t�\W4wr#rEV^8d\R4h\W5^,301,V4#)a^Return the sample variance of data.302 303data should be an iterable of Real-valued numbers, with at least two304values. The optional argument xbar, if given, should be the mean of305the data. If it is missing or None, the mean is automatically calculated.306 307Use this function when your data is a sample from a population. To308calculate the variance from the entire population, see ``pvariance``.309 310Examples:311 312>>> data = [2.75, 1.75, 1.25, 0.25, 0.5, 1.25, 3.5]313>>> variance(data)3141.3720238095238095315 316If you have already calculated the mean of your data, you can pass it as317the optional second argument ``xbar`` to avoid recalculating it:318 319>>> m = mean(data)320>>> variance(data, m)3211.3720238095238095322 323This function does not check that ``xbar`` is actually the mean of324``data``. Giving arbitrary values for ``xbar`` may lead to invalid or325impossible results.326 327Decimals and Fractions are supported:328 329>>> from decimal import Decimal as D330>>> variance([D("27.5"), D("30.25"), D("30.25"), D("34.5"), D("41.75")])331Decimal('31.01875')332 333>>> from fractions import Fraction as F334>>> variance([F(1, 6), F(1, 2), F(5, 3)])335Fraction(67, 108)336 337z*variance requires at least two data points��_ssrr0)r1�xbarr2�ss�cr4s&&    r-�variancer�s8��P�d�/�K�A�1��1�u��J�K�K��B�a�%�L�!�$�$r,c�f�\W4wr#rEV^8d\R4h\W5,V4#)a�Return the population variance of ``data``.338 339data should be a sequence or iterable of Real-valued numbers, with at least one340value. The optional argument mu, if given, should be the mean of341the data. If it is missing or None, the mean is automatically calculated.342 343Use this function to calculate the variance from the entire population.344To estimate the variance from a sample, the ``variance`` function is345usually a better choice.346 347Examples:348 349>>> data = [0.0, 0.25, 0.25, 1.25, 1.5, 1.75, 2.75, 3.25]350>>> pvariance(data)3511.25352 353If you have already calculated the mean of the data, you can pass it as354the optional second argument to avoid recalculating it:355 356>>> mu = mean(data)357>>> pvariance(data, mu)3581.25359 360Decimals and Fractions are supported:361 362>>> from decimal import Decimal as D363>>> pvariance([D("27.5"), D("30.25"), D("30.25"), D("34.5"), D("41.75")])364Decimal('24.815')365 366>>> from fractions import Fraction as F367>>> pvariance([F(1, 4), F(5, 4), F(1, 2)])368Fraction(13, 72)369 370z*pvariance requires at least one data pointr�)r1�mur2r�r�r4s&&    r-�	pvariancer�6s4��J�d�-�K�A�1��1�u��J�K�K��B�F�A��r,c��\W4wr#rEV^8d\R4hW5^,371,pVPpVPp\
T\4'd\Yx4#\Yx4# \d
\R4hi;i)z�Return the square root of the sample variance.372 373See ``variance`` for arguments and other details.374 375>>> stdev([1.5, 2.5, 2.5, 2.75, 3.25, 4.75])3761.0810874155219827377 378�'stdev requires at least two data points�inf or nan encountered in data�379r�r�	numerator�denominator�AttributeErrorr?�380issubclassr�_decimal_sqrt_of_frac�_float_sqrt_of_frac)	r1r�r2r�r�r4�mss�
mss_numerator�mss_denominators	&&       r-�stdevr�as����d�/�K�A�1��1�u��G�H�H�381�A��,�C�;��
�
�
��/�/���!�W���$�]�D�D��}�>�>��	�;��9�:�:�;�s�A5�5Bc��\W4wr#rEV^8d\R4hW5,pVPpVPp\
T\4'd\Yx4#\Yx4# \d
\R4hi;i)z�Return the square root of the population variance.382 383See ``pvariance`` for arguments and other details.384 385>>> pstdev([1.5, 2.5, 2.5, 2.75, 3.25, 4.75])3860.986893273527251387 388z'pstdev requires at least one data pointr�r�)	r1r�r2r�r�r4r�r�r�s	&&       r-�pstdevr�xs����d�-�K�A�1��1�u��G�H�H�389�&�C�;��
�
�
��/�/���!�W���$�]�D�D��}�>�>��	�;��9�:�:�;�s�A.�.Bc�aa�\V4p\V4V8wd\R4hV^8d\R4h\V4V,o\V4V,o\V3RlV4V3RlV44pW2^,390,#)a@Covariance391 392Return the sample covariance of two inputs *x* and *y*. Covariance393is a measure of the joint variability of two inputs.394 395>>> x = [1, 2, 3, 4, 5, 6, 7, 8, 9]396>>> y = [1, 2, 3, 1, 2, 3, 1, 2, 3]397>>> covariance(x, y)3980.75399>>> z = [9, 8, 7, 6, 5, 4, 3, 2, 1]400>>> covariance(x, z)401-7.5402>>> covariance(z, x)403-7.5404 405zDcovariance requires that both inputs have same number of data pointsz,covariance requires at least two data pointsc3�4<"�TF
qS,406x�K	R#5irXr&)rY�xir�s& �r-r[�covariance.<locals>.<genexpr>�s����)�q���9�9�q���c3�4<"�TF
qS,407x�K	R#5irXr&�rY�yi�ybars& �r-r[r��s����+B��"��I�I��r�)r7rrr)rO�yr4�sxyr�r�s""  @@r-�408covariancer��sv���$	�A��A�409�1�v��{��d�e�e��1�u��L�M�M���7�Q�;�D���7�Q�;�D�410�)�q�)�+B��+B�411C�C��a�%�=�r,�method�linearc�R�\V4p\V4V8wd\R4hV^8d\R4hVR9d\RV:24hVR8Xd*V^,412R,p\WR7p\WR7pMR\	V4V,p\	V4V,pVUu.uFqwV,413NK
	ppVUu.uFq�V,414NK
	pp\W4p	\W4p415\W4pV	\
W�4,#uupiuupi \d
\R4hi;i)	a)Pearson's correlation coefficient416 417Return the Pearson's correlation coefficient for two inputs. Pearson's418correlation coefficient *r* takes values between -1 and +1. It measures419the strength and direction of a linear relationship.420 421>>> x = [1, 2, 3, 4, 5, 6, 7, 8, 9]422>>> y = [9, 8, 7, 6, 5, 4, 3, 2, 1]423>>> correlation(x, x)4241.0425>>> correlation(x, y)426-1.0427 428If *method* is "ranked", computes Spearman's rank correlation coefficient429for two inputs.  The data is replaced by ranks.  Ties are averaged430so that equal values receive the same rank.  The resulting coefficient431measures the strength of a monotonic relationship.432 433Spearman's rank correlation coefficient is appropriate for ordinal434data or for continuous data that doesn't meet the linear proportion435requirement for Pearson's correlation coefficient.436 437zEcorrelation requires that both inputs have same number of data pointsz-correlation requires at least two data points�ranked�Unknown method: rHz&at least one of the inputs is constant>r�r������)r7rr?�_rankrr�	_sqrtprodrd)rOr�r�r4rIr�r�r�r�r��sxx�syys""$         r-�correlationr��s ��4	�A��A�438�1�v��{��e�f�f��1�u��M�N�N�
�)�)��+�F�:�6�7�7�
����Q��"����!�!���!�!���A�w��{���A�w��{��!"�#��2�$�Y�Y���#�!"�#��2�$�Y�Y���#�439�!�-�C�440�!�-�C�441�!�-�C�H��Y�s�(�(�(��
$��#���H��F�G�G�H�s�'D�>D442�3D�D&�LinearRegression�proportionalFc��a443�\V4p\V4V8wd\R4hV^8d\R4hV'gH\V4V,p\V4V,o444VUu.uFqUV,445NK
	ppV4463RlV4p\W4R,p\W4pWg,pT'dRMS447TX,,448p	\Y�R7#uupi \d
\R4hi;i)aOSlope and intercept for simple linear regression.449 450Return the slope and intercept of simple linear regression451parameters estimated using ordinary least squares. Simple linear452regression describes relationship between an independent variable453*x* and a dependent variable *y* in terms of a linear function:454 455    y = slope * x + intercept + noise456 457where *slope* and *intercept* are the regression parameters that are458estimated, and noise represents the variability of the data that was459not explained by the linear regression (it is equal to the460difference between predicted and actual values of the dependent461variable).462 463The parameters are returned as a named tuple.464 465>>> x = [1, 2, 3, 4, 5]466>>> noise = NormalDist().samples(5, seed=42)467>>> y = [3 * x[i] + 2 + noise[i] for i in range(5)]468>>> linear_regression(x, y)  #doctest: +ELLIPSIS469LinearRegression(slope=3.17495..., intercept=1.00925...)470 471If *proportional* is true, the independent variable *x* and the472dependent variable *y* are assumed to be directly proportional.473The data is fit to a line passing through the origin.474 475Since the *intercept* will always be 0.0, the underlying linear476function simplifies to:477 478    y = slope * x + noise479 480>>> y = [3 * x[i] + noise[i] for i in range(5)]481>>> linear_regression(x, y, proportional=True)  #doctest: +ELLIPSIS482LinearRegression(slope=2.90475..., intercept=0.0)483 484zKlinear regression requires that both inputs have same number of data pointsz3linear regression requires at least two data pointsc3�4<"�TF
qS,485x�K	R#5irXr&r�s& �r-r[�$linear_regression.<locals>.<genexpr>s����#��2�$�Y�Y��r�rJz
x is constant��slope�	intercept)r7rrrrdr�)rOr�r�r4r�r�r�r�r�r�r�s""$       @r-�linear_regressionr��s����N	�A��A�486�1�v��{��k�l�l��1�u��S�T�T���A�w��{���A�w��{��!"�#��2�$�Y�Y���#�#��#��487�!�-�#�488�C�489�!�-�C�/��	��$������)<�I��%�=�=��
$���/��o�.�.�/�s�*C�'C�C1c�a�V3RlpV#)zCLoad the kernel's pdf, cdf, invcdf, and support into _kernel_specs.c�`<�\\RV!444pSFpV\V&K	V#)�pdf�r��cdf�invcdf�support)�dictr:�
_kernel_specs)�builder�spec�kernel�kernelss&  �r-�deco�register.<locals>.deco-s0����C�;�W�Y�G�H���F�$(�M�&�!���r,r&)r�r�sj r-�registerr�+s����490�Kr,�normal�gaussc�taa�\^\,4o\^4)oV3RlpV3RlpRpRpWW#3#)�c�D<�\RV,V,4S,#)rG�࿩r)�t�sqrt2pis&�r-�<lambda>�normal_kernel.<locals>.<lambda>8s���C��q��1��%��/r,c�6<�R\VS,4,#�rG��?)r)r��	neg_sqrt2s&�r-r�r�9s���C�$�q�9�}�-�-r,c��\VRR4#�rJ��?��_normal_dist_inv_cdf�r�s&r-r�r�:s��+�A�s�C�8r,N)r
r)r�r�r�r�r�r�s    @@r-�
normal_kernelr�4s:����1�r�6�l�G��a���I�491/�C�492-�C�
8�F��G��V�$�$r,�logisticc� �RpRpRpRpWW#3#)c�4�RR\V4,,#)rGr�r��rr�s&r-r��!logistic_kernel.<locals>.<lambda>As��C�3��a��=�)r,c�B�RR\V4R,,,493#�r�r�r�s&r-r�r�Bs��C�#��Q��#��.�.r,c�4�\VRV,494,4#r�)r��ps&r-r�r�Cs��s�1��a��=�)r,Nr&r�s    r-�logistic_kernelr�>s#��*�C�495.�C�
)�F��G��V�$�$r,�sigmoidc�aaa�^\,o^\,o\^,oV3RlpV3RlpV3RlpRpWW#3#)rGc�(<�S\V4,#rXr�)r��c1s&�r-r�� sigmoid_kernel.<locals>.<lambda>Ms
���B��a��Lr,c�:<�S\\V44,#rX)rr�r��c2s&�r-r�r�Ns���B��c�!�f��%r,c�:<�\\VS,44#rX)rr)r��c3s&�r-r�r�Os���s�3�q�2�v�;�'r,N�r)r�r�r�r�r�r�r�s    @@@r-�sigmoid_kernelrGs?���496�R��B�	497�R��B�	�a��B�498 �C�499%�C�
'�F��G��V�$�$r,�rectangular�uniformc� �RpRpRpRpWW#3#)c��R#r�r&r�s&r-r��$rectangular_kernel.<locals>.<lambda>Us��Cr,c�"�RV,R,#r�r&r�s&r-r�rVs��C�!�G�c�Mr,c�"�RV,R,500#�r$r�r&r�s&r-r�rWs��s�Q�w��}r,r�r&r�s    r-�rectangular_kernelr	Ss!��501�C�502!�C�
$�F��G��V�$�$r,�503triangularc� �RpRpRpRpWW#3#)c�&�R\V4,504#r���absr�s&r-r��#triangular_kernel.<locals>.<lambda>]s��C�#�a�&�Lr,c�N�W,VR8dRMR,V,R,#)rJr�r�r&r�s&r-r�r^s��A�C�!�c�'�3�t�4�q�8�3�>r,c��VR8d\RV,4R,505#R\RRV,,5064,507#)rGr$r�r�)r
r�s&r-r�r_s1��A��G�t�C��E�{�S�(�P��t�C�#�a�%�K�?P�9P�Pr,r�r&r�s    r-�triangular_kernelr[s!��508 �C�509>�C�
P�F��G��V�$�$r,�	parabolic�epanechnikovc� �RpRpRpRpWW#3#)c�.�RRW,,510,#)�r���?r&r�s&r-r��"parabolic_kernel.<locals>.<lambda>es��C�3���;�'r,c�.�\RV^,VR34#)rGr�)gпrr��rr�s&r-r�rfs��G�,�q�!�t�Q��n�=r,c�x�R\\RV,R,5114\,R,4,#)r$r�g@)rrrr�s&r-r�rgs%��s�S�$�s�1�u�s�{�"3�b�"8�C�!?�@�@r,r�r&r�s    r-�parabolic_kernelrcs!��512'�C�513=�C�
@�F��G��V�$�$r,c� aaaa�VVVV3RlpV#)c�<�S!V4p\S!V4V,514;p4S8�dWS!V4,,pK6V#)u=Return x such that f(x) ≈ y within the specified tolerance.r
)r�rO�diffr{�f_inv_estimate�f_prime�	tolerances&  ����r-�f_inv�_newton_raphson.<locals>.f_invls=����1����!�A�$��(�"�$�#�i�/�
���515�"�"�A��r,r&)r!r{r"r#r$sffff r-�_newton_raphsonr&ks������Lr,c��VR5168:dRV3M517RRV,5183wrVR8dRV,R,R,519V,#RV,R,R,520pVR8d(VR\RV,R	,4,,
pW!,#)rGr�g�g��s��?r$gq
�-��?g��鼹A�?�V-����?gM�p�^v�?g��$2h@g_���@r���r�r��signrOs&  r-�_quartic_invcdf_estimater-ts|���s�(�s�A�h��s�Q�w��G�D��6�z��q��V�#�c�)�T�1�1�	�q��_�$�s�*�A��5�y�	�[�3�{�Q��1A�A�B�
B�B���8�Or,�quartic�biweightc�<�RpRp\\WR7pRpWW#3#)c�<�RRW,,521^,,#)�r���?r&r�s&r-r�� quartic_kernel.<locals>.<lambda>����E�S�1�5�[�Q�.�.r,c�>�\RV^,V^,VR34#)rr�)g�?g�r3r�rr�s&r-r�r4�s ��G�4���T�1�a�4��C�0�2r,�r{r"r�)r&r-r�s    r-�quartic_kernelr8~s+��522.�C�2�C�
�5��
J�F��G��V�$�$r,c��VR	8:dRV3M523R524RV,5253wrRV,R,R,526pRTu;8dR8d=M	W!,#VR\R\,VR,527,4,,pW!,#)rGr�r$g�c���?g�h㈵��>r(gL7�A`�?g��Q��?g�Q���?r�r))rrr+s&  r-�_triweight_invcdf_estimater:�so���s�(�s�A�h��s�Q�w��G�D�	�q��'�'�#�-�A����U���8�O�	528�U�S����q�5�y�1�2�
2�2���8�Or,�	triweightc�<�RpRp\\WR7pRpWW#3#)c�<�RRW,,529^,,#)�#r����?r&r�s&r-r��"triweight_kernel.<locals>.<lambda>�r5r,c�N�\RV^,V^,V^,VR34#)�r�)gĿg�?g��r?r�rr�s&r-r�r@�s&��G�>���T�1�a�4��A��q�#�6�8r,r7r�)r&r:r�s    r-�triweight_kernelrC�s+��530.�C�8�C�
�7�3�
L�F��G��V�$�$r,�cosinec�faa�\^,o\^,oVV3RlpV3RlpRpRpWW#3#)�c�6<�S\SV,4,#rX)r)r�r�r�s&��r-r��cosine_kernel.<locals>.<lambda>�s���B��R�!�V��$r,c�D<�R\SV,4,R,#r�r*r�s&�r-r�rH�s���C�#�b�1�f�+�%��+r,c�X�R\RV,R,5314,\,#r)rrr�s&r-r�rH�s��s�T�#��'�C�-�0�0�2�5r,r�r�)r�r�r�r�r�r�s    @@r-�
cosine_kernelrK�s4���	�a��B�	�a��B�532$�C�533+�C�
5�F��G��V�$�$r,�534cumulativec�,aaaa	a535aa�\S4oS'g\R4h\S^,\\34'g\R4hSR8:d\RS:24h\PV4pVf\RV:24hVR,oVR,o	VR,pVfVVV3R	lpV	VV3R536lpM*\S4oSV,o537VV538VVVV3RlpV	V539VVVV3RlpV'dR
S:RV:2Vn	V#RS:RV:2Vn	V#)a�Kernel Density Estimation:  Create a continuous probability density540function or cumulative distribution function from discrete samples.541 542The basic idea is to smooth the data using a kernel function543to help draw inferences about a population from a sample.544 545The degree of smoothing is controlled by the scaling parameter h546which is called the bandwidth.  Smaller values emphasize local547features while larger values give smoother results.548 549The kernel determines the relative weights of the sample data550points.  Generally, the choice of kernel shape does not matter551as much as the more influential bandwidth smoothing parameter.552 553Kernels that give some weight to every sample point:554 555   normal (gauss)556   logistic557   sigmoid558 559Kernels that only give weight to sample points within560the bandwidth:561 562   rectangular (uniform)563   triangular564   parabolic (epanechnikov)565   quartic (biweight)566   triweight567   cosine568 569If *cumulative* is true, will return a cumulative distribution function.570 571A StatisticsError will be raised if the data sequence is empty.572 573Example574-------575 576Given a sample of six data points, construct a continuous577function that estimates the underlying probability density:578 579    >>> sample = [-2.1, -1.3, -0.4, 1.9, 5.1, 6.2]580    >>> f_hat = kde(sample, h=1.5)581 582Compute the area under the curve:583 584    >>> area = sum(f_hat(x) for x in range(-20, 20))585    >>> round(area, 4)586    1.0587 588Plot the estimated probability density function at589evenly spaced points from -6 to 10:590 591    >>> for x in range(-6, 11):592    ...     density = f_hat(x)593    ...     plot = ' ' * int(density * 400) + 'x'594    ...     print(f'{x:2}: {density:.3f} {plot}')595    ...596    -6: 0.002 x597    -5: 0.009    x598    -4: 0.031             x599    -3: 0.070                             x600    -2: 0.111                                             x601    -1: 0.125                                                   x602     0: 0.110                                            x603     1: 0.086                                   x604     2: 0.068                            x605     3: 0.059                        x606     4: 0.066                           x607     5: 0.082                                 x608     6: 0.082                                 x609     7: 0.058                        x610     8: 0.028            x611     9: 0.009    x612    10: 0.002 x613 614Estimate P(4.5 < X <= 7.5), the probability that a new sample value615will be between 4.5 and 7.5:616 617    >>> cdf = kde(sample, h=1.5, cumulative=True)618    >>> round(cdf(7.5) - cdf(4.5), 2)619    0.22620 621References622----------623 624Kernel density estimation and its application:625https://www.itm-conferences.org/articles/itmconf/pdf/2018/08/itmconf_sam2018_00037.pdf626 627Kernel functions in common use:628https://en.wikipedia.org/wiki/Kernel_(statistics)#kernel_functions_in_common_use629 630Interactive graphical demonstration and exploration:631https://demonstrations.wolfram.com/KernelDensityEstimation/632 633Kernel estimation of cumulative distribution function of a random variable with bounded support634https://www.econstor.eu/bitstream/10419/207829/1/10.21307_stattrans-2016-037.pdf635 636�Empty data sequence�)Data sequence must contain ints or floatsrJ�$Bandwidth h must be positive, not h=�Unknown kernel name: r�r�r�c�b<a�\VVV3RlS44\S4S,,#)c3�P<"�TFpS!SV,637S,4x�K	R#5irXr&�rY�x_i�K�hrOs& ���r-r[�#kde.<locals>.pdf.<locals>.<genexpr>�!����8�4�C�q�!�c�'�Q��'�'�4���#&��sumr7)rOrVr1rWsf���r-r��kde.<locals>.pdfs!����8�4�8�8�C��I��M�J�Jr,c�T<a�\VVV3RlS44\S4,#)c3�P<"�TFpS!SV,638S,4x�K	R#5irXr&�rYrU�WrWrOs& ���r-r[�#kde.<locals>.cdf.<locals>.<genexpr>"rYrZr[)rOrar1rWsf���r-r��kde.<locals>.cdf!s����8�4�8�8�3�t�9�D�Dr,c��<a�\S4S8wd\S4o	\S4o\S	SS,6394p\S	SS,4pS	Wp\	VVV3RlV44SS,,#)c3�P<"�TFpS!SV,640S,4x�K	R#5irXr&rTs& ���r-r[rX1s!����=�9�C�q�!�c�'�Q��'�'�9�rZ�r7rlr641rr\)642rOrmrx�	supportedrV�	bandwidthr1rWr4�samples643f   ������r-r�r])sc����4�y�A�~�������I���F�A�	�M�2�A��V�Q��]�3�A��q�
�I��=�9�=�=��Q��G�Gr,c��<a�\S4S8wd\S4o	\S4o\S	SS,6444p\S	SS,4pS	Wp\	VVV3RlV4V4S,#)c3�P<"�TFpS!SV,645S,4x�K	R#5irXr&r`s& ���r-r[rb;s!����>�I�S��1�s�7�a�-�(�(�I�rZrf)646rOrmrxrgrarhr1rWr4ris647f   ������r-r�rc3sa����4�y�A�~�������I���F�A�	�M�2�A��V�Q��]�3�A��q�
�I��>�I�>��B�Q�F�Fr,zCDF estimate with h=� and kernel=zPDF estimate with h=)648r7rr<�intrvr8r��getrl�__doc__)
r1rWr�rL�kernel_specr�r�r�rVrarhr4ris
ff&$    @@@@@r-�kderq�s���H	�D�	�A���3�4�4��d�1�g��U�|�,�,��C�D�D��C�x�� E�1�&�I�J�J��#�#�F�+�K���� 5�f�Z�@�A�A��E��A��E��A��)�$�G���	K�	E�	E�649������K�	�	H�	H�	G�	G��-�1�&�
�f�[�A����650�.�1�&�
�f�[�A����651r,�seedc��aaaa	a652�\S4pV'g\R4h\S^,\\34'g\R4hSR8:d\RS:24h\PV4pVf\RV:24hVR,o	\PV4pVPo653VPoVVVV	V6543RlpRS:R	V:2VnV#)655a<Return a function that makes a random selection from the estimated656probability density function created by kde(data, h, kernel).657 658Providing a *seed* allows reproducible selections within a single659thread.  The seed may be an integer, float, str, or bytes.660 661A StatisticsError will be raised if the *data* sequence is empty.662 663Example:664 665>>> data = [-2.1, -1.3, -0.4, 1.9, 5.1, 6.2]666>>> rand = kde_random(data, h=1.5, seed=8675309)667>>> new_selections = [rand() for i in range(10)]668>>> [round(x, 1) for x in new_selections]669[0.7, 6.2, 1.2, 6.9, 7.0, 1.8, 2.5, -0.5, -1.8, 5.6]670 671rNrOrJrPrQr�c�F<�S!S4SS!S!44,,#rXr&)�choicer1rWr��randoms�����r-�rand�kde_random.<locals>.randks����d�|�a�&���"2�2�2�2r,zRandom KDE selection with h=rl)
r7rr<rmrvr8r�rn�_random�Randomrvruro)r1rWr�rrr4rp�prngrwrur�rvsff&$    @@@r-�672kde_randomr|Fs����$	�D�	�A���3�4�4��d�1�g��U�|�,�,��C�D�D��C�x�� E�1�&�I�J�J��#�#�F�+�K���� 5�f�Z�@�A�A�
��
"�F��>�>�$��D�
�[�[�F�
�[�[�F�3�3�3��v�]�6�+�F�D�L��Kr,r4�	exclusivec�.�V^8d\R4h\V4p\V4pV^8d"V^8XdW^,673,#\R4hVR8Xd}V^,674p.p\^V4F_p\	Wd,V4wrxW,W,675,W^,,V,,V,p	VPV	4Ka	V#VR8Xd�V^,p.p\^V4F�pWd,V,pV^8d^MWs^,6768�d677V^,678MTpWd,Wq,,679pW^,680,W,681,W,V,,V,p	VPV	4K�	V#\
RV:24h)afDivide *data* into *n* continuous intervals with equal probability.682 683Returns a list of (n - 1) cut points separating the intervals.684 685Set *n* to 4 for quartiles (the default).  Set *n* to 10 for deciles.686Set *n* to 100 for percentiles which gives the 99 cuts points that687separate *data* in to 100 equal sized groups.688 689The *data* can be any iterable containing sample.690The cut points are linearly interpolated between data points.691 692If *method* is set to *inclusive*, *data* is treated as population693data.  The minimum value is treated as the 0th percentile and the694maximum value is treated as the 100th percentile.695 696zn must be at least 1z!must have at least one data point�	inclusiver}r�)rrlr7�range�divmod�appendr?)697r1r4r��ld�m�resultrmrx�delta�interpolateds698&$$       r-�	quantilesr��s\��"	�1�u��4�5�5��$�<�D�	�T��B�	�A�v�
��7��q�5�>�!��A�B�B�
�����F�����q�!��A��a�e�Q�'�H�A� �G�q�y�1�D�Q��K�%�4G�G�1�L�L��M�M�,�'���
�
�����F�����q�!��A����699�A���U���q�D���1��a�A��C�!�#�I�E� �Q��K�1�9�5���%��G�1�L�L��M�M�,�'���
�700�'��z�2�7013�3r,c� a�]tRtRtoRtRRRR/tR$Rlt]R4tR	R702/Rlt	Rt703R
tRtR%Rlt
RtRt]R4t]R4t]R4t]R4t]R4tRtRtRtRtRtRt]tRt]tRtRt R t!R!t"R"t#R#t$Vt%R704#)&ri�z(Normal distribution of a random variable�_muz(Arithmetic mean of a normal distribution�_sigmaz+Standard deviation of a normal distributionc�j�VR8d\R4h\V4Vn\V4VnR#)zDNormalDist where mu is the mean and sigma is the standard deviation.rJzsigma must be non-negativeN)rrvr�r�)�selfr��sigmas&&&r-�__init__�NormalDist.__init__�s+���3�;�!�">�?�?���9����E�l��r,c� �V!\V4!#)z5Make a normal distribution instance from sample data.)�_mean_stdev)�clsr1s&&r-�from_samples�NormalDist.from_samples�s���K��%�&�&r,rrNc���Vf\PM\P!V4Pp\pVPpVPp\RV4Uu.uFqt!V!4WV4NK	up#uupi)z=Generate *n* samples for a given mean and standard deviation.N)rvrzr�r�r�r	)r�r4rr�rnd�inv_cdfr�r�rgs&&$     r-�samples�NormalDist.samples�s^��#�|�f�m�m����t�1D�1K�1K��&��
�X�X������39�$��?�C�?�a����r�)�?�C�C��Cs�!A:c���VPVP,pV'g\R4hWP,705p\W3,RV,,4\	\706V,4,#)z4Probability density function.  P(x <= X < x+dx) / dxz$pdf() not defined when sigma is zerog�)r�rr�rr
r)r�rOr�r s&&  r-r��NormalDist.pdf�sR���;�;����,���!�"H�I�I��8�8�|���4�;�$��/�2�3�d�3��>�6J�J�Jr,c��VP'g\R4hR\VPV,707VP\,,4,#)z,Cumulative distribution function.  P(X <= x)z$cdf() not defined when sigma is zeror�)r�rrr��_SQRT2�r�rOs&&r-r��NormalDist.cdf�s=���{�{�{�!�"H�I�I��T�4�8�8�a�<�D�K�K�&�,@�A�B�B�Br,c�t�VR8:gVR8�d\R4h\WPVP4#)a#Inverse cumulative distribution function.  x : P(X <= x) = p708 709Finds the value of the random variable such that the probability of710the variable being less than or equal to that value equals the given711probability.712 713This function is also called the percent point function or quantile714function.715rJr�z$p must be in the range 0.0 < p < 1.0)rr�r�r�)r�r�s&&r-r��NormalDist.inv_cdf�s2��
��8�q�C�x�!�"H�I�I�#�A�x�x����=�=r,c�l�\^V4Uu.uFq PW!,4NK	up#uupi)aFDivide into *n* continuous intervals with equal probability.716 717Returns a list of (n - 1) cut points separating the intervals.718 719Set *n* to 4 for quartiles (the default).  Set *n* to 10 for deciles.720Set *n* to 100 for percentiles which gives the 99 cuts points that721separate the normal distribution in to 100 equal sized groups.722)r�r�)r�r4rms&& r-r��NormalDist.quantiless+��.3�1�a�[�9�[����Q�U�#�[�9�9��9s�1c	���\V\4'g\R4hYr2VPVP3VPVP38dY2r2VP723VP724rTV'd	V'g\
R4hWT,725p\VPVP,7264pV'g/\VRVP,\,,4#VPV,VPV,,727pVPVP,\Ww,V\WT,4,,4,p	W�,V,p728W�,729V,pR\VPV7304VPV7314,7324\VPV4VPV4,7334,,734#)azCompute the overlapping coefficient (OVL) between two normal distributions.735 736Measures the agreement between two normal probability distributions.737Returns a value between 0.0 and 1.0 giving the overlapping area in738the two underlying probability density functions.739 740    >>> N1 = NormalDist(2.4, 1.6)741    >>> N2 = NormalDist(3.2, 2.0)742    >>> N1.overlap(N2)743    0.8035050657330205744z$Expected another NormalDist instancez(overlap() not defined when sigma is zeror$r�)
r<rr8r�r�r�rrrr�r
rr�)r��other�X�Y�X_var�Y_var�dv�dm�a�b�x1�x2s&&          r-�overlap�NormalDist.overlapsI�� �%��,�,��B�C�C��1�
�H�H�a�e�e�����!�%�%�0�0��q��z�z�1�:�:�u��E�!�"L�M�M�
�]��
�!�%�%�!�%�%�-�
 �����c�A�H�H�n�v�5�6�7�7�
�E�E�E�M�A�E�E�E�M�)��
�H�H�q�x�x��$�r�w��c�%�-�6H�1H�'H�"I�I���e�r�\���e�r�\���d�1�5�5��9�q�u�u�R�y�0�1�D����r��Q�U�U�2�Y�9N�4O�O�P�Pr,c��VP'g\R4hWP,745VP,#)z�Compute the Standard Score.  (x - mean) / stdev746 747Describes *x* in terms of the number of standard deviations748above or below the mean of the normal distribution.749z'zscore() not defined when sigma is zero)r�rr�r�s&&r-�zscore�NormalDist.zscore3s.���{�{�{�!�"K�L�L��H�H�����+�+r,c��VP#)z+Arithmetic mean of the normal distribution.�r��r�s&r-r5�NormalDist.mean>�
���x�x�r,c��VP#)z,Return the median of the normal distributionr�r�s&r-rn�NormalDist.medianCr�r,c��VP#)z�Return the mode of the normal distribution750 751The mode is the value x where which the probability density752function (pdf) takes its maximum value.753r�r�s&r-r��NormalDist.modeHs
���x�x�r,c��VP#)z.Standard deviation of the normal distribution.�r�r�s&r-r��NormalDist.stdevQs���{�{�r,c�<�VPVP,#)z!Square of the standard deviation.r�r�s&r-r��NormalDist.varianceVs���{�{�T�[�[�(�(r,c��\V\4'dF\VPVP,\VPVP44#\VPV,VP4#)a:Add a constant or another NormalDist instance.754 755If *other* is a constant, translate mu by the constant,756leaving sigma unchanged.757 758If *other* is a NormalDist, add both the means and the variances.759Mathematically, this works only if the two distributions are760independent or if they are jointly normally distributed.761�r<rr�rr��r�r�s&&r-�__add__�NormalDist.__add__[�R���b�*�%�%��b�f�f�r�v�v�o�u�R�Y�Y��	�	�/J�K�K��"�&�&�2�+�r�y�y�1�1r,c��\V\4'dF\VPVP,762\VPVP44#\VPV,763VP4#)aCSubtract a constant or another NormalDist instance.764 765If *other* is a constant, translate by the constant mu,766leaving sigma unchanged.767 768If *other* is a NormalDist, subtract the means and add the variances.769Mathematically, this works only if the two distributions are770independent or if they are jointly normally distributed.771r�r�s&&r-�__sub__�NormalDist.__sub__ir�r,c�p�\VPV,VP\V4,4#)z�Multiply both mu and sigma by a constant.772 773Used for rescaling, perhaps to change measurement units.774Sigma is scaled with the absolute value of the constant.775�rr�r�rr�s&&r-�__mul__�NormalDist.__mul__w�&���"�&�&�2�+�r�y�y�4��8�';�<�<r,c�p�\VPV,VP\V4,4#)z�Divide both mu and sigma by a constant.776 777Used for rescaling, perhaps to change measurement units.778Sigma is scaled with the absolute value of the constant.779r�r�s&&r-�__truediv__�NormalDist.__truediv__r�r,c�B�\VPVP4#)zReturn a copy of the instance.�rr�r��r�s&r-�__pos__�NormalDist.__pos__�s���"�&�&�"�)�)�,�,r,c�D�\VP)VP4#)z(Negates mu while keeping sigma the same.r�r�s&r-�__neg__�NormalDist.__neg__�s���2�6�6�'�2�9�9�-�-r,c��W,780)#)z<Subtract a NormalDist from a constant or another NormalDist.r&r�s&&r-�__rsub__�NormalDist.__rsub__�s����z�r,c��\V\4'g\#VPVP8H;'dVPVP8H#)zFTwo NormalDist objects are equal if their mu and sigma are both equal.)r<r�NotImplementedr�r�r�s&&r-�__eq__�NormalDist.__eq__�s=���"�j�)�)�!�!��v�v�����:�:�B�I�I����$:�:r,c�D�\VPVP34#)zCNormalDist objects hash equal if their mu and sigma are both equal.)�hashr�r�r�s&r-�__hash__�NormalDist.__hash__�s���T�X�X�t�{�{�+�,�,r,c�j�\V4PRVP:RVP:R2#)z(mu=z, sigma=�))�typer'r�r�r�s&r-�__repr__�NormalDist.__repr__�s.���t�*�%�%�&�d�4�8�8�,�h�t�{�{�o�Q�O�Or,c�2�VPVP3#rX�r�r�r�s&r-�__getstate__�NormalDist.__getstate__�s���x�x����$�$r,c�$�VwVnVnR#rXr�)r��states&&r-�__setstate__�NormalDist.__setstate__�s�� %����$�+r,r�r�)rF)&r'r(r)r*ro�	__slots__r��classmethodr�r�r�r�r�r�r�r��propertyr5rnr�r�r�r�r�r�r�r�r��__radd__r��__rmul__r�r�r�r�r�r+�__classdictcell__)�
__classdict__s@r-rr�s����.�781	�9��?��I�782#��'��'�D��D�K�C�>�	:� Q�D	,������������������)��)�2�2�=�=�-�.��H���H�;�-�P�%�&�&r,c��^p\4pVPp/pVPp\V\4FAwrgV!V4\\V4F wr�V^,
pV!V	^4V,WI&K"	KC	RV9dVR,p783\V7844'dQhM \RVP444p785\\V\4pW�V3#)aU_sum(data) -> (type, sum, count)786 787Return a high-precision sum of the given numeric data as a fraction,788together with the type to be converted to and the count of items.789 790Examples791--------792 793>>> _sum([3, 2.25, 4.5, -0.5, 0.25])794(<class 'float'>, Fraction(19, 2), 5)795 796Some sources of round-off error will be avoided:797 798# Built-in sum returns zero.799>>> _sum([1e50, 1, -1e50] * 1000)800(<class 'float'>, Fraction(1000, 1), 3000)801 802Fractions and Decimals are also supported:803 804>>> from fractions import Fraction as F805>>> _sum([F(2, 3), F(7, 5), F(1, 4), F(5, 6)])806(<class 'fractions.Fraction'>, Fraction(63, 20), 4)807 808>>> from decimal import Decimal as D809>>> data = [D("0.1375"), D("0.2108"), D("0.3061"), D("0.0419")]810>>> _sum(data)811(<class 'decimal.Decimal'>, Fraction(6963, 10000), 4)812 813Mixed types are currently treated as an error, except that int is814allowed.815 816Nc3�<"�TFwr\W!4x�K	R#5irXr�rY�dr4s&  r-r[�_sum.<locals>.<genexpr>�s���@�/?�t�q�H�Q�N�N�/?���)
�set�addrnrr�r9�_exact_ratio�	_isfiniter\r�r�_coercerm)r1r�types�	types_add�partials�partials_get�typr�r4r�r3r2s&           r-r/r/�s���B
�E��E�E��	�	�I��H��<�<�L��t�T�*����#����f�-�D�A��Q�J�E�&�q�!�,�q�0�H�K�.�+��x�������U�#�#�#�#�#��@�x�~�~�/?�@�@���w��s�#�A�
�e��r,c�aa�Se\VV3RlV44wr#pW#SV3#^p\4pVPp\\4p\\4p\V\4F`wr�V!V	4\\V8174F?wpoV^,
pVS;;,V,
uu&VS;;,W�,,
uu&KA	Kb	V'g\^4;poM�RV9d VR,;po\V4'dQhMd\RVP444p\RVP444p
WM,W�,,818V,pW�,o\\V\4pW#SV3#)a#Return the exact mean and sum of square deviations of sequence data.819 820Calculations are done in a single pass, allowing the input to be an iterator.821 822If given *c* is used the mean; otherwise, it is calculated from the data.823Use the *c* argument with care, as it can lead to garbage results.824 825Nc3�F<"�TFqS,826;oS,x�K	R#5irXr&)rYrOr�r�s& ��r-r[�_ss.<locals>.<genexpr>�s����<�t�!�q�5�j�a�A�-�-�t�s�!c3�<"�TFwr\W!4x�K	R#5irXrr�s&  r-r[rs���@�,?�D�A��!���,?�rc3�J"�TFwr\W!V,4x�K	R#5irXrr�s&  r-r[rs ���D�/C�t�q�(�1��c�"�"�/C�r_)r/rrr#rmrr�r9rrrr\r�rr)r1r�r2�ssdrrr�sx_partials�sxx_partialsrr�r4�sxr�r�s&f            @r-r�r��sR���	�}��<�t�<�<�
�����5�!�!�
�E��E�E��	�	�I��c�"�K��s�#�L��t�T�*����#����f�-�D�A�q��Q�J�E���N�a��N���O�q�u�$�O�.�+���1�+���a�	
��	��d�#�#��a��S�>�>�!�!�>��@�K�,=�,=�,?�@�
@���D�|�/A�/A�/C�D�D���{�R�W�$��-���J���w��s�#�A�
�A�u��r,c�r�VP4# \d\P!T4u#i;irX)�	is_finiter�rLr)rOs&r-rrs1�� ��{�{�}���� ��}�}�Q��� �s��!6�6c�,�V\JgQR4hWJdV#V\JgV\JdV#V\JdV#\W4'dV#\W4'dV#\V\4'dV#\V\4'dV#\V\4'd\V\4'dV#\V\4'd\V\4'dV#Rp\W PVP3,4h)z�Coerce types T and S to a common type, or raise TypeError.827 828Coercion rules are currently an implementation detail. See the CoerceTest829test class in test_statistics for details.830 831zinitial type T is boolz"don't know how to coerce %s and %s)�boolrmr�rrvr8r')r2�S�msgs&& r-rrs���
�D�=�2�2�2�=�	�v�q���C�x�1��9�a�x��C�x��(��!����(��!����(��!�S���1�H��!�S���1�H��!�X���:�a��#7�#7����!�U���832�1�h� 7� 7���833.�C�834�C�:�:�q�z�z�2�2�8353�3r,c�0�VP4# \dM-\\3d\	T4'dQhTR3u#i;iTP836TP3# \d&R\T4PR2p\T4hi;i)z�Return Real number x to exact (numerator, denominator) pair.837 838>>> _exact_ratio(0.25)839(1, 4)840 841x is expected to be an int, Fraction, Decimal or float.842 843Nzcan't convert type 'z' to numerator/denominator)844�as_integer_ratior��
OverflowErrorr?rr�r�r�r'r8)rOrs& r-rr=s�����!�!�#�#���
���:�&���Q�<�<����4�y����845����Q�]�]�+�+����$�T�!�W�%5�%5�$6�6P�Q����n���s%��A	�A	�A	�A	�
A%�%0Bc�2�\V4VJdV#\V\4'dVP^8wd\pV!V4# \846dD\T\4'd,T!TP4T!TP4,u#hi;i)z&Convert value to given numeric type T.)r�r�rmr�rvr8rr�)r�r2s&&r-r0r0Ws����E�{�a�����!�S���e�/�/�1�4������x������a��!�!��U�_�_�%��%�*;�*;�(<�<�<��	�s�A�A847B�Bc#�L"�VFpV^8d\V4hVx�K	R#5i)z7Iterate over values, failing if any are less than zero.N)r)r�rerOs&& r-rcrcks&���
���q�5�!�&�)�)����s�"$�key�reverse�ties�averagerIc�:�V^8�dQhR\\,/#)r��return)r=rv)�formats"r-�__annotate__r'ss��3�3�4�PU�;�3r,c��VR8wd\RV:24hVe\W4p\\V\	44VR7pV^,848p^.\V4,p\
V\^4R7FHwr�\V	4p849\V8504pWk^,^,,pV851F	wr�W�V&K	Wk,
pKJ	V#)a�Rank order a dataset. The lowest value has rank 1.852 853Ties are averaged so that equal values receive the same rank:854 855    >>> data = [31, 56, 31, 25, 75, 18]856    >>> _rank(data)857    [3.5, 5.0, 3.5, 2.0, 6.0, 1.0]858 859The operation is idempotent:860 861    >>> _rank([3.5, 5.0, 3.5, 2.0, 6.0, 1.0])862    [3.5, 5.0, 3.5, 2.0, 6.0, 1.0]863 864It is possible to rank the data in reverse order so that the865highest value has rank 1.  Also, a key-function can extract866the field to be ranked:867 868    >>> goals = [('eagles', 45), ('bears', 48), ('lions', 44)]869    >>> _rank(goals, key=itemgetter(1), reverse=True)870    [2.0, 1.0, 3.0]871 872Ranks are conventionally numbered starting from one; however,873setting *start* to zero allows the ranks to be used as array indices:874 875    >>> prize = ['Gold', 'Silver', 'Bronze', 'Certificate']876    >>> scores = [8.1, 7.3, 9.4, 8.3]877    >>> [prize[int(i)] for i in _rank(scores, start=0, reverse=True)]878    ['Bronze', 'Certificate', 'Gold', 'Silver']879 880r#zUnknown tie resolution method: )r!)r )	r?r9rlr:rr7rr r=)r1r r!r"rI�val_posrmr�rg�g�group�size�rankr��orig_poss"$$$$          r-r�r�ss���J�y���:�4�(�C�D�D�881���3�~���S��u�w�'��9�G�
��	�A��S�3�w�<�
�F���Z��]�3����Q����5�z���1�H��>�!��$�O�E�#�8�� %�	�	��
4��Mr,c�<�V^8�dQhR\R\R\/#�r�r4r�r%)rm)r&s"r-r'r'�s!���������r,c�l�\P!W,4pW"V,V,V8g,#)zFSquare root of n/m, rounded to the nearest integer using round-to-odd.)rL�isqrt)r4r�r�s&& r-�_integer_sqrt_of_frac_rtor3�s)��	
�882�883�1�6��A��!��A���884��r,c�<�V^8�dQhR\R\R\/#r0)rmrv)r&s"r-r'r'�s!��885#�886#�3�887#�3�888#�5�889#r,c�*�VP4VP4,890\,891^,pV^8�d+\W^V,,4V,p^pW4,#\VRV,,V4p^V),pW4,#)z1Square root of n/m as a float, correctly rounded.r�)�892bit_length�_sqrt_bit_widthr3)r4r��qr�r�s&&   r-r�r��s|��893����!�,�,�.�	(�?�	:�q�@�A��A�v�-�a�a�!�e��<��A�	����"�"�.�a�2��6�k�1�=�	��A�2�g���"�"r,c�<�V^8�dQhR\R\R\/#r0)rmr)r&s"r-r'r'�s!����S��S��W�r,c�V�V^8:dV'g\R4#V)V)r\V4\V4,P4pVP4wr4VP4pVP4wrg^V,WG,^,,WV,Ws,,^,,8�dV#VP	4pVP4wr�^V,WJ,^,,WV	,W�,,^,,8dV#V#)z3Square root of n/m as a Decimal, correctly rounded.z0.0)rr
r�	next_plus�894next_minus)r4r��root�nr�dr�plus�np�dp�minus�nmr�s&&         r-r�r��s���895	�A�v���5�>�!��r�A�2�1��A�J����#�)�)�+�D�
�
"�
"�
$�F�B��>�>��D�
�
"�
"�
$�F�B��1�u����z��A�B������ 2�2�2����O�O��E�
�
#�
#�
%�F�B��1�u����z��A�B������ 2�2�2����Kr,c�&�\V4wrr4V^8d\R4hW$^,896,p\V4\VPVP89743# \d*\T4\T4\T4,3u#i;i)zFIn one pass, compute the mean and sample standard deviation as floats.r�)r�rrvr�r�r�r�)r1r2r�r�r4r�s&     r-r�r��s|����Y�N�A�4��1�u��G�H�H�898�A��,�C�4��T�{�/��
�
�s���O�O�O���4��T�{�E�$�K�%��)�3�3�3�4�s�*A�1B�Bc�<�V^8�dQhR\R\R\/#)r�rOr�r%)rv)r&s"r-r'r'�s!������5��U�r,c��\W,4p\V4'gW\V4'dD\V4'g3\V4'g"Rp\W0,W1,4V,#V#V'g4V'd*V'd"Rp\W0,W1,4V,#V#\	W3W)34pW$RV,,,#)zRReturn sqrt(x * y) computed with improved accuracy and without overflow/underflow.r$g�g�a)r
rrr�r)rOr�rW�scaler�s&&   r-r�r��s���	
�Q�U��A��A�;�;���8�8�E�!�H�H�U�1�X�X��E��U�Y��	�2�U�:�:�������E��U�Y��	�2�U�:�:���	����B�� �A��C�!�G�}��r,c��VR,899p\V4R8:d�RW3,,900pRV,R,V,R,V,R,V,R,V,R,V,R	,V,R901,V,pRV,R,V,R
,V,R,V,R,V,R,V,R,V,R,pWV,pWV,,#VR8:dTMRV,902p\\V4)4pVR8:d�VR,903pRV,R,V,R,V,R,V,R,V,R,V,R,V,R,pRV,R,V,R ,V,R!,V,R",V,R#,V,R$,V,R,pM�VR,904pR%V,R&,V,R',V,R(,V,R),V,R*,V,R+,V,R,,pR-V,R.,V,R/,V,R0,V,R1,V,R2,V,R3,V,R,pWV,pVR8dV)pWV,,#)4r�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@r�rJg@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�@�F�>g�tcI,\�>g�ŝ���I?g*F2�v�?g�C4��?g��O�1�?)rr
r)r�r�r�r8�rrBrCrOs&&&     r-r�r�s���	905�C��A��A�w�%���q�u���0�1�4�0�1�45�6�0�1�45�6�1�1�56�6�1�	1�56�	6�9061�1�90756�6�1�
1�56�
6�1�1�56�6��1�1�4�0�1�45�6�0�1�45�6�1�1�56�6�1�	1�56�	6�9081�1�90956�6�1�
1�56�
6����
�I����Y���
�#�X��3��7�A��c�!�f�W�
�A��C�x�
��G��1�A�5�1�2�56�7�1�2�56�7�2�2�67�7�2�	2�67�	7�9102�2�91167�7�2�
2�67�
7�2�2��2�A�5�1�2�56�7�1�2�56�7�2�2�67�7�2�	2�67�	7�9122�2�91367�7�2�
2�67�
7����
��G��1�A�5�1�2�56�7�1�2�56�7�2�2�67�7�2�	2�67�	7�9142�2�91567�7�2�
2�67�
7�2�2��3�Q�6�1�2�56�7�1�2�56�7�2�2�67�7�2�	2�67�	7�9162�2�91767�7�2�
2�67�
7����	�	�A��3�w�
�B��
�U���r,r�c�@�V^8�dQh/^\9d918\;R&#)r�r7)�__conditional_annotations__rm)r&s"r-r'r's#��h�h�b57�6��6�c5hr,)rrr�r�rDrUrhrqr|r�r5rnr|rsrqr�r�r�r�r�r�r�rXr�r�)g�-���q=)r�)znegative value)irLro�__all__rLrarv�sys�	fractionsr�decimalr�	itertoolsrrr	�bisectr919rrr
rrrrrrrrrrrrrrrrr�	functoolsr�operatorr �collectionsr!r"r#r�ryr?rr5rDrUrhrnrqrsr|r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr	rrr&r-r8r:rCrKrqr|r�rr/r�rrrr0rcr�r3�920float_info�mant_digr7r�r�r�r�r��_statistics�ImportErrorr')rLs@r-�<module>rZs����h�T��2��
�921���,�,�,�F�F�F�K�K�K���8�8�	
�c���922��	�j�	�"�.(�V%�P<,�~+�0 �2�&E+�PB�<K�.+%�\(�V?�.?�2�:4H�8�4H�n�0�2H�I��<>�u�<>�B�
��923�(�G��%��%�924�*��%��%�925�)��	%��	%�926�-��#�%�$�%�927�,��%��%�928�+�~�&�%�'�%���929�)�Z� �%�!�%��930�+��%��%�931�(��%��%�
�m�_�n��)�+;��$�m�\��\�~*��*�b04��04�;�04�j\&�\&�B7�t,�^ �4�@�4�(�3�$�3��3�I�3�Q�3�l��3�>�>�2�2�2�Q�6��6�932#��89334��4K�^	�0���	��	�s�H�H*�)H*
codekingpro/portable-devtools · Team Ai