Skip to main content

binned-cdf

License: CC-BY-4.0 python Docs CI CD Coverage Tests mkdocs-material mypy pre-commit pytest Ruff uv

A PyTorch-based distribution parametrized by the logits of CDF bins

Background

The Cumulative Distribution Function (CDF) is a fundamental concept in probability theory and statistics that describes the probability that a random variable $X$ takes on a value less than or equal to a given threshold $x$. Formally, the CDF is defined as $F(x) = P(X \leq x)$, where $F(x)$ ranges from 0 to 1 as $x$ varies from negative to positive infinity. The CDF provides a complete characterization of the probability distribution of a random variable: for continuous distributions, it is the integral of the probability density function (PDF), while for discrete distributions, it is the sum of probabilities up to and including $x$. Key properties of any CDF are the monotonicity and the boundary conditions $\lim_{x \to -\infty} F(x) = 0$ and $\lim_{x \to \infty} F(x) = 1$. CDFs are particularly useful for computing probabilities of intervals, quantiles, and for statistical inference.

Application to Machine Learning

This repository uses the CDF to model and learn flexible probability distributions in machine learning tasks. By parameterizing the CDF with binned logits, it enables differentiable training and efficient sampling, making it suitable for uncertainty estimation, probabilistic prediction, and distributional modeling in neural networks.

Implementation

The PiecewiseConstantBinnedCDF, PiecewiseLinearBinnedCDF, and BezierCDF classes inherit directly from torch.distributions.Distribution, implementing all necessary methods plus some convenience functions. They support multi-dimensional batch shapes and CUDA devices. The bins can be initialized linearly or log-spaced.

torch>=2.7 it the only non-dev dependency of this repo.

Getting Started

I recommend using PiecewiseLinearBinnedCDF for most applications.

from binned_cdf import PiecewiseLinearBinnedCDF

# logits = ... some model output
distr = PiecewiseLinearBinnedCDF(
    logits=logits,  # shape: (*batch_shape, num_bins)
    bound_low=-5,  # adapt to your data
    bound_up=7,  # adapt to your data
    log_spacing=True,  # if False, linear spacing is used
    normalization_method="sigmoid",  # "sigmoid" or "softmax"
    validate_args=None,  # None uses PyTorch's default argument validation; or set True/False
)
# ... use it like any other torch.distribution.Distribution

This package also provides the more esoteric BezierCDF.

from binned_cdf import BezierCDF

# logits_y, logits_x = ... model outputs with the same floating dtype/device and broadcastable batch shapes
# Degrees may differ; omit logits_x or pass None for fixed horizontal spacing.
distr = BezierCDF(
    logits_y=logits_y,  # vertical increments; shape: (*batch_shape_y, degree_y)
    logits_x=logits_x,  # horizontal increments; shape: (*batch_shape_x, degree_x)
    bound_low=-2,  # finite lower support bound; adapt to your data
    bound_up=2,  # finite upper support bound; must exceed bound_low
    normalization_method="softmax",  # "softmax" or "sigmoid", applied to both axes
    validate_args=None,  # None uses PyTorch's default argument validation; or set True/False
)
# ... use it like any other torch.distribution.Distribution

👉 Please have a look at the documentation to get started.

Metadata

Release files for binned-cdf 2.1.10

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

Source distribution (sdist)

Source distribution for binned-cdf 2.1.10
File Size Uploaded Provenance Actions
binned_cdf-2.1.10.tar.gz 50.4 kB With provenance Details for binned_cdf-2.1.10.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for binned-cdf 2.1.10
File Interpreter ABI Platform Actions
binned_cdf-2.1.10-py3-none-any.whl Python 3 none any Details for binned_cdf-2.1.10-py3-none-any.whl

Total release size: 73.0 kB

Release files / binned_cdf-2.1.10.tar.gz

Download URL binned_cdf-2.1.10.tar.gz
Size 50.4 kB
Tags Source
SHA-256 checksum
How to use checksums
30de3458e21baffbab9deb9a344b6c449ffe6e7974ef10f8d2a91a343cd00a68
BLAKE2b-256 checksum
How to use checksums
3060c6e00b73eafedfe67e73ef780f2c687984fde503ee9aa134f7cdb78963a5
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 5, 2026.

Transparency log

Release files / binned_cdf-2.1.10-py3-none-any.whl

Download URL binned_cdf-2.1.10-py3-none-any.whl
Size 22.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a27091dcfc09b8e3ad0493962f838d68c9135017ec9a02b97c6e16d5368349bb
BLAKE2b-256 checksum
How to use checksums
e1af9f65d060d53f993e2b89b341045da9aade3bf99fcd53aacd55bfd2bf68a3
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 5, 2026.

Transparency log

Security for binned-cdf 2.1.10

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 binned_cdf-2.1.10.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 5, 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.

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