A Python package for Ratio-of-Uniforms sampling.
Project description
rusampling
lynnejewson.github.io/rusampling
A Python package for Ratio-of-Uniforms sampling in multiple dimensions.
Ratio-of-Uniforms is a method of sampling random variables that uses the pdf, which does not need to be normalised, and requires minimal setup.
Install from the terminal with pip install RUSampling.
Development of this package was funded by the Lighthill Risk Network: https://lighthillrisknetwork.org.
Many thanks to Paul Northrop, the author of RUST, the package for Ratio-of-Uniforms sampling in R, and who helped me with the development of this project.
Usage
- Create an instance of the Ru class, passing the log-pdf logf, the dimension d (default 1), and any extra arguments that the log-pdf takes.
- Call this object's rvs method, passing the number of samples n to generate. This returns a (n, d)- dimensional numpy array of samples.
Example: Sampling the log-normal distribution
import numpy as np
import scipy
from ru import Ru
logf = scipy.stats.lognorm.logpdf
t = Ru(logf, s=1)
samples = t.rvs(n=100000)
t.plot()
Project details
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 rusampling-0.0.3.tar.gz.
File metadata
- Download URL: rusampling-0.0.3.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2cf1fbe3f93cce46541b7c2532e325297b6d4995ea3fff170c2bdb9583b03cf5
|
|
| MD5 |
b189a975bc4e5c6b4dc1faf9fa6a6e0f
|
|
| BLAKE2b-256 |
4942423b382956eea937e1d02fbe9b1f71f81d455923db5c5070eb7d1f6e747c
|
File details
Details for the file rusampling-0.0.3-py3-none-any.whl.
File metadata
- Download URL: rusampling-0.0.3-py3-none-any.whl
- Upload date:
- Size: 12.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0675286f9f7d2d4a818fc4c138e747682137b46c9467dcbc6589525b3f6d479e
|
|
| MD5 |
2d3cadcabf794b444ee4ee404b98f9b5
|
|
| BLAKE2b-256 |
e29ad1a687ba7890c18e78a3109b53e5b3d618f01f710f288d0b4cd1b387dfb6
|