Skip to main content

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)

Release files for ars-dev 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ars-dev 0.1.0
File Size Uploaded
ars_dev-0.1.0.tar.gz 7.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ars-dev 0.1.0
File Interpreter ABI Platform
ars_dev-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size:10.0 kB

Release files / ars_dev-0.1.0.tar.gz

Download URL ars_dev-0.1.0.tar.gz
Size 7.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d4c81b15184ab1e0e78862e91656e7152a2b80d598b8757ee014dd37b1b8baa0
BLAKE2b-256 checksum
How to use checksums
e6a7c2d7959e93ed383bbe76451dc29037826ed2ffac304277ed251a0e69de3d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.3

Release files / ars_dev-0.1.0-py3-none-any.whl

Download URL ars_dev-0.1.0-py3-none-any.whl
Size 3.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bb3b938e0900050c5dc90630ada513cad9e80e6e3c623022819b9a54933c08b0
BLAKE2b-256 checksum
How to use checksums
0aa6ce2fa0dca16f4fb3bc291bd5438c921b80616de7292b22dc1908efb2f8bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page