Skip to main content

Numba-accelerated implementations of common probability distributions

Project description

numba-stats

We provide numba-accelerated implementations of statistical functions for common probability distributions

  • Uniform
  • (Truncated) Normal
  • Log-normal
  • Poisson
  • (Truncated) Exponential
  • Student's t
  • Voigtian
  • Crystal Ball
  • Generalised double-sided Crystal Ball
  • Tsallis-Hagedorn, a model for the minimum bias pT distribution
  • Q-Gaussian
  • Bernstein density (not normalised to unity, use this in extended likelihood fits)

with more to come. The speed gains are huge, up to a factor of 100 compared to scipy. Benchmarks are included in the repository and are run by pytest.

Usage

Each distribution is implemented in a submodule. Import the submodule that you need.

from numba_stats import norm
import numpy as np

x = np.linspace(-10, 10)
mu = 2
sigma = 3

dp = norm.pdf(x, mu, sigma)
p = norm.cdf(x, mu, sigma)

The functions are fully vectorised, which means that mu and sigma can be vectors, too, although this is not usually needed. In the best case, the following functions are implemented

  • logpdf
  • pdf
  • cdf
  • ppf logpdf is only implemented if it is more efficient and accurate compared to computing log(dist.pdf(...)). cdf and ppf are missing for some distributions (e.g. voigt), if there is no known way to compute them accurately.

Documentation (or lack of)

Because of a technical limitation of Numba, this project is poorly documented. Functions with equivalents in scipy.stats follow the Scipy calling conventions exactly. These conventions are sometimes a bit unusual, for example, in case of the exponential, the log-normal or the uniform distribution. See the SciPy docs for details.

Please look into the source code for documentation of the other functions.

Technical note: pydoc numba_stats does not show anything useful, because numba.vectorize creates instances of a class DUFunc. The wrapped functions show up as objects of that class and help() shows the generic documentation of that class instead of the documentation for the instances.

Contributions

You can help with adding more distributions, patches are very welcome. Implementing a probability distribution is easy. You need to write it in simple Python that numba can understand. Special functions from scipy.special can be used after some wrapping, see submodule numba_stats._special.py how it is done.

numba-stats and numba-scipy

numba-scipy is the official package and repository for fast numba-accelerated scipy functions, are we reinventing the wheel?

Ideally, the functionality in this package should be in numba-scipy and we hope that eventually this will be case. In this package, we don't offer overloads for scipy functions and classes like numba-scipy does. This simplifies the implementation dramatically. numba-stats is intended as a temporary solution until fast statistical functions are included in numba-scipy. numba-stats currently does not depend on numba-scipy, only on numba and scipy.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

numba-stats-1.0.1.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

numba_stats-1.0.1-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file numba-stats-1.0.1.tar.gz.

File metadata

  • Download URL: numba-stats-1.0.1.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for numba-stats-1.0.1.tar.gz
Algorithm Hash digest
SHA256 3f24d31e65b50187e79875cb2d1186225281fcfab58f342be1a7b3b5aa24b6bb
MD5 2544b0fec8531204edb5f4bfa7158bf2
BLAKE2b-256 70bdff851f69f5cf67bc409ff1128daa8aa63492166df2f6ad36e60d6ac208b1

See more details on using hashes here.

File details

Details for the file numba_stats-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: numba_stats-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 14.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for numba_stats-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3cf8bcf9b90ea32adcb02f31b2c09879d40202a9fd57e0d23fbd26f4a9e3cce9
MD5 1ed33c3264ade4ef2df5fc22aaf70569
BLAKE2b-256 7d62b81f2bcd43b7d2bd2550343538f2149e05b963cfc458f3fd164860c9b59c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page