Variational Inference for Mixtures of Gamma Distributions
This package implements variational inference for mixtures of gamma distributions. For more information, see Comparing Markov Chain Monte Carlo and Variational Methods for Bayesian Inference on Mixtures of Gamma Distributions.
Two parameterisations of the gamma distribution are available: the shape-rate parameterisation and the shape-mean parameterisation. The shape-mean parameterisation is recommended since it generally produces superior posterior approximations and predictive distributions.
Getting Started
Prerequisites
python>=3.6
tensorflow>=2.0
tensorflow_probability>=0.8
Installing
I recommend installing using pip as it will also install the prerequisites. Run
pip install mix_gamma_vi
Example
This is an example of posterior inference on a mixture of two gamma distributions under the shape-mean parameterisation. Suppose we have a one-dimensional tensor x of data.
# import mix_gamma_vi function
from mix_gamma_vi import mix_gamma_vi
# Fit a model
fit = mix_gamma_vi(x, K=2)
# Get the fitted distribution
distribution = fit.distribution()
# Print the means of the parameters under the fitted distribution
distribution.mean()
{'pi': <tf.Tensor: id=4201, shape=(1, 2), dtype=float32, numpy=array([[0.50948393, 0.49051604]], dtype=float32)>,
'beta': <tf.Tensor: id=4208, shape=(1, 2), dtype=float32, numpy=array([[1.0013412, 1.9965338]], dtype=float32)>,
'alpha': <tf.Tensor: id=4212, shape=(1, 2), dtype=float32, numpy=array([[20.712543, 82.77388 ]], dtype=float32)>}
We can sample from this distribution by calling distribution.sample().
For a more in-depth example, see example.py.
Performance Tip
To avoid retracing the tensor graph every time you change the parameters, pass them as TensorFlow constants. e.g. instead of the above, do
fit = mix_gamma_vi(x, K=tf.constant(2))
Authors
This work is submitted by Isaac Breen in partial fulfillment of the requirements for the Bachelor of Science degree with Honours at the University of Western Australia. Supervised by John Lau and Edward Cripps.
License
This project is licensed under the MIT License - see the LICENSE.md file for details
Metadata
Release files for mix-gamma-vi 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mix_gamma_vi-0.0.1.tar.gz | 5.8 kB | Without provenance | Details for mix_gamma_vi-0.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mix_gamma_vi-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for mix_gamma_vi-0.0.1-py3-none-any.whl |
Total release size: 12.7 kB
Release files / mix_gamma_vi-0.0.1.tar.gz
| Download URL | mix_gamma_vi-0.0.1.tar.gz |
|---|---|
| Size | 5.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
85393e193af857dbd787f16bbe637ce34ffe215259867a79b6c926556f58fe8a
|
|
BLAKE2b-256 checksum How to use checksums |
b18548981099b3368b8168c0bfd61de555448a260510d80c703c4425b050a698
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.1
|
Release files / mix_gamma_vi-0.0.1-py3-none-any.whl
| Download URL | mix_gamma_vi-0.0.1-py3-none-any.whl |
|---|---|
| Size | 7.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c62d6d854edaeeee0b1a722feae091cec02d77371995bd3b3281bfe5aae9ee06
|
|
BLAKE2b-256 checksum How to use checksums |
cae1bf705a53dc56fea205bcefd758e873e0dbea3135b06803a4042d26514647
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.1
|
Security for mix-gamma-vi 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.