Skip to main content

Efficiently sample from the Polya-Gamma distribution using NumPy's Generator interface

Project description

polya-gamma

Efficiently generate samples from the Polya-Gamma distribution using a NumPy/SciPy compatible interface. densities

Features

  • polyagamma is written in C and optimized for performance.
  • It is flexible and allows the user to sample using one of 4 available methods.
  • Input parameters can be scalars, arrays or both; allowing for easy generation of multi-dimensional samples without specifying the size.
  • Random number generation is thread safe.
  • The functional API resembles that of common numpy/scipy functions, therefore making it easy to plugin to existing libraries.

Dependencies

  • Numpy >= 1.17

Installation

To get the latest version of the package, one can install it by downloading the wheel/source distribution from the releases page, or using pip with the following shell command:

$ pip install -U polyagamma

Alternatively, once can install from source by cloning the repo. This requires an installation of poetry and the following shell commands:

$ git clone https://github.com/zoj613/polya-gamma.git
$ cd polya-gamma/
$ poetry install
# add package to python's path
$ export PYTHONPATH=$PWD:$PYTHONPATH 

Example

Python

import numpy as np
from polyagamma import polyagamma

o = polyagamma()

# Get a 5 by 10 array of PG(1, 2) variates.
o = polyagamma(z=2, size=(5, 10))

# Pass sequences as input. Numpy's broadcasting rules apply here.
h = [[1, 2, 3, 4, 5], [9, 8, 7, 6, 5]]
o = polyagamma(h, 1)

# Pass an output array
out = np.empty(5)
polyagamma(out=out)
print(out)

# one can choose a sampling method from {devroye, alternate, gamma, saddle}.
# If not given, the default behaviour is a hybrid sampler that picks a method
# based on the parameter values.
o = polyagamma(method="saddle")

# We can also use an existing instance of `numpy.random.Generator` as a parameter.
# This is useful to reproduce samples generated via a given seed.
rng = np.random.default_rng(12345)
o = polyagamma(random_state=rng)

C

For an example of how to use polyagamma in a C program, see here.

Contributing

All contributions, bug reports, bug fixes, documentation improvements, enhancements, and ideas are welcome.

To submit a PR, follow the steps below:

  1. Fork the repo.
  2. Setup the dev environment with poetry install. All dependencies will be installed.
  3. Start writing your changes, including unittests.
  4. Once finished, run make install to build the project with the new changes.
  5. Once build is successful, run tests to make sure they all pass with make test.
  6. Once finished, you can submit a PR for review.

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


Download files

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

Source Distribution

polyagamma-1.0.0.tar.gz (139.1 kB view details)

Uploaded Source

Built Distributions

polyagamma-1.0.0-cp39-cp39-manylinux2014_x86_64.whl (556.7 kB view details)

Uploaded CPython 3.9

polyagamma-1.0.0-cp39-cp39-manylinux2010_x86_64.whl (518.3 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64

polyagamma-1.0.0-cp39-cp39-manylinux1_x86_64.whl (417.1 kB view details)

Uploaded CPython 3.9

polyagamma-1.0.0-cp39-cp39-manylinux1_x86_64.manylinux2010_x86_64.whl (518.3 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64

polyagamma-1.0.0-cp38-cp38-manylinux2014_x86_64.whl (539.1 kB view details)

Uploaded CPython 3.8

polyagamma-1.0.0-cp37-cp37m-manylinux2014_x86_64.whl (526.2 kB view details)

Uploaded CPython 3.7m

polyagamma-1.0.0-cp37-cp37m-manylinux2010_x86_64.whl (487.0 kB view details)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64

polyagamma-1.0.0-cp37-cp37m-manylinux2010_x86_64.manylinux1_x86_64.whl (487.0 kB view details)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64

polyagamma-1.0.0-cp37-cp37m-manylinux1_x86_64.whl (417.3 kB view details)

Uploaded CPython 3.7m

polyagamma-1.0.0-cp36-cp36m-manylinux2014_x86_64.whl (524.7 kB view details)

Uploaded CPython 3.6m

polyagamma-1.0.0-cp36-cp36m-manylinux2010_x86_64.whl (486.3 kB view details)

Uploaded CPython 3.6m manylinux: glibc 2.12+ x86-64

polyagamma-1.0.0-cp36-cp36m-manylinux2010_x86_64.manylinux1_x86_64.whl (486.3 kB view details)

Uploaded CPython 3.6m manylinux: glibc 2.12+ x86-64

polyagamma-1.0.0-cp36-cp36m-manylinux1_x86_64.whl (416.6 kB view details)

Uploaded CPython 3.6m

File details

Details for the file polyagamma-1.0.0.tar.gz.

File metadata

  • Download URL: polyagamma-1.0.0.tar.gz
  • Upload date:
  • Size: 139.1 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

Hashes for polyagamma-1.0.0.tar.gz
Algorithm Hash digest
SHA256 4fca25298f03f3f549e05bee3cdc6c8eae78f725f6dc14481d19b9fd0d67382b
MD5 2766757df6e75521f68847426a325e62
BLAKE2b-256 0f55b56e79c48d54253de0ba0d3b51f848b1c573f9ce76011abd691111d9f4f1

See more details on using hashes here.

File details

Details for the file polyagamma-1.0.0-cp39-cp39-manylinux2014_x86_64.whl.

File metadata

  • Download URL: polyagamma-1.0.0-cp39-cp39-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 556.7 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

Hashes for polyagamma-1.0.0-cp39-cp39-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6fac5f063361a69792f05dc3ba74e609389ba8479ff495b359331559d9d46d1c
MD5 eec84bb9d48f0ae125214e705fd00fe1
BLAKE2b-256 483c0dd920f01c9ad4afef00984977e0a4179fcc524772d259cf9b7e87301fad

See more details on using hashes here.

File details

Details for the file polyagamma-1.0.0-cp39-cp39-manylinux2010_x86_64.whl.

File metadata

  • Download URL: polyagamma-1.0.0-cp39-cp39-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 518.3 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

Hashes for polyagamma-1.0.0-cp39-cp39-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 afcaa9d523734f154388a08cb40af6dbeb705f420ed7d99d8124c47ecd05ac7d
MD5 786ce66ebc8b7ac0ef1e543a594fef2b
BLAKE2b-256 66b97a356dc89e82dd5fa26ceaa73eaea1afa224d08bd31eb6d0b8699ea38ca6

See more details on using hashes here.

File details

Details for the file polyagamma-1.0.0-cp39-cp39-manylinux1_x86_64.whl.

File metadata

  • Download URL: polyagamma-1.0.0-cp39-cp39-manylinux1_x86_64.whl
  • Upload date:
  • Size: 417.1 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

Hashes for polyagamma-1.0.0-cp39-cp39-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 e1fc5bdbcc1e37b7657e4554aaf84c27f3a34fac3e9dce87726857663386582f
MD5 d4879b312e08b03e3c9ae7ab086f8e3d
BLAKE2b-256 462aad7784cb9a72d33c7aabbf9b4d80fe4e59251ef6cc0d387e0856b1697c71

See more details on using hashes here.

File details

Details for the file polyagamma-1.0.0-cp39-cp39-manylinux1_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for polyagamma-1.0.0-cp39-cp39-manylinux1_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 f8466af0c1b03b7edd82211a805abe540e3e52713a97f9d8a9244100fda96ae8
MD5 ebe5db4fbbae03c5c8a1d707aed27403
BLAKE2b-256 0bb179a536fa97ea207f43872f789e4664dadc6d4755c2237b73761fe3c95d98

See more details on using hashes here.

File details

Details for the file polyagamma-1.0.0-cp38-cp38-manylinux2014_x86_64.whl.

File metadata

  • Download URL: polyagamma-1.0.0-cp38-cp38-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 539.1 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

Hashes for polyagamma-1.0.0-cp38-cp38-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e3d6213255cca979b0e79cf3a29730d458c73fb0766f19d0135270c2f5dc34e3
MD5 21e200cbf4d43e2ab6da9039ee32fe98
BLAKE2b-256 73b8d38062810810e3a3c12476c6ccb027b60529154d0e2ef53d03825c893604

See more details on using hashes here.

File details

Details for the file polyagamma-1.0.0-cp37-cp37m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: polyagamma-1.0.0-cp37-cp37m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 526.2 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

Hashes for polyagamma-1.0.0-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 622f8fb41141910a991816b62f463e89f784cc6e6f1061ab32df05b5c8ca6309
MD5 27e14a40af17b4391a413e2d8ede09ea
BLAKE2b-256 f775c585e6235dd2b8179d138facb30ddd56b4d0a26b01e3287a158d71fe548d

See more details on using hashes here.

File details

Details for the file polyagamma-1.0.0-cp37-cp37m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: polyagamma-1.0.0-cp37-cp37m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 487.0 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

Hashes for polyagamma-1.0.0-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 97764888b840af40b047c78856bc7fd4f5a560e13d41f460808c67f21e760900
MD5 3233bca96b2b254d8c8b76ba6d95d41f
BLAKE2b-256 d7b48ed5a54488019f0753b9afcbdaba3421bf9ccf611df8a3c7f9ee5194d436

See more details on using hashes here.

File details

Details for the file polyagamma-1.0.0-cp37-cp37m-manylinux2010_x86_64.manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for polyagamma-1.0.0-cp37-cp37m-manylinux2010_x86_64.manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 6fdee4d313a57c631b14d0cd764752e2fbf65f71ebeee832e0d12bdb68f3a5e9
MD5 9bbc92c31487a4fdef2673b0a7a7e6e4
BLAKE2b-256 a09fcc8b89002f74c859b76fcfdafb921c9d161faddd1b01cc8a5bacfe161290

See more details on using hashes here.

File details

Details for the file polyagamma-1.0.0-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

  • Download URL: polyagamma-1.0.0-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 417.3 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

Hashes for polyagamma-1.0.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 8975cdbb8322a2f24d163560fc0e55301170175d8ca23d96ee60bf49955371f3
MD5 33a8f5914f60cd679e1397f439e68eef
BLAKE2b-256 9b6959f01e2f4de396e1f3d9c924346868ff7a26ca1b5ef7d53cc29005e20d3d

See more details on using hashes here.

File details

Details for the file polyagamma-1.0.0-cp36-cp36m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: polyagamma-1.0.0-cp36-cp36m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 524.7 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

Hashes for polyagamma-1.0.0-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6b22063aaa5b1f559f07c7e70571f577c224c8aad31d316ce08fe5fbae2cb2ae
MD5 b5b0df820c5ee2174e28ac90c0e046c5
BLAKE2b-256 7648e9861771f2ccb3484efcf69ec074abf36bc18610e9b199bd75ec1a4d3e1f

See more details on using hashes here.

File details

Details for the file polyagamma-1.0.0-cp36-cp36m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: polyagamma-1.0.0-cp36-cp36m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 486.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

Hashes for polyagamma-1.0.0-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 6217d022b65990cbd0d0d5d270d62b750ee047812609049a19eea1ad81c41c49
MD5 5a19156494c5410868e8064ccfda6cca
BLAKE2b-256 3df2cce933a1c70c19a7bc68270ba300d8efbbc30c5b13874b4597a6687c418d

See more details on using hashes here.

File details

Details for the file polyagamma-1.0.0-cp36-cp36m-manylinux2010_x86_64.manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for polyagamma-1.0.0-cp36-cp36m-manylinux2010_x86_64.manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 e43e4875fb0c9976e31d5d316e9150aac18ac2399c89070bc288bd59caf12170
MD5 ee73f0e81363a5601a79019e50686ece
BLAKE2b-256 41afa585afd5420f931387c6b3cccaae12f5b5df906224fe2ed966ed9effc8e9

See more details on using hashes here.

File details

Details for the file polyagamma-1.0.0-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

  • Download URL: polyagamma-1.0.0-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 416.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

Hashes for polyagamma-1.0.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 1b5c33f47b9583495ba44307f0ee3163ef2732337bc7839479b4ce76f765c5f6
MD5 72f270d18042160e5f709a5123c6ece5
BLAKE2b-256 4be80485caceb6d97930f8b9c0cf16d4178dab033d2497d9defa7337c5d4ba29

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