UniformSumDistribution
A implementation of the Irwin-Hall (the uniform sum) distribution - https://randomservices.org/random/special/IrwinHall.html
How to use
Install it from pip (depends on scipy and numpy)
pip install UniformSumDistribution
The package provides one class called UniformSumDistribution, which implements the distribution.
from UniformSumDistribution import UniformSumDistribution
distribution = UniformSumDistribution(n)
the distribution object has methods:
rvs(size=1, *args, **kwds)- Random variates of given type.pdf(x, *args, **kwds)- Probability density function at x of the given RV.logpdf(x, *args, **kwds)- Log of the probability density function at x of the given RV.cdf(x, *args, **kwds)- Cumulative distribution function of the given RV.logcdf(x, *args, **kwds)- Log of the cumulative distribution function at x of the given RV.sf(x, *args, **kwds)- Survival function (1 - cdf) at x of the given RV.logsf(x, *args, **kwds)- Log of the survival function of the given RV.ppf(q, *args, **kwds)- Percent point function (inverse of cdf) at q of the given RV.isf(q, *args, **kwds)- Inverse survival function (inverse of sf) at q of the given RV.moment(n, *args, **kwds)- n-th order non-central moment of distribution.stats(*args, **kwds)- Some statistics of the given RV.entropy(*args, **kwds)- Differential entropy of the RV.expect([func, args, loc, scale, lb, ub, …])- Calculate expected value of a function with respect to the distribution by numerical integration.median(*args, **kwds)- Median of the distribution.mean(*args, **kwds)- Mean of the distribution.std(*args, **kwds)- Standard deviation of the distribution.var(*args, **kwds)- Variance of the distribution.interval(alpha, *args, **kwds)- Confidence interval with equal areas around the median.__call__(*args, **kwds)- Freeze the distribution for the given arguments.fit(data, *args, **kwds)- Return estimates of shape (if applicable), location, and scale parameters from data.fit_loc_scale(data, *args)- Estimate loc and scale parameters from data using 1st and 2nd moments.nnlf(theta, x)- Negative loglikelihood function.support(*args, **kwargs)- Support of the distribution.
Read more
scipy.stats.rv_continuous- https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.rv_continuous.html?highlight=rv_continuousContinuous Statistical Distributions- https://docs.scipy.org/doc/scipy/tutorial/stats/continuous.html#continuous-distributions-in-scipy-stats
Usage example
size = 8196
# Build PDF
plt.figure(figsize=(10, 6))
for n in range(1, 14):
distribution = UniformSumDistribution(n)
start = distribution.ppf(0.0001)
end = distribution.ppf(0.9999)
x = np.linspace(start, end, size)
y = distribution.pdf(x)
pdf = pd.Series(y, x)
ax = pdf.plot(kind = 'line', label = 'n=%s' % n, legend = True, lw = 2)
ax.set_title('PDF')
# Build CDF
plt.figure(figsize=(10, 6))
for n in range(1, 14):
distribution = UniformSumDistribution(n)
start = distribution.ppf(0.0001)
end = distribution.ppf(0.9999)
x = np.linspace(start, end, size)
y = distribution.cdf(x)
cdf = pd.Series(y, x)
ax = cdf.plot(kind = 'line', label = 'n=%s' % n, legend = True, lw = 2)
ax.set_title('CDF')
distribution = UniformSumDistribution(n = 2)
mean, variance, skew, kurtosis = distribution.stats(moments = 'mvsk')
mean, variance, skew, kurtosis
[out]: (array(1.), array(0.16666667), array(0.), array(-0.6))
size = 5000
bins = 32
n = 2
distribution = UniformSumDistribution(n = n)
# Get start and end points of distribution
start = distribution.ppf(0.0001)
end = distribution.ppf(0.9999)
# Build PDF
x = np.linspace(start, end, size)
y = distribution.pdf(x)
pdf = pd.Series(y, x)
# Create random data
rv = pd.Series(distribution.rvs(size = size))
# Get histogram of random data
b = np.linspace(start, end, bins + 1)
y, x = np.histogram(rv, bins = b, density = True)
x = [(a + x[i + 1]) / 2.0 for i, a in enumerate(x[0:-1])]
hist = pd.Series(y, x)
w = abs(abs(hist.index[0]) - abs(hist.index[1]))
plt.figure(figsize=(10, 6))
ax = pdf.plot(kind = 'line', label = 'PDF', legend = True, lw = 2, color = 'r')
ax.bar(hist.index, hist.values, label = 'Random Sample', width = w, alpha = 0.5, color = 'c')
legend = plt.legend()
License
Copyright (c) 2022 Artyom Zolotarevskiy.
UniformSumDistribution is free software made available under the MIT License. For details see the LICENSE file.
Release files for UniformSumDistribution 1.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| UniformSumDistribution-1.0.3.tar.gz | 4.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| UniformSumDistribution-1.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.4 kB
Release files / UniformSumDistribution-1.0.3.tar.gz
| Download URL | UniformSumDistribution-1.0.3.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ba4321ece4582f726c853ef0b1787e0531b6e99af478e6ca2e9cb610c1ebfae2
|
|
BLAKE2b-256 checksum How to use checksums |
8ae5ab290c947c17b7c769b4100b25e5c5385199f1689f44e7e34dce7a815c41
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.9.7
|
Release files / UniformSumDistribution-1.0.3-py3-none-any.whl
| Download URL | UniformSumDistribution-1.0.3-py3-none-any.whl |
|---|---|
| Size | 4.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0e73f298ec31c736ff4d31f20fd5952fb429cdbda804741cdbe726a4dcdb7b0c
|
|
BLAKE2b-256 checksum How to use checksums |
e2fbd9b92b0789151c8494ce4aaf70f38384ccb82cc411a36c7c8c91b739ed58
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.9.7
|