A JAX/numpy implementation of Adaptive Rejection Sampling (ARS) introduced by Gilks and Wild in 1992
Project description
Ars-dev
Ars-dev is a Python package designed for adaptive rejection sampling(ARS). This implementation references Adaptive Rejection Sampling for Gibbs Sampling(Gilks et al. 1992).
Installation
First clone this project locally with git
git clone https://github.berkeley.edu/yoshi-chiu/ars-dev.git
Then you can install the package via pip. First move in the directory, then run pip.
cd ars-dev/
python -m pip install .
Quick Start
Here is an example on how to run the package.
from ars import ars
from scipy.stats import norm
import numpy as np
domain = (-np.inf, np.inf)
n_samples = 10000
samples = ars(pdf=norm.pdf, domain=domain, n_samples=n_samples, is_logpdf=False, verbose=True)
The function also accepts pdf functions built with JAX. In that case, jax automatic differentiation is used in the sampling
from ars import ars
import jax.numpy as jnp
target_pdf = lambda x: jnp.exp(-x**2 / 2)
domain = (-jnp.inf, jnp.inf)
samples = ars(pdf=target_pdf, domain=domain, n_samples=1000, is_logpdf=False, verbose=True)
A function test_ars is also provided to run tests on easy to compute pdfs
from ars import test_ars
from scipy.stats import norm
import numpy as np
domain = (-np.inf, np.inf)
n_samples = 10000
samples, obj, fig = test_ars(pdf=norm.pdf, domain=domain, n_samples=n_samples, verbose=False)
Running Unit tests
To run all the unit tests, first move in the project directory then run pytest
pytest
Documentation
Documentation can be found at https://github.berkeley.edu/yoshi-chiu/ars-dev/blob/main/docs/report.pdf
License
This project is licensed under the MIT License.
(To be deleted)
Setup (For us)
Run this to install the package in editable mode
python -m pip install -e .
Running the function
TODO
- JIT ? (TBD)
- write testing for all non-trivial functions (Jordan)
- Setup as a package (Hongyu)
- write a README on the easy setup and initial simple examples (Hongyu)
- Write documentation, especially the main function with some simple examples (Yoshi)
- write a report documet explaining the implementation approach (Jordan for a good part of it)
- Add tests explanation and examples in report (Yoshi)
- Add in results plots and examples in report (Jordan, Yoshi)
- Improve the update of the arrays to avoid recomputing everything (not faster)
- Update code for non-jax functions (Jordan)
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 ars_dev-0.1.0.tar.gz.
File metadata
- Download URL: ars_dev-0.1.0.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d4c81b15184ab1e0e78862e91656e7152a2b80d598b8757ee014dd37b1b8baa0
|
|
| MD5 |
b9ee977d791579e60d1b98ea7a1377e6
|
|
| BLAKE2b-256 |
e6a7c2d7959e93ed383bbe76451dc29037826ed2ffac304277ed251a0e69de3d
|
File details
Details for the file ars_dev-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ars_dev-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb3b938e0900050c5dc90630ada513cad9e80e6e3c623022819b9a54933c08b0
|
|
| MD5 |
18cef381d794d471482fc2a403de4233
|
|
| BLAKE2b-256 |
0aa6ce2fa0dca16f4fb3bc291bd5438c921b80616de7292b22dc1908efb2f8bd
|