Skip to content

mj-will/minipcn

Repository files navigation

minipcn

DOI

A minimalistic implementation of preconditioned Crank-Nicolson MCMC sampling.

Installation

minipcn can be installed using from PyPI using pip:

pip install minipcn

Usage

The basic usage is:

from minipcn import Sampler
import numpy as np

log_prob_fn = ...    # Log-probability function - must be vectorized
dims = ...    # The number of dimensions
rng = np.random.default_rng(42)

sampler = Sampler(
    log_prob_fn=log_prob_fn,
    dims=dims,
    step_fn="pcn",    # Or tpcn
    rng=rng,
)

# Generate initial samples
x0 = rng.randn(size=(100, dims)

# Run the sampler
chain, history = sampler.run(x0, n_steps=500)

For a complete example, see the examples directory.

About

A minimalistic preconditioned Crank-Nicolson MCMC sampler

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages