Skip to main content

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

rusampling-0.0.5.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rusampling-0.0.5-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file rusampling-0.0.5.tar.gz.

File metadata

  • Download URL: rusampling-0.0.5.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

Hashes for rusampling-0.0.5.tar.gz
Algorithm Hash digest
SHA256 2104b9583930de980474edc4c7f2e2b67ce9583bc3efdf93cc3984b19650d944
MD5 d959f5d4235a5c5e820e9724d2c6eb2e
BLAKE2b-256 3b86dd093605122b7dce5277d72c57bfb3bcd5f5db500b4b07e752d0b2eaf32f

See more details on using hashes here.

File details

Details for the file rusampling-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: rusampling-0.0.5-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

Hashes for rusampling-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 6247fb6cf5c2343a74c15eca811811953d7f704085df1eb1fa958268283a500d
MD5 d734da54b635b5163ead67cbd27bb0d0
BLAKE2b-256 0d35abaaa4b658569a7b5de5d5a3fa4bf1b1ab183f616afc9c434dcb3e51564b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page