Nutpie for Stan or PyMC Models

0.16.8 · active · verified Fri Apr 17

Nutpie is a Python library designed to sample Stan or PyMC models efficiently, leveraging JAX for high-performance computation. It provides an alternative MCMC sampler for probabilistic programming models, aiming for speed and robustness. The current version is 0.16.8, and it maintains a frequent release cadence, often with minor bug fixes, dependency updates, and feature enhancements.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to define a basic PyMC model and then use `nutpie.sample()` to perform MCMC sampling. The results are returned in an `arviz.InferenceData` object.

import pymc as pm
import nutpie as np

# Define a simple PyMC model
with pm.Model() as model:
    # Priors
    mu = pm.Normal('mu', mu=0, sigma=1)
    sigma = pm.HalfNormal('sigma', sigma=1)
    
    # Likelihood
    obs = pm.Normal('obs', mu=mu, sigma=sigma, observed=[1.0, 2.0, 3.0])

# Sample the model using Nutpie
print("Starting Nutpie sampling...")
idata = np.sample(model)

print("Sampling complete. InferenceData:\n", idata)

view raw JSON →