Skip to main content
Help us improve PyPI by participating in user testing. All experience levels needed!

sampling from univariate distributions

Project description

samplepy implements three sampling methods for univariate distributions. The package includes:

  • Importance sampling: samplepy.Importance
  • Rejection sampling: samplepy.Rejection
  • Metropolis-Hastings sampling: samplepy.MH


from samplepy import Rejection
import matplotlib.pyplot as plt
import numpy as np

Rejection sampling example from 2 different functions
# define a unimodal function to sample under
f = lambda x: 2.0*np.exp(-2.0*x)
rej = Rejection(f, [0.01, 3.0])  # instantiate Rejection sampling with f and interval
sample = rej.sample(10000, 1)    # create a sample of 10K points

x = np.arange(0.01, 3.0, (3.0-0.01)/10000)
fx = f(x)

figure, axis = plt.subplots()
axis.hist(sample, normed=1, bins=40)
axis2 = axis.twinx()
axis2.plot(x, fx, 'g', label="f(x)=2.0*exp(-2*x)")

More examples and package documentation can be found at <>


pip install samplepy

Project details

Release history Release notifications

This version
History Node


History Node


History Node


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date (147.4 kB) Copy SHA256 hash SHA256 Source None Oct 3, 2016

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page