Skip to main content

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

Project description

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 and PiecewiseLinearBinnedCDF 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

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
    bin_normalization_method="sigmoid",  # "sigmoid" or "softmax"
)

# ... use it like any other torch.distribution.Distribution

:point_right: Please have a look at the documentation to get started.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

binned_cdf-1.1.2.tar.gz (32.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

binned_cdf-1.1.2-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file binned_cdf-1.1.2.tar.gz.

File metadata

  • Download URL: binned_cdf-1.1.2.tar.gz
  • Upload date:
  • Size: 32.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for binned_cdf-1.1.2.tar.gz
Algorithm Hash digest
SHA256 17b7d758f8dbd4150b1efdddda39f5d9d7cf3c0b86180afd1e1b6e928d2097bd
MD5 1a8f4fd321dfd85a9d22b86c64b17ad3
BLAKE2b-256 c44c147e0f52019cc6f3ec036561655ff430404e382d4d92659ed9ee86330df8

See more details on using hashes here.

Provenance

The following attestation bundles were made for binned_cdf-1.1.2.tar.gz:

Publisher: cd.yaml on famura/binned-cdf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file binned_cdf-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: binned_cdf-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for binned_cdf-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ae4c70d0321a0a0b0b11e92a93fb9aefbd4358befe6e632b1995702804313c8e
MD5 624ac6ff54fc101caab71316c75e3a67
BLAKE2b-256 a71c854d48c4a50a56f5914139d347e2e2d27fe5e8f71649d8734b7426702f0c

See more details on using hashes here.

Provenance

The following attestation bundles were made for binned_cdf-1.1.2-py3-none-any.whl:

Publisher: cd.yaml on famura/binned-cdf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page