Efficiently sample from the Polya-Gamma distribution using NumPy's Generator interface
Project description
polya-gamma
Efficiently sample from the Polya-Gamma distribution using NumPy's Generator interface.
Dependencies
- Numpy >= 1.17
Installation
$ pip install -U polyagamma
Example
Python
polyagamma
can act as a drop-in replacement for numpy's Generator class.
import numpy as np
from polyagamma import default_rng, Generator
g = Generator(np.random.PCG64()) # or use default_rng()
print(g.polyagamma())
# Get a 5 by 10 array of PG(1, 2) variates.
print(g.polyagamma(z=2, size=(5, 10)))
# Pass sequences as input. Numpy's broadcasting semantics apply here.
h = [[1, 2, 3, 4, 5], [9, 8, 7, 6, 5]]
print(g.polyagamma(h, 1))
# Pass an output array
out = np.empty(5)
g.polyagamma(out=out)
print(out)
# one can choose a sampling method from {devroye, alternate, gamma}.
# If not given, the default behaviour is a hybrid sampler that picks
# the best method based on the parameter values
out = g.polyagamma(method="devroye")
# other numpy distributions are still accessible
print(g.standard_normal())
print(g.standard_gamma())
C
For an example of how to use polyagamma
in a C program, see here.
TODO
Add devroye and gamma convolution methods.Add the "alternate" sampling method.Add the hybrid sampler based on a combination of available methods.Add array broadcasting support for paramater inputs.- Add the "saddle point approximation" method.
References
- Luc Devroye. "On exact simulation algorithms for some distributions related to Jacobi theta functions." Statistics & Probability Letters, Volume 79, Issue 21, (2009): 2251-2259.
- Polson, Nicholas G., James G. Scott, and Jesse Windle. "Bayesian inference for logistic models using Pólya–Gamma latent variables." Journal of the American statistical Association 108.504 (2013): 1339-1349.
- J. Windle, N. G. Polson, and J. G. Scott. "Improved Polya-gamma sampling". Technical Report, University of Texas at Austin, 2013b.
- Windle, Jesse, Nicholas G. Polson, and James G. Scott. "Sampling Polya-Gamma random variates: alternate and approximate techniques." arXiv preprint arXiv:1405.0506 (2014)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file polyagamma-0.1.0.tar.gz
.
File metadata
- Download URL: polyagamma-0.1.0.tar.gz
- Upload date:
- Size: 138.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce73a0c9671e8ffb371d7bea59cf5d20ae6e9969a7b6629a67c1d2b2ebee2787 |
|
MD5 | 7bfd4277e4ca9ea4d5380a1e5444d92a |
|
BLAKE2b-256 | 74147df4c6541dfb292335213cfb1a498d96c52fa67e807f9b3a9a9c4f829e6a |
File details
Details for the file polyagamma-0.1.0-cp39-cp39-manylinux2014_x86_64.whl
.
File metadata
- Download URL: polyagamma-0.1.0-cp39-cp39-manylinux2014_x86_64.whl
- Upload date:
- Size: 567.4 kB
- Tags: CPython 3.9
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00310dc98fccc23f41d27309dcde90e4e5ce7ef71d3f5ad8d4d700485ecda622 |
|
MD5 | b8840ba297ddb40aba2584dd36193b0d |
|
BLAKE2b-256 | 3d1970d5e709514f15304a7281bc0e2ac397d129dc764010a552a5a117bf6578 |
File details
Details for the file polyagamma-0.1.0-cp39-cp39-manylinux2010_x86_64.whl
.
File metadata
- Download URL: polyagamma-0.1.0-cp39-cp39-manylinux2010_x86_64.whl
- Upload date:
- Size: 525.1 kB
- Tags: CPython 3.9, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9aaee27e22c3ee9ae162e642fd9e18666b0a5c586d5fe30e63395e7fc4368bd |
|
MD5 | 47878f6b9e9728bca105210611d8169d |
|
BLAKE2b-256 | b73d8edabb80be685f140972981dfbce67ceb83987ac1e6a4cf69447d99ba00b |
File details
Details for the file polyagamma-0.1.0-cp39-cp39-manylinux2010_x86_64.manylinux1_x86_64.whl
.
File metadata
- Download URL: polyagamma-0.1.0-cp39-cp39-manylinux2010_x86_64.manylinux1_x86_64.whl
- Upload date:
- Size: 525.1 kB
- Tags: CPython 3.9, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f60114af208dd15728d377b19c90adec068e926dcd46206bf1c98b03e59f5ec |
|
MD5 | 1d73d93309a548e8941bbd2734c3287e |
|
BLAKE2b-256 | cd9cfe292d72dae87c0aa36e610f3a1fe77b6a09c3ddac3ee8a3fc68ebd634da |
File details
Details for the file polyagamma-0.1.0-cp39-cp39-manylinux1_x86_64.whl
.
File metadata
- Download URL: polyagamma-0.1.0-cp39-cp39-manylinux1_x86_64.whl
- Upload date:
- Size: 427.8 kB
- Tags: CPython 3.9
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aac5bc2dfbed2012a35c239b96f4732808b8d7a171c8e39091e40e6b1a348261 |
|
MD5 | 58d095e87c4c163bc24ce5f951944733 |
|
BLAKE2b-256 | f1d0763f36fd8b632be39cae622152e886262267d1c1d7eff3ccfafa4a1589ca |
File details
Details for the file polyagamma-0.1.0-cp38-cp38-manylinux2014_x86_64.whl
.
File metadata
- Download URL: polyagamma-0.1.0-cp38-cp38-manylinux2014_x86_64.whl
- Upload date:
- Size: 583.9 kB
- Tags: CPython 3.8
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ff158fc7a689f46ac1ad777f9fe1930b244608b220dd0ceeb2ff9820fd19e8a |
|
MD5 | 622cfe966d2904d82d4a5a9f8024f160 |
|
BLAKE2b-256 | b4aaeb76a07d36874ffa3caa4699aca816ae82c218a1a4b188029b8d42b9a1b6 |
File details
Details for the file polyagamma-0.1.0-cp38-cp38-manylinux2010_x86_64.whl
.
File metadata
- Download URL: polyagamma-0.1.0-cp38-cp38-manylinux2010_x86_64.whl
- Upload date:
- Size: 542.6 kB
- Tags: CPython 3.8, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28ed5b8962bdf949377064e3626eced58dc3e89080dcc0b27d43458ceeb97765 |
|
MD5 | a07ec0d1bd341274ca1f43c919af9378 |
|
BLAKE2b-256 | 9d9063eb2b6b18c5177d35cdb8e3566e5c04ab212e3dda7862f001372235addc |
File details
Details for the file polyagamma-0.1.0-cp38-cp38-manylinux2010_x86_64.manylinux1_x86_64.whl
.
File metadata
- Download URL: polyagamma-0.1.0-cp38-cp38-manylinux2010_x86_64.manylinux1_x86_64.whl
- Upload date:
- Size: 542.6 kB
- Tags: CPython 3.8, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0cd3d51a6885f5285c65e9fae03493fb351ad64d4a2fcd6ed1c04f80c2e3465 |
|
MD5 | b994c9d2ad6cfaa25b21c43ee8503495 |
|
BLAKE2b-256 | eb1ffdbf4ce65907f6131418aba9f769608b948fcd0899bee38f3e0b812bd96c |
File details
Details for the file polyagamma-0.1.0-cp38-cp38-manylinux1_x86_64.whl
.
File metadata
- Download URL: polyagamma-0.1.0-cp38-cp38-manylinux1_x86_64.whl
- Upload date:
- Size: 435.8 kB
- Tags: CPython 3.8
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1938e51673e66050c347e61659d42f56412d2cc3f8a25a90c2f8753d044cd3eb |
|
MD5 | 31ced7c62bd8aba2516d8bfd3aeb90f9 |
|
BLAKE2b-256 | 73dbfaeec61a4f9b4989248043188a7a001c747b9b1edc9ee907ae9d25f5f227 |
File details
Details for the file polyagamma-0.1.0-cp37-cp37m-manylinux2014_x86_64.whl
.
File metadata
- Download URL: polyagamma-0.1.0-cp37-cp37m-manylinux2014_x86_64.whl
- Upload date:
- Size: 537.5 kB
- Tags: CPython 3.7m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91f24a964bfc138afe9ce87d12d5ba9f3ac2d708dd3e569c273cadd4bd507651 |
|
MD5 | 2fa38f66abff787decfc4d0df6222aa3 |
|
BLAKE2b-256 | 173cb3d1a5524dcd10efc4658ef7c1c19c88057d1c66dadf842cbcdb5626e3dd |
File details
Details for the file polyagamma-0.1.0-cp37-cp37m-manylinux2010_x86_64.whl
.
File metadata
- Download URL: polyagamma-0.1.0-cp37-cp37m-manylinux2010_x86_64.whl
- Upload date:
- Size: 498.2 kB
- Tags: CPython 3.7m, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1ad38242bb097d0ee8a468f7339014418c0de2b470fafa461d03601dae2a001 |
|
MD5 | c5f5932575855fa498ccef4fcd3b3950 |
|
BLAKE2b-256 | f58f8a84879b36a3362351ad05f4acc58bbc13f5cb5c1935d865a1f404608873 |
File details
Details for the file polyagamma-0.1.0-cp37-cp37m-manylinux2010_x86_64.manylinux1_x86_64.whl
.
File metadata
- Download URL: polyagamma-0.1.0-cp37-cp37m-manylinux2010_x86_64.manylinux1_x86_64.whl
- Upload date:
- Size: 498.2 kB
- Tags: CPython 3.7m, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb88eb8d5582b4b9e3bee957521eac65507378b516adbb889c5210f48ec394e4 |
|
MD5 | 63d62a80cdfbb5c0b1988ea38cd5c400 |
|
BLAKE2b-256 | 0cdab6b2356a12b932d1b813bbb3082203a450ddaf2943e653de33b38cf1227c |
File details
Details for the file polyagamma-0.1.0-cp37-cp37m-manylinux1_x86_64.whl
.
File metadata
- Download URL: polyagamma-0.1.0-cp37-cp37m-manylinux1_x86_64.whl
- Upload date:
- Size: 424.0 kB
- Tags: CPython 3.7m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ccb610499bc7fd052f6ee4a80caa39791ccdb00123c186e5509f9af4a87dd354 |
|
MD5 | 9efebb145c4eba01d99b4dde5c679ec6 |
|
BLAKE2b-256 | da7d21224f1ef9aa2892099e092be93497c45ffc344170e6dbe8495e374e7bb6 |
File details
Details for the file polyagamma-0.1.0-cp36-cp36m-manylinux2014_x86_64.whl
.
File metadata
- Download URL: polyagamma-0.1.0-cp36-cp36m-manylinux2014_x86_64.whl
- Upload date:
- Size: 536.6 kB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc323ec1755c6bbebb417874d33199c8348b27571b0ee66bdea37aa2fec2171f |
|
MD5 | f9f3c569d670de2f81ff973b0be59bfb |
|
BLAKE2b-256 | 9e5ea6737706bda590643bb1e7432c293baa032e9e92a66f57a1fc99c8069f8d |
File details
Details for the file polyagamma-0.1.0-cp36-cp36m-manylinux2010_x86_64.whl
.
File metadata
- Download URL: polyagamma-0.1.0-cp36-cp36m-manylinux2010_x86_64.whl
- Upload date:
- Size: 496.3 kB
- Tags: CPython 3.6m, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bfe0d4d48821a61c66a9893ce2bc2c66cd32683a3fc45f25487d0208269699d3 |
|
MD5 | 21e15e1753b21d8db17088e9bfb23ba9 |
|
BLAKE2b-256 | 4ec3da01da50c32f73c5f2046df4c566a654f013c4f302c58363613240392844 |
File details
Details for the file polyagamma-0.1.0-cp36-cp36m-manylinux1_x86_64.whl
.
File metadata
- Download URL: polyagamma-0.1.0-cp36-cp36m-manylinux1_x86_64.whl
- Upload date:
- Size: 425.9 kB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9fd47365d77ce74b2d2a1757f0092051a4953404fecf2e825d074e77c73e3cde |
|
MD5 | 9c5fcd22bbb856ce3b66785690bcabbf |
|
BLAKE2b-256 | a30d683c03a948d8bfd76e88405f79909108cbbba4714943183bb0ee1367eff2 |
File details
Details for the file polyagamma-0.1.0-cp36-cp36m-manylinux1_x86_64.manylinux2010_x86_64.whl
.
File metadata
- Download URL: polyagamma-0.1.0-cp36-cp36m-manylinux1_x86_64.manylinux2010_x86_64.whl
- Upload date:
- Size: 496.3 kB
- Tags: CPython 3.6m, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7ebac691212b08e3df3a28844f2f3d576ab90127d96c2927f64193943fe0ddd |
|
MD5 | 6af16f1730b87d18030918ed521cf333 |
|
BLAKE2b-256 | 3678dcb4f69a9e910162a561b1b9c1e65ab8ffba0d413b35f7dd3ce0bbc8126d |