Skip to main content

priorities

Tests License Python 3.12+

Probability distributions as Equinox records for JAX: a density, its draws and its map to the unit cube, held as array parameters that jit, vmap and differentiate like any other pytree. The runtime dependencies are jax and equinox.

Example

import jax

jax.config.update("jax_enable_x64", True)

import jax.numpy as jnp
import priorities as pr

# An eccentricity prior: a Beta distribution cut at 0.95.
prior = pr.TruncatedDistribution(pr.Beta(0.867, 3.03), high=0.95)

draws = prior.sample(jax.random.key(0), (1000,))
assert draws.shape == (1000,)
assert float(draws.max()) <= 0.95

# The density, exactly -inf outside the support.
assert jnp.isfinite(prior.log_prob(0.2))
assert prior.log_prob(0.97) == -jnp.inf

# The inverse CDF: uniform in, the distribution out, and back.
value = prior.icdf(0.25)
assert jnp.allclose(prior.cdf(value), 0.25)

# An unconstrained coordinate for a gradient-based sampler. real_log_prob
# is the density of that coordinate, including the volume term.
z = pr.to_real(prior, value)
back, log_volume = pr.from_real(prior, z)
assert jnp.allclose(back, value)
gradient = jax.grad(lambda z: pr.real_log_prob(prior, z))(z)
assert jnp.isfinite(gradient)

# Parameters are leaves: one compiled function serves every value.
score = jax.jit(jax.grad(lambda dist: dist.log_prob(0.2)))(pr.Beta(0.867, 3.03))
assert jnp.isfinite(score.concentration1)

What it holds

Record Support icdf
Uniform(low, high) [low, high] yes
LogUniform(low, high) [low, high], low > 0 yes
Normal(loc, scale) the real line yes
LogNormal(loc, scale) (0, inf) yes
HalfNormal(scale) [0, inf) yes
Rayleigh(scale) (0, inf) yes
Beta(concentration1, concentration0) (0, 1) yes
TruncatedDistribution(base_dist, low, high) the cut of a scalar distribution yes
MultivariateNormal(loc, scale_tril) vectors yes
Mixture(mixing_logits, component_distribution) union of the components no

Every record implements five methods: support, log_prob, sample, cdf and icdf. Three free functions work on any distribution: to_real, from_real and real_log_prob, the default change of variable to an unconstrained coordinate, chosen from the static bounds of the distribution.

Names follow NumPyro: sample(key, sample_shape), log_prob, cdf, icdf(q), Beta(concentration1, concentration0), MultivariateNormal(loc, scale_tril), TruncatedDistribution(base_dist, low, high). The differences are deliberate: support() is a method returning the bounds as arrays rather than a constraint object, bounds names the bounded sides statically, has_icdf says before tracing whether icdf exists, and Mixture(mixing_logits, component_distribution) takes its weights as logits rather than a categorical distribution.

Conventions

  • Shapes. A value has shape sample + batch + event, where batch is the broadcast of the parameter shapes. A distribution is elementwise or has one event axis. The components of a Mixture are one distribution whose batch has a last axis of length K.
  • Precision. The output dtype is the promotion of the argument and the parameters. A distribution built from Python numbers follows its argument, so it serves float32 and float64 pipelines alike. Nothing is built at import: enable x64 before constructing a distribution, not before importing the package.
  • Off the support. log_prob is exactly -inf outside the support, with a zero gradient, and NaN for a NaN value.
  • Invalid parameters. A distribution built from concrete parameters outside their domain raises ValueError. Under a transformation the parameters are traced and cannot be inspected, so log_prob returns -inf and the other methods return NaN: a sampler that proposes an invalid parameter rejects it. Set PRIORITIES_DEBUG_CHECKS=1 before import to raise at run time instead.
  • Truncation. Which sides are cut is static: None leaves a side open. The mass of the cut is computed from the base distribution's cdf, so a cut far in a tail loses relative precision.
  • Beta shapes. The Beta density is differentiable in its shapes. Its distribution function and quantile are not, and differentiating them in a or b raises instead of returning a wrong number.
  • Mixture. A scalar mixture has a distribution function (cdf) but no quantile: has_icdf is false and icdf raises.

Adding a distribution

Subclass AbstractDistribution when the mathematics is new, and implement the five methods. A named prior that only fixes the parameters of an existing record is a function returning that record, not a class:

import priorities as pr


def kipping_eccentricity():
    """Short-period eccentricity distribution of Kipping (2013)."""
    return pr.Beta(0.867, 3.03)


assert isinstance(kipping_eccentricity(), pr.Beta)

priorities.testing.check_distribution(distribution, key) checks that the draws, the inverse CDF and the support of a distribution agree with its density without restating any formula, so it applies unchanged to a new subclass. It needs no reference code; pin the absolute scale of log_prob against one separately.

Scope

The package stays small on purpose. It holds distributions and the three functions above. Samplers, inference, parameter trees, bijector objects and domain-specific priors belong to the packages that use it. A test holds the source to its line budget and to jax and equinox as the only runtime dependencies.

Installation

pip install priorities

Metadata

Release files for priorities 0.2.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 priorities 0.2.0
File Size Uploaded Provenance Actions
priorities-0.2.0.tar.gz 23.6 kB With provenance Details for priorities-0.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 44.9 kB

Release files / priorities-0.2.0.tar.gz

Download URL priorities-0.2.0.tar.gz
Size 23.6 kB
Tags Source
SHA-256 checksum
How to use checksums
331d56621ad97ce7451357efcce8a9977862b21663750e3b2eb192cc7e67dbac
BLAKE2b-256 checksum
How to use checksums
6ad2c7474190ff2f80fdfb587a1e3223d74f4b4611dc1d5ff2774a7d0c57ea79
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

Release files / priorities-0.2.0-py3-none-any.whl

Download URL priorities-0.2.0-py3-none-any.whl
Size 21.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4b5f7dd41ef49aefa25aa0301192fca103c10ad77e2d249abf517e1ff56b8176
BLAKE2b-256 checksum
How to use checksums
c30e03c03c05b1ca01dc92036b399b75d94be0789f24693f70cf824d9a4485ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

Security for priorities 0.2.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for priorities-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

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