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. et al. (2001). Cytometry 45: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.1.tar.gz (144.8 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.1-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for equibin-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8f1caad818bdcd5f23aaf1ccd8c9713b4dad3202e79bfca6bf0639da63c5d705
MD5 5dca8a1aa5ef130a802075c0bf895d3a
BLAKE2b-256 a6d1b681d9456d02952914c2e9aa3599b20c1d144789cf7918e03b31807383d9

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for equibin-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 26b4f690e0588ba7e8294842e7f59b03c45818dc23d22dfdaadef510ec106164
MD5 5427d97d03be1713767c2cb9911011f6
BLAKE2b-256 8d8a337f51f78fdd973bce08ec41b24faa06975fc341b0f0a673ba8a5258b24c

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