Skip to main content

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

  • Importance sampling: samplepy.Importance

  • Rejection sampling: samplepy.Rejection

  • Metropolis-Hastings sampling: samplepy.MH

Examples:

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)")
plt.legend(loc=1)
plt.show()

More examples and package documentation can be found at <https://github.com/elena-sharova/samplepy/blob/master/README.rst>

Installation

pip install samplepy

Download files

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

Source Distribution

samplepy-1.0.11.zip (147.4 kB view details)

Uploaded Source

File details

Details for the file samplepy-1.0.11.zip.

File metadata

  • Download URL: samplepy-1.0.11.zip
  • Upload date:
  • Size: 147.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for samplepy-1.0.11.zip
Algorithm Hash digest
SHA256 c739952aab59bd920f8d28e3aa81a2ce310465d114618d7fc3e2927dcdb8b63b
MD5 754df59102a5324f1086344b0fccc92f
BLAKE2b-256 77be186d0ba711a1cc4a46ec6171b1a3d63e6850edf7a61c3591b726cd27d9af

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.11 This release

1 file

1.0.10

1 file

1.0.9

1 file

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