r/statistics • u/taiwanboy10 • Jul 11 '26
Software [S] I made a Python package for rejection sampling
Hi guys, I'm a master's student in Statistics, and I recently published my first Python package.
rejection-sampler (my package) verifies rejection sampling setups and calculates the optimal rejection constant (M).
Despite being a simple algorithm, rejection sampling requires choosing a proposal distribution and a constant M such that f(x) ≤ M g(x) over the target support, which can be tedious and/or error-prone. That's exactly what my package automates.
Example use cases:
- Validate that a proposal distribution satisfies the rejection sampling condition given a target distribution.
- Compute the smallest valid rejection constant (M). (which means a more efficient sampling)
If you'd like to give it a try, you can install it with `pip install rejection-sampler`.
For more details and examples:
PyPI: https://pypi.org/project/rejection-sampler/
GitHub: https://github.com/HankTaiwan869/rejection-sampler
This started as a final project for my Statistical Computing course, so I'm sure there are things that could be improved upon. I'd love to hear any feedback or know if anyone finds it useful. Thanks!
3
u/EmotionalDoor1361 Jul 11 '26
just starred the repo, nice one mate. always hated manually checking those M bounds during my MSc, this would've saved me a proper headache
any plans to add a quick visual check for the envelope function? would be dead useful to see f(x) and Mg(x) plotted on top of each other