Skip to main content

mcsamplers

Monte-Carlo stochastic samplers for gravitational-wave parameter estimation: nested sampling and MCMC, built around a small Model base class that you subclass with your own likelihood.

pip install mcsamplers

Requires Python 3.11+.

The Model contract

Everything here works against one abstraction. Subclass Model, implement evaluate_logliklihood, and the reduced-coordinate machinery comes with it: the samplers explore the unit cube [0, 1]^ndim, and Model maps those points onto your physical priors before calling you.

import numpy as np
from mcsamplers.model import Model

class Gaussian(Model):
    def evaluate_logliklihood(self, parameters):
        return -0.5 * float(np.sum(np.asarray(parameters) ** 2))

model = Gaussian(
    xdata=np.linspace(0, 1, 64),
    ydata=np.zeros(64),
    initial_guess=[0.5, 0.5],
    parameter_priors_dict={"a": [0.0, 2.0], "b": [-1.0, 1.0]},
)

# Unit cube in, physical parameters out: (0.5, 0.5) -> (1.0, 0.0)
model.evaluate_logliklihood_reduced(np.array([0.5, 0.5]))

Priors are uniform boxes given as {name: [min, max]}. Model also supplies evaluate_liklihood, ln_prior_probability, pushforward_samples and the pickle round trip the samplers use for checkpointing.

Nested sampling

from mcsamplers.nested.sampler import NestedSampler

sampler = NestedSampler(n_live=500, n_dim=2, n_iter=5000, Model=model)
sampler.run()

samples = sampler.posterior_samples
log_z = sampler.logevidence

New live points are drawn according to random_sample_method, one of prior, mcmc, random-distance or relative-centroid. Runs can be checkpointed and resumed with restart=True and checkpoint_time_stamps.

MCMC

mcsamplers.markov_chain.yumcee is a Metropolis–Hastings sampler with multiple walkers:

from mcsamplers.markov_chain.yumcee import yumcee_run

samples = yumcee_run(loglik, iguess, ndim, nwalkers, nsteps, prop_sigma)

yumcee_p is a parallel variant intended to run across nodes, and yumcee_utils holds autocorrelation, corner-plot and sample-statistics helpers.

Tests

pip install mcsamplers[opt]
pytest --pyargs mcsamplers.tests

Status and caveats

This is research code — used in anger, but not hardened for general use. The test suite pins the Model contract, not sampling correctness: the samplers themselves have no numerical regression tests.

Licence

MIT. See LICENSE.

Download files

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

Source Distribution

mcsamplers-2026.9.4.tar.gz (312.7 kB view details)

Uploaded Source

Built Distribution

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

mcsamplers-2026.9.4-py3-none-any.whl (31.0 kB view details)

Uploaded Python 3

File details

Details for the file mcsamplers-2026.9.4.tar.gz.

File metadata

  • Download URL: mcsamplers-2026.9.4.tar.gz
  • Upload date:
  • Size: 312.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.12.14

File hashes

Hashes for mcsamplers-2026.9.4.tar.gz
Algorithm Hash digest
SHA256 6c0131d29b7e25f7f9a71a205e9e620454061f76853716a8930c1bac5932b53e
MD5 b712843314d3cf9038544595eecacfe2
BLAKE2b-256 37fa61401f6976aee725d8928f3da43e87b769c5fe66caecdf3ca9d98eeaf309

See more details on using hashes here.

File details

Details for the file mcsamplers-2026.9.4-py3-none-any.whl.

File metadata

  • Download URL: mcsamplers-2026.9.4-py3-none-any.whl
  • Upload date:
  • Size: 31.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.12.14

File hashes

Hashes for mcsamplers-2026.9.4-py3-none-any.whl
Algorithm Hash digest
SHA256 32ab00b5a61e1df8d32f7ee57d2ecc20a2a11aac25ca2a9a556082411ce2a7a5
MD5 666da468b9972a21afd99c42889eb9b3
BLAKE2b-256 24e81d100afa60785b916efe430134a2fc27f41b3a458fa562e6d4f0541d9fac

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

2026.9.4 This release

2 files

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