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.3.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.3-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: equibin-0.1.3.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.3.tar.gz
Algorithm Hash digest
SHA256 579c1a979c9fad2951e92224d0030dcd53d4c915fce4b21b2c5549a02b435d3d
MD5 ff9b57b959b51a131f9a16a98f0fbf49
BLAKE2b-256 a9aae711105ac07c16accbece92d4af9b2cc4314c294a450b470870e1c1a36d0

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for equibin-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2b9dd0ea557dd6301254f0de640ee70b4d294f959b190f2c4739c7fd561b2b07
MD5 9c6eb5f3a5f26638554a4a7ddebb02c1
BLAKE2b-256 29e4792a45f98644fa8cfbc71442669d58c7646d675ff4c33c0494b90fea7339

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