id
int64
1
6.07M
name
stringlengths
1
295
code
stringlengths
12
426k
language
stringclasses
1 value
source_file
stringlengths
5
202
start_line
int64
1
158k
end_line
int64
1
158k
repo
dict
15,701
__enter__
def __enter__(self): self._old_cwd.append(os.getcwd()) os.chdir(self.path)
python
Lib/contextlib.py
809
811
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,702
__exit__
def __exit__(self, *excinfo): os.chdir(self._old_cwd.pop())
python
Lib/contextlib.py
813
814
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,703
_sum
def _sum(data): """_sum(data) -> (type, sum, count) Return a high-precision sum of the given numeric data as a fraction, together with the type to be converted to and the count of items. Examples -------- >>> _sum([3, 2.25, 4.5, -0.5, 0.25]) (<class 'float'>, Fraction(19, 2), 5) Some...
python
Lib/statistics.py
158
209
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,704
_ss
def _ss(data, c=None): """Return the exact mean and sum of square deviations of sequence data. Calculations are done in a single pass, allowing the input to be an iterator. If given *c* is used the mean; otherwise, it is calculated from the data. Use the *c* argument with care, as it can lead to garba...
python
Lib/statistics.py
212
250
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,705
_isfinite
def _isfinite(x): try: return x.is_finite() # Likely a Decimal. except AttributeError: return math.isfinite(x) # Coerces to float first.
python
Lib/statistics.py
253
257
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,706
_coerce
def _coerce(T, S): """Coerce types T and S to a common type, or raise TypeError. Coercion rules are currently an implementation detail. See the CoerceTest test class in test_statistics for details. """ # See http://bugs.python.org/issue24068. assert T is not bool, "initial type T is bool" #...
python
Lib/statistics.py
260
288
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,707
_exact_ratio
def _exact_ratio(x): """Return Real number x to exact (numerator, denominator) pair. >>> _exact_ratio(0.25) (1, 4) x is expected to be an int, Fraction, Decimal or float. """ # XXX We should revisit whether using fractions to accumulate exact # ratios is the right way to go. # The in...
python
Lib/statistics.py
291
334
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,708
_convert
def _convert(value, T): """Convert value to given numeric type T.""" if type(value) is T: # This covers the cases where T is Fraction, or where value is # a NAN or INF (Decimal or float). return value if issubclass(T, int) and value.denominator != 1: T = float try: ...
python
Lib/statistics.py
337
352
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,709
_fail_neg
def _fail_neg(values, errmsg='negative value'): """Iterate over values, failing if any are less than zero.""" for x in values: if x < 0: raise StatisticsError(errmsg) yield x
python
Lib/statistics.py
355
360
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,710
_rank
def _rank(data, /, *, key=None, reverse=False, ties='average', start=1) -> list[float]: """Rank order a dataset. The lowest value has rank 1. Ties are averaged so that equal values receive the same rank: >>> data = [31, 56, 31, 25, 75, 18] >>> _rank(data) [3.5, 5.0, 3.5, 2.0, 6.0, 1.0]...
python
Lib/statistics.py
363
414
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,711
_integer_sqrt_of_frac_rto
def _integer_sqrt_of_frac_rto(n: int, m: int) -> int: """Square root of n/m, rounded to the nearest integer using round-to-odd.""" # Reference: https://www.lri.fr/~melquion/doc/05-imacs17_1-expose.pdf a = math.isqrt(n // m) return a | (a*a*m != n)
python
Lib/statistics.py
417
421
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,712
_float_sqrt_of_frac
def _float_sqrt_of_frac(n: int, m: int) -> float: """Square root of n/m as a float, correctly rounded.""" # See principle and proof sketch at: https://bugs.python.org/msg407078 q = (n.bit_length() - m.bit_length() - _sqrt_bit_width) // 2 if q >= 0: numerator = _integer_sqrt_of_frac_rto(n, m << 2...
python
Lib/statistics.py
429
439
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,713
_decimal_sqrt_of_frac
def _decimal_sqrt_of_frac(n: int, m: int) -> Decimal: """Square root of n/m as a Decimal, correctly rounded.""" # Premise: For decimal, computing (n/m).sqrt() can be off # by 1 ulp from the correctly rounded result. # Method: Check the result, moving up or down a step if needed. if n <=...
python
Lib/statistics.py
442
467
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,714
mean
def mean(data): """Return the sample arithmetic mean of data. >>> mean([1, 2, 3, 4, 4]) 2.8 >>> from fractions import Fraction as F >>> mean([F(3, 7), F(1, 21), F(5, 3), F(1, 3)]) Fraction(13, 21) >>> from decimal import Decimal as D >>> mean([D("0.5"), D("0.75"), D("0.625"), D("0.375...
python
Lib/statistics.py
472
491
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,715
fmean
def fmean(data, weights=None): """Convert data to floats and compute the arithmetic mean. This runs faster than the mean() function and it always returns a float. If the input dataset is empty, it raises a StatisticsError. >>> fmean([3.5, 4.0, 5.25]) 4.25 """ if weights is None: tr...
python
Lib/statistics.py
494
527
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,716
count
def count(iterable): nonlocal n for n, x in enumerate(iterable, start=1): yield x
python
Lib/statistics.py
509
512
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,717
geometric_mean
def geometric_mean(data): """Convert data to floats and compute the geometric mean. Raises a StatisticsError if the input dataset is empty or if it contains a negative value. Returns zero if the product of inputs is zero. No special efforts are made to achieve exact results. (However, this ma...
python
Lib/statistics.py
530
562
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,718
count_positive
def count_positive(iterable): nonlocal n, found_zero for n, x in enumerate(iterable, start=1): if x > 0.0 or math.isnan(x): yield x elif x == 0.0: found_zero = True else: raise StatisticsError('No negative inputs allowed...
python
Lib/statistics.py
546
554
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,719
harmonic_mean
def harmonic_mean(data, weights=None): """Return the harmonic mean of data. The harmonic mean is the reciprocal of the arithmetic mean of the reciprocals of the data. It can be used for averaging ratios or rates, for example speeds. Suppose a car travels 40 km/hr for 5 km and then speeds-up to ...
python
Lib/statistics.py
565
618
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,720
median
def median(data): """Return the median (middle value) of numeric data. When the number of data points is odd, return the middle data point. When the number of data points is even, the median is interpolated by taking the average of the two middle values: >>> median([1, 3, 5]) 3 >>> median(...
python
Lib/statistics.py
621
642
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,721
median_low
def median_low(data): """Return the low median of numeric data. When the number of data points is odd, the middle value is returned. When it is even, the smaller of the two middle values is returned. >>> median_low([1, 3, 5]) 3 >>> median_low([1, 3, 5, 7]) 3 """ data = sorted(data...
python
Lib/statistics.py
645
664
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,722
median_high
def median_high(data): """Return the high median of data. When the number of data points is odd, the middle value is returned. When it is even, the larger of the two middle values is returned. >>> median_high([1, 3, 5]) 3 >>> median_high([1, 3, 5, 7]) 5 """ data = sorted(data) ...
python
Lib/statistics.py
667
683
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,723
median_grouped
def median_grouped(data, interval=1.0): """Estimates the median for numeric data binned around the midpoints of consecutive, fixed-width intervals. The *data* can be any iterable of numeric data with each value being exactly the midpoint of a bin. At least one value must be present. The *interval...
python
Lib/statistics.py
686
755
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,724
mode
def mode(data): """Return the most common data point from discrete or nominal data. ``mode`` assumes discrete data, and returns a single value. This is the standard treatment of the mode as commonly taught in schools: >>> mode([1, 1, 2, 3, 3, 3, 3, 4]) 3 This also works with nominal (...
python
Lib/statistics.py
758
785
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,725
multimode
def multimode(data): """Return a list of the most frequently occurring values. Will return more than one result if there are multiple modes or an empty list if *data* is empty. >>> multimode('aabbbbbbbbcc') ['b'] >>> multimode('aabbbbccddddeeffffgg') ['b', 'd', 'f'] >>> multimode('') ...
python
Lib/statistics.py
788
805
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,726
kde
def kde(data, h, kernel='normal', *, cumulative=False): """Kernel Density Estimation: Create a continuous probability density function or cumulative distribution function from discrete samples. The basic idea is to smooth the data using a kernel function to help draw inferences about a population from...
python
Lib/statistics.py
808
1,017
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,727
pdf
def pdf(x): n = len(data) return sum(K((x - x_i) / h) for x_i in data) / (n * h)
python
Lib/statistics.py
978
980
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,728
cdf
def cdf(x): n = len(data) return sum(W((x - x_i) / h) for x_i in data) / n
python
Lib/statistics.py
982
984
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,729
pdf
def pdf(x): nonlocal n, sample if len(data) != n: sample = sorted(data) n = len(data) i = bisect_left(sample, x - bandwidth) j = bisect_right(sample, x + bandwidth) supported = sample[i : j] return sum(K((x - x_i) / ...
python
Lib/statistics.py
991
999
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,730
cdf
def cdf(x): nonlocal n, sample if len(data) != n: sample = sorted(data) n = len(data) i = bisect_left(sample, x - bandwidth) j = bisect_right(sample, x + bandwidth) supported = sample[i : j] return sum((W((x - x_i) /...
python
Lib/statistics.py
1,001
1,009
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,731
quantiles
def quantiles(data, *, n=4, method='exclusive'): """Divide *data* into *n* continuous intervals with equal probability. Returns a list of (n - 1) cut points separating the intervals. Set *n* to 4 for quartiles (the default). Set *n* to 10 for deciles. Set *n* to 100 for percentiles which gives the 99...
python
Lib/statistics.py
1,057
1,102
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,732
variance
def variance(data, xbar=None): """Return the sample variance of data. data should be an iterable of Real-valued numbers, with at least two values. The optional argument xbar, if given, should be the mean of the data. If it is missing or None, the mean is automatically calculated. Use this function...
python
Lib/statistics.py
1,111
1,152
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,733
pvariance
def pvariance(data, mu=None): """Return the population variance of ``data``. data should be a sequence or iterable of Real-valued numbers, with at least one value. The optional argument mu, if given, should be the mean of the data. If it is missing or None, the mean is automatically calculated. Us...
python
Lib/statistics.py
1,155
1,193
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,734
stdev
def stdev(data, xbar=None): """Return the square root of the sample variance. See ``variance`` for arguments and other details. >>> stdev([1.5, 2.5, 2.5, 2.75, 3.25, 4.75]) 1.0810874155219827 """ T, ss, c, n = _ss(data, xbar) if n < 2: raise StatisticsError('stdev requires at leas...
python
Lib/statistics.py
1,196
1,211
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,735
pstdev
def pstdev(data, mu=None): """Return the square root of the population variance. See ``pvariance`` for arguments and other details. >>> pstdev([1.5, 2.5, 2.5, 2.75, 3.25, 4.75]) 0.986893273527251 """ T, ss, c, n = _ss(data, mu) if n < 1: raise StatisticsError('pstdev requires at l...
python
Lib/statistics.py
1,214
1,229
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,736
_mean_stdev
def _mean_stdev(data): """In one pass, compute the mean and sample standard deviation as floats.""" T, ss, xbar, n = _ss(data) if n < 2: raise StatisticsError('stdev requires at least two data points') mss = ss / (n - 1) try: return float(xbar), _float_sqrt_of_frac(mss.numerator, mss...
python
Lib/statistics.py
1,232
1,242
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,737
_sqrtprod
def _sqrtprod(x: float, y: float) -> float: "Return sqrt(x * y) computed with improved accuracy and without overflow/underflow." h = sqrt(x * y) if not isfinite(h): if isinf(h) and not isinf(x) and not isinf(y): # Finite inputs overflowed, so scale down, and recompute. scale ...
python
Lib/statistics.py
1,244
1,263
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,738
covariance
def covariance(x, y, /): """Covariance Return the sample covariance of two inputs *x* and *y*. Covariance is a measure of the joint variability of two inputs. >>> x = [1, 2, 3, 4, 5, 6, 7, 8, 9] >>> y = [1, 2, 3, 1, 2, 3, 1, 2, 3] >>> covariance(x, y) 0.75 >>> z = [9, 8, 7, 6, 5, 4, 3,...
python
Lib/statistics.py
1,273
1,298
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,739
correlation
def correlation(x, y, /, *, method='linear'): """Pearson's correlation coefficient Return the Pearson's correlation coefficient for two inputs. Pearson's correlation coefficient *r* takes values between -1 and +1. It measures the strength and direction of a linear relationship. >>> x = [1, 2, 3, 4...
python
Lib/statistics.py
1,301
1,346
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,740
linear_regression
def linear_regression(x, y, /, *, proportional=False): """Slope and intercept for simple linear regression. Return the slope and intercept of simple linear regression parameters estimated using ordinary least squares. Simple linear regression describes relationship between an independent variable *...
python
Lib/statistics.py
1,352
1,407
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,741
_normal_dist_inv_cdf
def _normal_dist_inv_cdf(p, mu, sigma): # There is no closed-form solution to the inverse CDF for the normal # distribution, so we use a rational approximation instead: # Wichura, M.J. (1988). "Algorithm AS241: The Percentage Points of the # Normal Distribution". Applied Statistics. Blackwell Publishin...
python
Lib/statistics.py
1,413
1,484
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,742
__init__
def __init__(self, mu=0.0, sigma=1.0): "NormalDist where mu is the mean and sigma is the standard deviation." if sigma < 0.0: raise StatisticsError('sigma must be non-negative') self._mu = float(mu) self._sigma = float(sigma)
python
Lib/statistics.py
1,504
1,509
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,743
from_samples
def from_samples(cls, data): "Make a normal distribution instance from sample data." return cls(*_mean_stdev(data))
python
Lib/statistics.py
1,512
1,514
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,744
samples
def samples(self, n, *, seed=None): "Generate *n* samples for a given mean and standard deviation." rnd = random.random if seed is None else random.Random(seed).random inv_cdf = _normal_dist_inv_cdf mu = self._mu sigma = self._sigma return [inv_cdf(rnd(), mu, sigma) for _...
python
Lib/statistics.py
1,516
1,522
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,745
pdf
def pdf(self, x): "Probability density function. P(x <= X < x+dx) / dx" variance = self._sigma * self._sigma if not variance: raise StatisticsError('pdf() not defined when sigma is zero') diff = x - self._mu return exp(diff * diff / (-2.0 * variance)) / sqrt(tau * va...
python
Lib/statistics.py
1,524
1,530
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,746
cdf
def cdf(self, x): "Cumulative distribution function. P(X <= x)" if not self._sigma: raise StatisticsError('cdf() not defined when sigma is zero') return 0.5 * (1.0 + erf((x - self._mu) / (self._sigma * _SQRT2)))
python
Lib/statistics.py
1,532
1,536
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,747
inv_cdf
def inv_cdf(self, p): """Inverse cumulative distribution function. x : P(X <= x) = p Finds the value of the random variable such that the probability of the variable being less than or equal to that value equals the given probability. This function is also called the percent p...
python
Lib/statistics.py
1,538
1,550
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,748
quantiles
def quantiles(self, n=4): """Divide into *n* continuous intervals with equal probability. Returns a list of (n - 1) cut points separating the intervals. Set *n* to 4 for quartiles (the default). Set *n* to 10 for deciles. Set *n* to 100 for percentiles which gives the 99 cuts points t...
python
Lib/statistics.py
1,552
1,561
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,749
overlap
def overlap(self, other): """Compute the overlapping coefficient (OVL) between two normal distributions. Measures the agreement between two normal probability distributions. Returns a value between 0.0 and 1.0 giving the overlapping area in the two underlying probability density functio...
python
Lib/statistics.py
1,563
1,595
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,750
zscore
def zscore(self, x): """Compute the Standard Score. (x - mean) / stdev Describes *x* in terms of the number of standard deviations above or below the mean of the normal distribution. """ # https://www.statisticshowto.com/probability-and-statistics/z-score/ if not self._...
python
Lib/statistics.py
1,597
1,606
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,751
mean
def mean(self): "Arithmetic mean of the normal distribution." return self._mu
python
Lib/statistics.py
1,609
1,611
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,752
median
def median(self): "Return the median of the normal distribution" return self._mu
python
Lib/statistics.py
1,614
1,616
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,753
mode
def mode(self): """Return the mode of the normal distribution The mode is the value x where which the probability density function (pdf) takes its maximum value. """ return self._mu
python
Lib/statistics.py
1,619
1,625
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,754
stdev
def stdev(self): "Standard deviation of the normal distribution." return self._sigma
python
Lib/statistics.py
1,628
1,630
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,755
variance
def variance(self): "Square of the standard deviation." return self._sigma * self._sigma
python
Lib/statistics.py
1,633
1,635
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,756
__add__
def __add__(x1, x2): """Add a constant or another NormalDist instance. If *other* is a constant, translate mu by the constant, leaving sigma unchanged. If *other* is a NormalDist, add both the means and the variances. Mathematically, this works only if the two distributions are...
python
Lib/statistics.py
1,637
1,649
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,757
__sub__
def __sub__(x1, x2): """Subtract a constant or another NormalDist instance. If *other* is a constant, translate by the constant mu, leaving sigma unchanged. If *other* is a NormalDist, subtract the means and add the variances. Mathematically, this works only if the two distribu...
python
Lib/statistics.py
1,651
1,663
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,758
__mul__
def __mul__(x1, x2): """Multiply both mu and sigma by a constant. Used for rescaling, perhaps to change measurement units. Sigma is scaled with the absolute value of the constant. """ return NormalDist(x1._mu * x2, x1._sigma * fabs(x2))
python
Lib/statistics.py
1,665
1,671
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,759
__truediv__
def __truediv__(x1, x2): """Divide both mu and sigma by a constant. Used for rescaling, perhaps to change measurement units. Sigma is scaled with the absolute value of the constant. """ return NormalDist(x1._mu / x2, x1._sigma / fabs(x2))
python
Lib/statistics.py
1,673
1,679
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,760
__pos__
def __pos__(x1): "Return a copy of the instance." return NormalDist(x1._mu, x1._sigma)
python
Lib/statistics.py
1,681
1,683
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,761
__neg__
def __neg__(x1): "Negates mu while keeping sigma the same." return NormalDist(-x1._mu, x1._sigma)
python
Lib/statistics.py
1,685
1,687
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,762
__rsub__
def __rsub__(x1, x2): "Subtract a NormalDist from a constant or another NormalDist." return -(x1 - x2)
python
Lib/statistics.py
1,691
1,693
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,763
__eq__
def __eq__(x1, x2): "Two NormalDist objects are equal if their mu and sigma are both equal." if not isinstance(x2, NormalDist): return NotImplemented return x1._mu == x2._mu and x1._sigma == x2._sigma
python
Lib/statistics.py
1,697
1,701
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,764
__hash__
def __hash__(self): "NormalDist objects hash equal if their mu and sigma are both equal." return hash((self._mu, self._sigma))
python
Lib/statistics.py
1,703
1,705
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,765
__repr__
def __repr__(self): return f'{type(self).__name__}(mu={self._mu!r}, sigma={self._sigma!r})'
python
Lib/statistics.py
1,707
1,708
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,766
__getstate__
def __getstate__(self): return self._mu, self._sigma
python
Lib/statistics.py
1,710
1,711
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,767
__setstate__
def __setstate__(self, state): self._mu, self._sigma = state
python
Lib/statistics.py
1,713
1,714
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,768
_newton_raphson
def _newton_raphson(f_inv_estimate, f, f_prime, tolerance=1e-12): def f_inv(y): "Return x such that f(x) ≈ y within the specified tolerance." x = f_inv_estimate(y) while abs(diff := f(x) - y) > tolerance: x -= diff / f_prime(x) return x return f_inv
python
Lib/statistics.py
1,719
1,726
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,769
f_inv
def f_inv(y): "Return x such that f(x) ≈ y within the specified tolerance." x = f_inv_estimate(y) while abs(diff := f(x) - y) > tolerance: x -= diff / f_prime(x) return x
python
Lib/statistics.py
1,720
1,725
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,770
_quartic_invcdf_estimate
def _quartic_invcdf_estimate(p): sign, p = (1.0, p) if p <= 1/2 else (-1.0, 1.0 - p) x = (2.0 * p) ** 0.4258865685331 - 1.0 if p >= 0.004 < 0.499: x += 0.026818732 * sin(7.101753784 * p + 2.73230839482953) return x * sign
python
Lib/statistics.py
1,728
1,733
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,771
_triweight_invcdf_estimate
def _triweight_invcdf_estimate(p): sign, p = (1.0, p) if p <= 1/2 else (-1.0, 1.0 - p) x = (2.0 * p) ** 0.3400218741872791 - 1.0 return x * sign
python
Lib/statistics.py
1,740
1,743
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,772
kde_random
def kde_random(data, h, kernel='normal', *, seed=None): """Return a function that makes a random selection from the estimated probability density function created by kde(data, h, kernel). Providing a *seed* allows reproducible selections within a single thread. The seed may be an integer, float, str, ...
python
Lib/statistics.py
1,766
1,807
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,773
rand
def rand(): return choice(data) + h * kernel_invcdf(random())
python
Lib/statistics.py
1,802
1,803
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,774
_f
def _f(): pass
python
Lib/_collections_abc.py
40
40
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,775
_coro
async def _coro(): pass
python
Lib/_collections_abc.py
90
90
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,776
_ag
async def _ag(): yield
python
Lib/_collections_abc.py
96
96
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,777
_check_methods
def _check_methods(C, *methods): mro = C.__mro__ for method in methods: for B in mro: if method in B.__dict__: if B.__dict__[method] is None: return NotImplemented break else: return NotImplemented return True
python
Lib/_collections_abc.py
104
114
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,778
__hash__
def __hash__(self): return 0
python
Lib/_collections_abc.py
121
122
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,779
__subclasshook__
def __subclasshook__(cls, C): if cls is Hashable: return _check_methods(C, "__hash__") return NotImplemented
python
Lib/_collections_abc.py
125
128
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,780
__await__
def __await__(self): yield
python
Lib/_collections_abc.py
136
137
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,781
__subclasshook__
def __subclasshook__(cls, C): if cls is Awaitable: return _check_methods(C, "__await__") return NotImplemented
python
Lib/_collections_abc.py
140
143
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,782
send
def send(self, value): """Send a value into the coroutine. Return next yielded value or raise StopIteration. """ raise StopIteration
python
Lib/_collections_abc.py
153
157
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,783
throw
def throw(self, typ, val=None, tb=None): """Raise an exception in the coroutine. Return next yielded value or raise StopIteration. """ if val is None: if tb is None: raise typ val = typ() if tb is not None: val = val.with_traceb...
python
Lib/_collections_abc.py
160
170
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,784
close
def close(self): """Raise GeneratorExit inside coroutine. """ try: self.throw(GeneratorExit) except (GeneratorExit, StopIteration): pass else: raise RuntimeError("coroutine ignored GeneratorExit")
python
Lib/_collections_abc.py
172
180
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,785
__subclasshook__
def __subclasshook__(cls, C): if cls is Coroutine: return _check_methods(C, '__await__', 'send', 'throw', 'close') return NotImplemented
python
Lib/_collections_abc.py
183
186
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,786
__aiter__
def __aiter__(self): return AsyncIterator()
python
Lib/_collections_abc.py
197
198
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,787
__subclasshook__
def __subclasshook__(cls, C): if cls is AsyncIterable: return _check_methods(C, "__aiter__") return NotImplemented
python
Lib/_collections_abc.py
201
204
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,788
__anext__
async def __anext__(self): """Return the next item or raise StopAsyncIteration when exhausted.""" raise StopAsyncIteration
python
Lib/_collections_abc.py
214
216
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,789
__aiter__
def __aiter__(self): return self
python
Lib/_collections_abc.py
218
219
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,790
__subclasshook__
def __subclasshook__(cls, C): if cls is AsyncIterator: return _check_methods(C, "__anext__", "__aiter__") return NotImplemented
python
Lib/_collections_abc.py
222
225
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,791
__anext__
async def __anext__(self): """Return the next item from the asynchronous generator. When exhausted, raise StopAsyncIteration. """ return await self.asend(None)
python
Lib/_collections_abc.py
232
236
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,792
asend
async def asend(self, value): """Send a value into the asynchronous generator. Return next yielded value or raise StopAsyncIteration. """ raise StopAsyncIteration
python
Lib/_collections_abc.py
239
243
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,793
athrow
async def athrow(self, typ, val=None, tb=None): """Raise an exception in the asynchronous generator. Return next yielded value or raise StopAsyncIteration. """ if val is None: if tb is None: raise typ val = typ() if tb is not None: ...
python
Lib/_collections_abc.py
246
256
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,794
aclose
async def aclose(self): """Raise GeneratorExit inside coroutine. """ try: await self.athrow(GeneratorExit) except (GeneratorExit, StopAsyncIteration): pass else: raise RuntimeError("asynchronous generator ignored GeneratorExit")
python
Lib/_collections_abc.py
258
266
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,795
__subclasshook__
def __subclasshook__(cls, C): if cls is AsyncGenerator: return _check_methods(C, '__aiter__', '__anext__', 'asend', 'athrow', 'aclose') return NotImplemented
python
Lib/_collections_abc.py
269
273
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,796
__iter__
def __iter__(self): while False: yield None
python
Lib/_collections_abc.py
284
286
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,797
__subclasshook__
def __subclasshook__(cls, C): if cls is Iterable: return _check_methods(C, "__iter__") return NotImplemented
python
Lib/_collections_abc.py
289
292
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,798
__next__
def __next__(self): 'Return the next item from the iterator. When exhausted, raise StopIteration' raise StopIteration
python
Lib/_collections_abc.py
302
304
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,799
__iter__
def __iter__(self): return self
python
Lib/_collections_abc.py
306
307
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
15,800
__subclasshook__
def __subclasshook__(cls, C): if cls is Iterator: return _check_methods(C, '__iter__', '__next__') return NotImplemented
python
Lib/_collections_abc.py
310
313
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }