A minimal preconditioned Crank-Nicolson MCMC sampler
Project description
minipcn
A minimal 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.
Support for array-api
minipcn also supports different array API backends via array-api-compat
and orng for random number generation. These can be installed by running
pip install minicpn[array-api]
Usage is then similar to when using numpy, except one must use the RNG from
orng and specify the backend via xp:
from minipcn import Sampler
from orng import ArrayRNG
import torch
log_prob_fn = ... # Log-probability function - must be vectorized
dims = ... # The number of dimensions
rng = ArrayRNG(backend="torch", seed=42)
sampler = Sampler(
log_prob_fn=log_prob_fn,
dims=dims,
step_fn="pcn", # Or tpcn
rng=rng,
xp=torch,
)
# Generate initial samples
x0 = rng.randn(size=(100, dims))
# Run the sampler
chain, history = sampler.run(x0, n_steps=500)
Note: this still uses numpy when initializing the tpcn kernel.
Citing minipcn
If you use minipcn in your work, please cite our DOI
If using the tpcn kernel, please also cite Grumitt et al
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file minipcn-0.2.0a1.tar.gz.
File metadata
- Download URL: minipcn-0.2.0a1.tar.gz
- Upload date:
- Size: 14.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a0cdf0133e4f787202b3fe1e136c80d97c86fe274f7e9224aaffbe28eb3fbbee
|
|
| MD5 |
ddb7faa8819d4b1afcd2aeb9992490f9
|
|
| BLAKE2b-256 |
97f60583bf295b3601c65c5c5fa27cbd11538648be04dc47939c87975bd77597
|
Provenance
The following attestation bundles were made for minipcn-0.2.0a1.tar.gz:
Publisher:
publish.yml on mj-will/minipcn
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
minipcn-0.2.0a1.tar.gz -
Subject digest:
a0cdf0133e4f787202b3fe1e136c80d97c86fe274f7e9224aaffbe28eb3fbbee - Sigstore transparency entry: 682495864
- Sigstore integration time:
-
Permalink:
mj-will/minipcn@942d56c1734c021c0eb7f2182cd0438b7daa51a1 -
Branch / Tag:
refs/tags/v0.2.0a1 - Owner: https://github.com/mj-will
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@942d56c1734c021c0eb7f2182cd0438b7daa51a1 -
Trigger Event:
release
-
Statement type:
File details
Details for the file minipcn-0.2.0a1-py3-none-any.whl.
File metadata
- Download URL: minipcn-0.2.0a1-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
38bb7bfcccd604666fc5578d2b1206a2d48fc1f2731a96e3c166eed59dd3623f
|
|
| MD5 |
f1e71e99dd2c93685e7ab489cb589f16
|
|
| BLAKE2b-256 |
130a18045fcc60ecf3b08f9e2ce29f8f14daed226ccc507741be4edba9400f3f
|
Provenance
The following attestation bundles were made for minipcn-0.2.0a1-py3-none-any.whl:
Publisher:
publish.yml on mj-will/minipcn
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
minipcn-0.2.0a1-py3-none-any.whl -
Subject digest:
38bb7bfcccd604666fc5578d2b1206a2d48fc1f2731a96e3c166eed59dd3623f - Sigstore transparency entry: 682495888
- Sigstore integration time:
-
Permalink:
mj-will/minipcn@942d56c1734c021c0eb7f2182cd0438b7daa51a1 -
Branch / Tag:
refs/tags/v0.2.0a1 - Owner: https://github.com/mj-will
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@942d56c1734c021c0eb7f2182cd0438b7daa51a1 -
Trigger Event:
release
-
Statement type: