Probabilistic programming with arrays of Gaussian variables.
Project description
gprob
gprob is a python package that implements a probabilistic programming language for Gaussian random variables with exact conditioning. It is built around the idea that arrays of Gaussian random variables can be handled in the same way as numerical numpy arrays.
To give a flavor of it, the first example shows a few operations on scalar variables and conditioning
>>> import gprob as gp
>>> x = gp.normal()
>>> y = gp.normal()
>>> z = x + 0.2 * y + 3
>>> z
Normal(mean=3, var=1.04)
>>> z | {y - 0.5 * x: 1} # conditioning
Normal(mean=2.76, var=0.968)
The second example is the construction of a random walk of a Brownian particle observed in the beginning at x=0 and midway through its motion at x=1,
>>> nstep = 5 * 10**3
>>> dx = gp.normal(0, 1/nstep, size=(nstep,))
>>> x = gp.cumsum(dx, 0) # unconditional particle positions
>>> xc = x | {x[nstep//2]: 1} # positions conditioned on x[nstep//2] == 1
>>> samples = xc.sample(10**2) # sampling 100 trajectories
>>> import matplotlib.pyplot as plt
>>> plt.plot(samples.T, alpha=0.1, color='gray')
>>> plt.show()
Requirements
Installation
The package can be installed from PyPI,
pip install gprob
or from this repository (to get the latest version),
pip install git+https://github.com/SAFedorov/gprob.git
Getting started
Have a look at the notebooks in the examples folder, starting from the tutorials on
roughly in this order.
How it works
There is a supplementary note that presents some of the underying theory, especially the theory of inference.
How many variables it can handle
General multivariate Gaussian distributions of n variables require memory quadratic in n for their storage, and computational time cubic in n for their exact conditioning. My laptop can typically handle arrays whose sizes count in thousands.
If the Gaussian variables are such that their joint distribution is a direct product, they can be packed into sparse arrays. For those, memory and computational requirements grow linearly with the number of independent distributions, and the total number of variables can be larger.
Acknowledgements
gprob was inspired by (but works differently from) GaussianInfer. See the corresponding paper,
D. Stein and S. Staton, "Compositional Semantics for Probabilistic Programs with Exact Conditioning," 2021 36th Annual ACM/IEEE Symposium on Logic in Computer Science (LICS), Rome, Italy, 2021, pp. 1-13, doi: 10.1109/LICS52264.2021.9470552 .
gprob uses the subscript parser from opt-einsum. Some linearization tricks and choices of tooling follow autograd.
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 Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gprob-1.0.1.tar.gz.
File metadata
- Download URL: gprob-1.0.1.tar.gz
- Upload date:
- Size: 77.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0dcd433ee188e41f523fbb00504b72bb2c4c9b1f3abea65909c67c1875fa6a87
|
|
| MD5 |
9aed3fa8229b1b60259ddb3fa74120d4
|
|
| BLAKE2b-256 |
e2299443ff2a5d2f1aad67b2827b3028c9cd088c44edb42e640417a19d9fc567
|
File details
Details for the file gprob-1.0.1-py3-none-any.whl.
File metadata
- Download URL: gprob-1.0.1-py3-none-any.whl
- Upload date:
- Size: 39.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
168fdf76ad5cf952d9e6b477685c489fa4df24eb331593c8998788f1d2b2d773
|
|
| MD5 |
bb8a664acf6ffcb56dfd4b8b6d2f91b9
|
|
| BLAKE2b-256 |
dd2202d26d384af7de4c321c6422544d322c0cd2f2e87b7b1a7a2ab9ce2444b6
|