jacobin
JACOBIN: JAX Compound Binomials, head-counting distributions
Count distributions in JAX: Poisson, Binomial, NB, BetaBinomial, BetaNB, and MCNB, the marginalized compound negative binomial of MixALime. Each has logpmf, pmf, cdf, sf, logcdf, logsf, mean, var, sample, a table of the log-pmf by a recurrence (logpmf_recurrent), and long_pmf, long_cdf, long_sf in multiple precision (gmpy2) for p-values far below 1e-16. TruncatedDistribution and Mixture wrap any of them. The float functions work under jit, vmap, grad and jacfwd.
Importing the package switches JAX to 64-bit floats (jax_enable_x64). The accuracy of every routine relies on it.
Installation
pip install .
The tests need pytest, mpmath and betanegbinfit, run them with python -m pytest tests.
Conventions
- Positional order:
Poisson(x, rate),Binomial(x, n, p),NB(x, r, p),BetaBinomial(x, n, a, b),BetaNB(x, r, a, b),MCNB(x, r, p1, p2). Parameters can be passed as keywords. NB()has pmf proportional top ** x,NB(p_success=False)to(1 - p) ** x.BetaNBisNBwith the probability of the power ofrdrawn from Beta(a, b).MCNB(CompoundDist.Binomial).logpmf(x, r, p)is the MCNB(r, p) of the MixALime paper,p2is1 - p1by default.sf(x)is P(X > x).- Bounds of
TruncatedDistributionare the keyword argumentsleftandrightof each method, both inclusive. logpmf_recurrent(min_x, max_x, max_sz, *params)returnsmax_szvalues for x = 0, ...,max_sz - 1. Entries outside of [min_x,max_x], both inclusive, are-inf.
Example
import numpy as np
import jax
import jax.numpy as jnp
from jacobin import NB, MCNB, CompoundDist, TruncatedDistribution
x = jnp.array([5.0, 9.0, 40.0])
dist = TruncatedDistribution(MCNB(CompoundDist.Binomial))
loglik = lambda v: dist.logpmf(x, v[0], v[1], left=5).sum()
v = jnp.array([7.5, 0.6])
grad = jax.jit(jax.grad(loglik))(v)
hess = jax.jit(jax.jacfwd(jax.jacfwd(loglik)))(v)
# A table per value of r: 3 rows, counts 0..99 in columns.
tables = jax.vmap(lambda r: dist.logpmf_recurrent(0, None, 100, r, 0.6, left=5))(jnp.array([3.3, 7.5, 20.0]))
mean = dist.mean(7.5, 0.6, left=5)
# P(X > x | X >= 5) as mpfr numbers of 1024 bits: 9.18e-190, 0.788, 2.75e-06.
pvals = dist.long_sf(np.array([900, 5, 40]), 7.5, 0.6, left=5)
Metadata
Release files for jacobin 1.3.1
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 | Actions |
|---|---|---|---|---|
| jacobin-1.3.1.tar.gz | 40.3 kB | Without provenance | Details for jacobin-1.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| jacobin-1.3.1-py3-none-any.whl | Python 3 | none | any | Details for jacobin-1.3.1-py3-none-any.whl |
Total release size: 65.5 kB
Release files / jacobin-1.3.1.tar.gz
| Download URL | jacobin-1.3.1.tar.gz |
|---|---|
| Size | 40.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
34c6d5514eef88e6378bc4f0d2707ca10a2a6929cca9116beb2adc2d156bfd47
|
|
BLAKE2b-256 checksum How to use checksums |
e3ea1f84486994bfc86c5bcb1ac56914298303cebde4b52e030c43bac3e81d01
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / jacobin-1.3.1-py3-none-any.whl
| Download URL | jacobin-1.3.1-py3-none-any.whl |
|---|---|
| Size | 25.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
16bf9e489099a62c536bf0e06f803e93c2dc681854d9dde8cb3144339ec38cde
|
|
BLAKE2b-256 checksum How to use checksums |
ba23e3ff5abc5ef8283211f30035dea4213bb448770cc5a50d549e0856ecf847
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Security for jacobin 1.3.1
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.