Skip to main content

2D equal-probability binning (multivariate probability binning)

Project description

equibin

CI PyPI

2D equal-probability binning for statistical data analysis.

Partitions a 2D dataset into bins that each contain approximately the same number of points. At each step the dimension with the highest variance is split at its median, recursively, until the target number of bins is reached. The resulting bins are axis-aligned rectangles that adapt to the local density of the data.

This implements the multivariate probability binning algorithm described in:

Roederer, M., Moore, W., Treister, A., Hardy, R. R. & Herzenberg, L. A. (2001). Probability binning comparison: a metric for quantitating multivariate distribution differences. Cytometry 45(1):47–55. https://doi.org/10.1002/1097-0320(20010901)45:1<47::AID-CYTO1143>3.0.CO;2-A

Installation

pip install equibin

Usage

import numpy as np
from equibin import bin_2d, plot_bins, save_bins

rng = np.random.default_rng(0)
x = rng.uniform(0, 10, 5000)
y = rng.uniform(0, 10, 5000)

result = bin_2d(x, y, n_bins=128)

print(len(result))          # 128
print(result.counts.sum())  # 5000
print(result.bins[0])       # (xmin, xmax, ymin, ymax)

Restrict binning to a region of interest:

result = bin_2d(x, y, n_bins=256, xmin=2.5, xmax=20, ymin=0.25, ymax=10)

Plot the bins overlaid on the data:

plot_bins(result, x, y, title="Equal-probability bins", xlim=(0, 10), ylim=(0, 10))

Save bin boundaries to a text file (one line per bin: xlo xhi ylo yhi label):

save_bins(result, "bins.txt", label_prefix="run_")

Authors

License

GPL-2.0-only

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

equibin-0.1.2.tar.gz (144.9 kB view details)

Uploaded Source

Built Distribution

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

equibin-0.1.2-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file equibin-0.1.2.tar.gz.

File metadata

  • Download URL: equibin-0.1.2.tar.gz
  • Upload date:
  • Size: 144.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.5

File hashes

Hashes for equibin-0.1.2.tar.gz
Algorithm Hash digest
SHA256 92e1253e9b959689875851191d6650adca7a122a7020ea36bc5b747f50a0a8d3
MD5 c9262c7d04d18be67d3e88642339951a
BLAKE2b-256 e9afc98686f52fac960343a66fc591745edd2cdcfb4a67737c8875a37164fca2

See more details on using hashes here.

File details

Details for the file equibin-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: equibin-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.5

File hashes

Hashes for equibin-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 68b0bbff6faad0caea6ea879797a86ad1b773a43b18ec89275946302b51de3c3
MD5 68380946a2d0277711559b25206a5d87
BLAKE2b-256 89073280085d8208ad63c96f5a663ef7de00670aec601aacebbad52c507eaea6

See more details on using hashes here.

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