Skip to main content

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 to p ** x, NB(p_success=False) to (1 - p) ** x. BetaNB is NB with the probability of the power of r drawn from Beta(a, b).
  • MCNB(CompoundDist.Binomial).logpmf(x, r, p) is the MCNB(r, p) of the MixALime paper, p2 is 1 - p1 by default.
  • sf(x) is P(X > x).
  • Bounds of TruncatedDistribution are the keyword arguments left and right of each method, both inclusive.
  • logpmf_recurrent(min_x, max_x, max_sz, *params) returns max_sz values 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.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jacobin 1.3.0
File Size Uploaded Provenance Actions
jacobin-1.3.0.tar.gz 38.2 kB Without provenance Details for jacobin-1.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for jacobin 1.3.0
File Interpreter ABI Platform Actions
jacobin-1.3.0-py3-none-any.whl Python 3 none any Details for jacobin-1.3.0-py3-none-any.whl

Total release size: 62.1 kB

Release files / jacobin-1.3.0.tar.gz

Download URL jacobin-1.3.0.tar.gz
Size 38.2 kB
Tags Source
SHA-256 checksum
How to use checksums
4ab3d5264b7a8e01060f4584ffd0b06ec41f65fa57d5cdbea88de4ec0455f457
BLAKE2b-256 checksum
How to use checksums
c9478fd2525bdf58fd9bc2d8007179fea5e9c3bbc5687bb1d3cc6ea9e790e400
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.0-py3-none-any.whl

Download URL jacobin-1.3.0-py3-none-any.whl
Size 23.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
14c9dddc5a77138e62089bece96d6850d9be6a19148a5dd96cf6aa9b5e6fbbe6
BLAKE2b-256 checksum
How to use checksums
3fdf9d5f2038b372390e7ed382cf286f096913ca91a32b8511b5c63949372c74
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.0

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page