🚒 firetruck
!!! NOTE: This repo is just an experiment for now, not ready for any kind of serious use. The package is not published on PyPI either !!!
firetruck is NumPyro dialect for mental midgets. This means:
- No
numpyro.deterministicandnumpyro.sample, just write your code like a normal human, and assign variables you want to track toself - You can just return your outcome variable from the function, no
obsbullshit! - Greatly simplified sampling and VI. No bespoke solutions, just good defaults for 90% of your use cases.
- You can deal with latent categorical variables without having to do anything, yaaay!
- WebGL accelarated Plotly plots. You don't know ArViz, Matplotlib or any of that jazz. It not only looks better but it's also interactive and faster.
Example
I modified the Waffle House example in the NumPyro docs to use firetruck.
import jax as jax
import jax.numpy as jnp
import numpyro.distributions as dist
import pandas as pd
import firetruck as ftr
DATASET_URL = "https://raw.githubusercontent.com/rmcelreath/rethinking/master/data/WaffleDivorce.csv"
dset = pd.read_csv(DATASET_URL, sep=";")
marriage = jnp.array(dset["Marriage"])
divorce = jnp.array(dset["Divorce"])
age = jnp.array(dset["MedianAgeMarriage"])
# Don't forget this decorator!! Very important
@ftr.compact
def model(self, marriage, age):
# Just assign variables to self that you want to track,
# And they will be named automatically!!
self.a = dist.Normal(0.0, 0.2)
self.bM = dist.Normal(0.0, 0.5)
self.bA = dist.Normal(0.0, 0.5)
self.sigma = dist.Exponential(0.5)
mu = self.a + self.bM * marriage + self.bA * age
return dist.Normal(mu, self.sigma)
# Sampling Prior predictive distribution
rng_key = jax.random.key(42)
rng_key, subkey = jax.random.split(rng_key)
prior_predictive = model.add_input(marriage, age).sample_predictive(subkey)
# Add inputs to the model and condition on the output
conditioned_model = model.add_input(marriage, age).condition_on(divorce)
# Fit model using meanfield VI
rng_key, subkey = jax.random.split(rng_key)
res = conditioned_model.meanfield_vi(subkey)
# Sample from model using NUTS
rng_key, subkey = jax.random.split(rng_key)
mcmc = conditioned_model.sample_posterior(subkey)
# Prints this automatically, cause why the hell would you not need this:
# mean std median 5.0% 95.0% n_eff r_hat
# a 0.01 0.20 0.02 -0.31 0.35 2348.61 1.00
# bA 0.17 0.05 0.17 0.10 0.25 1634.25 1.00
# bM 0.26 0.06 0.26 0.16 0.35 1649.36 1.00
# sigma 1.82 0.19 1.81 1.52 2.11 2419.83 1.00
#
# Number of divergences: 0
# Plot sampling trace
fig = ftr.plot_trace(mcmc)
fig.show()
# Forest plot of posterior samples
fig = ftr.plot_forest(mcmc)
fig.show()
# Forest plot of posterior samples
fig = ftr.plot_ess(mcmc)
fig.show()
# Sampling prior predictive and plotting prior-predictive check
rng_key, subkey = jax.random.split(rng_key)
# NOTE that I'm using the unconditoned model
prior_predictive = model.add_input(marriage, age).sample_predictive(rng_key)
fig = ftr.plot_predictive_check(prior_predictive, obs=divorce)
fig.show()
# Sampling posterior predictive and plotting prior-predictive check
rng_key, subkey = jax.random.split(rng_key)
# Note that I'm passing the posterior_samples to the function
posterior_predictive = model.add_input(marriage, age).sample_predictive(
rng_key, posterior_samples=mcmc.get_samples()
)
fig = ftr.plot_predictive_check(posterior_predictive, obs=divorce)
fig.show()
Metadata
Release files for firetruck 0.1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| firetruck-0.1.7.tar.gz | 11.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| firetruck-0.1.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.7 kB
Release files / firetruck-0.1.7.tar.gz
| Download URL | firetruck-0.1.7.tar.gz |
|---|---|
| Size | 11.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
06d8aa835261ccf1352b1f87beebeb90d44a1c22e6c33231f7bbd930edee706a
|
|
BLAKE2b-256 checksum How to use checksums |
c59dbfc8d7f890806daec9209d45c381bd001e702021888a0f1966503d45ecbe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.4.1 CPython/3.14.7 Linux/6.17.0-1032-oem
|
Release files / firetruck-0.1.7-py3-none-any.whl
| Download URL | firetruck-0.1.7-py3-none-any.whl |
|---|---|
| Size | 11.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2ca4609df92b4039ca063b3c121e0f48d4e2cbe01ef7ca8c14de8bbfd0f3f1cf
|
|
BLAKE2b-256 checksum How to use checksums |
1d17206302984bd2a7a19f0f56d071ceb1df38db0e51d99b8d5ad279d3b610cc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.4.1 CPython/3.14.7 Linux/6.17.0-1032-oem
|
Security for firetruck 0.1.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.