Science Score: 54.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
✓Committers with academic emails
1 of 18 committers (5.6%) from academic institutions -
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (12.1%) to scientific vocabulary
Keywords from Contributors
Repository
Python wrapper for nuts-rs
Basic Info
- Host: GitHub
- Owner: pymc-devs
- License: mit
- Language: Python
- Default Branch: main
- Homepage: https://pymc-devs.github.io/nutpie/
- Size: 2.16 MB
Statistics
- Stars: 172
- Watchers: 17
- Forks: 20
- Open Issues: 30
- Releases: 33
Metadata Files
README.md
nutpie: A fast sampler for Bayesian posteriors
The nutpie package provides a fast NUTS sampler for PyMC and Stan models.
See the documentation for more details.
Installation
nutpie can be installed using Conda or Mamba from conda-forge with
bash
mamba install -c conda-forge nutpie
Or using pip:
bash
pip install nutpie
To install it from source, install a Rust compiler and maturin and then
bash
maturin develop --release
If you want to use the nightly SIMD implementation for some of the math functions,
switch to Rust nightly and then install with the simd_support feature in then
nutpie directory:
bash
rustup override set nightly
maturin develop --release --features=simd_support
Usage with PyMC
First, PyMC and Numba need to be installed, for example using
bash
mamba install -c conda-forge pymc numba
We need to create a model:
```python import pymc as pm import numpy as np import nutpie import pandas as pd import seaborn as sns
Load the radon dataset
data = pd.readcsv(pm.getdata("radon.csv")) data["logradon"] = data["logradon"].astype(np.float64) countyidx, counties = pd.factorize(data.county) coords = {"county": counties, "obsid": np.arange(len(county_idx))}
Create a simple hierarchical model for the radon dataset
with pm.Model(coords=coords, checkbounds=False) as pymcmodel: intercept = pm.Normal("intercept", sigma=10)
# County effects
raw = pm.ZeroSumNormal("county_raw", dims="county")
sd = pm.HalfNormal("county_sd")
county_effect = pm.Deterministic("county_effect", raw * sd, dims="county")
# Global floor effect
floor_effect = pm.Normal("floor_effect", sigma=2)
# County:floor interaction
raw = pm.ZeroSumNormal("county_floor_raw", dims="county")
sd = pm.HalfNormal("county_floor_sd")
county_floor_effect = pm.Deterministic(
"county_floor_effect", raw * sd, dims="county"
)
mu = (
intercept
+ county_effect[county_idx]
+ floor_effect * data.floor.values
+ county_floor_effect[county_idx] * data.floor.values
)
sigma = pm.HalfNormal("sigma", sigma=1.5)
pm.Normal(
"log_radon", mu=mu, sigma=sigma, observed=data.log_radon.values, dims="obs_id"
)
```
We then compile this model and sample form the posterior:
python
compiled_model = nutpie.compile_pymc_model(pymc_model)
trace_pymc = nutpie.sample(compiled_model)
trace_pymc now contains an ArviZ InferenceData object, including sampling
statistics and the posterior of the variables defined above.
We can also control the sampler in a non-blocking way:
```python
The sampler will now run the the background
sampler = nutpie.sample(compiled_model, blocking=False)
Pause and resume the sampling
sampler.pause() sampler.resume()
Wait for the sampler to finish (up to timeout seconds)
sampler.wait(timeout=0.1)
Note that not passing any timeout to wait will
wait until the sampler finishes, then return the InferenceData object:
idata = sampler.wait()
or we can also abort the sampler (and return the incomplete trace)
incomplete_trace = sampler.abort()
or cancel and discard all progress:
sampler.cancel() ```
Usage with Stan
In order to sample from Stan model, bridgestan needs to be installed.
A pip package is available, but right now this can not be installed using Conda.
bash
pip install bridgestan
When we install nutpie with pip, we can also specify that we want optional dependencies for Stan models using
pip install 'nutpie[stan]'
In addition, a C++ compiler needs to be available. For details see the Stan docs.
We can then compile a Stan model, and sample using nutpie:
```python import nutpie
code = """ data { real mu; } parameters { real x; } model { x ~ normal(mu, 1); } """
compiled = nutpie.compilestanmodel(code=code)
Provide data
compiled = compiled.with_data(mu=3.) trace = nutpie.sample(compiled) ```
Advantages
nutpie uses nuts-rs, a library written in Rust, that implements NUTS as in
PyMC and Stan, but with a slightly different mass matrix tuning method as
those. It often produces a higher effective sample size per gradient
evaluation, and tends to converge faster and with fewer gradient evaluation.
Owner
- Name: PyMC
- Login: pymc-devs
- Kind: organization
- Website: https://www.pymc.io
- Twitter: pymc_devs
- Repositories: 34
- Profile: https://github.com/pymc-devs
Citation (CITATION.cff)
# This CITATION.cff file was generated with cffinit.
# Visit https://bit.ly/cffinit to generate yours today!
cff-version: 1.2.0
title: nutpie
message: >-
If you use this software, please cite it using the
metadata from this file.
type: software
authors:
- given-names: Adrian
family-names: Seyboldt
email: adrian.seyboldt@gmail.com
affiliation: PyMC Labs
orcid: 'https://orcid.org/0000-0002-4239-4541'
- name: PyMC Developers
website: 'https://github.com/pymc-devs/'
repository-code: 'https://github.com/pymc-devs/nutpie'
abstract: 'A fast sampler for Bayesian posteriors, wrapping nuts-rs.'
keywords:
- NUTS
- Bayesian inference
- MCMC
license: MIT
GitHub Events
Total
- Create event: 15
- Release event: 7
- Issues event: 41
- Watch event: 45
- Delete event: 18
- Issue comment event: 131
- Push event: 63
- Pull request review comment event: 14
- Pull request review event: 21
- Pull request event: 74
- Fork event: 8
Last Year
- Create event: 15
- Release event: 7
- Issues event: 41
- Watch event: 45
- Delete event: 18
- Issue comment event: 131
- Push event: 63
- Pull request review comment event: 14
- Pull request review event: 21
- Pull request event: 74
- Fork event: 8
Committers
Last synced: 9 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Adrian Seyboldt | a****t@g****m | 224 |
| pre-commit-ci[bot] | 6****] | 32 |
| Ben Mares | s****1@t****m | 19 |
| dependabot[bot] | 4****] | 14 |
| Max Kochurov | m****v@g****m | 7 |
| Thomas Wiecki | t****i@g****m | 6 |
| Chris Fonnesbeck | f****k@g****m | 4 |
| Alexandre Andorra | a****e@g****m | 2 |
| Brian Ward | b****9@g****m | 1 |
| Daniel Saunders | 8****l | 1 |
| Guspan Tanadi | 3****i | 1 |
| Henry Simmons | 3****s | 1 |
| Michael Osthege | m****e@f****e | 1 |
| Tomás Capretto | t****o@g****m | 1 |
| Will Dean | 5****n | 1 |
| jessegrabowski | j****i@g****m | 1 |
| lucianopaz | l****o@g****m | 1 |
| markgoodhead | g****d@g****m | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 7 months ago
All Time
- Total issues: 86
- Total pull requests: 213
- Average time to close issues: 3 months
- Average time to close pull requests: 5 days
- Total issue authors: 43
- Total pull request authors: 19
- Average comments per issue: 2.43
- Average comments per pull request: 0.6
- Merged pull requests: 187
- Bot issues: 0
- Bot pull requests: 87
Past Year
- Issues: 34
- Pull requests: 88
- Average time to close issues: 3 months
- Average time to close pull requests: 5 days
- Issue authors: 23
- Pull request authors: 13
- Average comments per issue: 1.76
- Average comments per pull request: 0.55
- Merged pull requests: 74
- Bot issues: 0
- Bot pull requests: 42
Top Authors
Issue Authors
- aseyboldt (14)
- ricardoV94 (12)
- fonnesbeck (6)
- ferrine (5)
- twiecki (3)
- williambdean (2)
- maresb (2)
- WardBrian (2)
- trendelkampschroer (2)
- Dekermanjian (2)
- jessegrabowski (2)
- wd60622 (2)
- michaelosthege (1)
- giiyms (1)
- philpatton (1)
Pull Request Authors
- aseyboldt (83)
- pre-commit-ci[bot] (64)
- dependabot[bot] (29)
- maresb (15)
- twiecki (5)
- fonnesbeck (5)
- ferrine (4)
- AlexAndorra (3)
- daniel-saunders-phil (2)
- tomicapretto (2)
- williambdean (2)
- jessegrabowski (2)
- michaelosthege (2)
- juanitorduz (2)
- guspan-tanadi (2)
Top Labels
Issue Labels
Pull Request Labels
Dependencies
- crossbeam 0.8.1
- ndarray 0.15.4
- numpy 0.16.2
- nuts-rs 0.2
- pyo3 0.16.5
- rand 0.8.5
- thiserror 1.0.31
- actions-rs/toolchain v1 composite
- actions/checkout v2 composite
- actions/setup-python v4 composite
- messense/maturin-action v1 composite
- 112 dependencies
- arviz >= 0.15.0
- fastprogress >= 1.0.3
- pandas >= 2.0
- pyarrow >= 12.0.0
- xarray >= 2023.06.0