Bin width estimation — all major methods in one place
Project description
binjamin
Bin width estimation — every major method in one place.
import binjamin as bj
# Estimate bin width
bj.auto(intervals) # good default — max(FD, Sturges)
bj.freedman_diaconis(intervals) # robust, no distributional assumption
# Bin data and get the artifact
edges, counts = bj.bin(data)
edges, counts = bj.bin(data, method='bayesian_blocks')
Install
pip install binjamin
Methods
Scalar — return a single bin width
| Method | Formula | When to use |
|---|---|---|
auto |
max(FD, Sturges) | Good general default |
freedman_diaconis |
2·IQR·n^(-1/3) | Unknown or skewed distribution, outliers present |
scott |
3.5·σ·n^(-1/3) | Near-normal data, few outliers |
sturges |
(max−min)/(1+log₂n) | Small, near-normal datasets |
rice |
(max−min)/(2·n^(1/3)) | No assumption, simple alternative to FD |
sqrt |
(max−min)/√n | Quick exploratory work |
doane |
Sturges + skewness correction | Skewed or multimodal distributions |
stone |
Cross-validation | Unknown distribution, accuracy over speed |
knuth |
Maximum likelihood | Uniform bins, optimal posterior |
gcd_interval |
GCD of intervals | Integer sequences, regularly-sampled data |
Variable-width — returns bin edges
| Method | When to use |
|---|---|
bayesian_blocks |
Non-stationary event data; density varies across the domain |
Binning artifact
| Function | Returns |
|---|---|
bin(data, method='auto') |
(edges, counts) — edges and observation counts per bin |
Usage
All scalar methods take a 1-D array-like and return a float:
import numpy as np
import binjamin as bj
intervals = np.diff(np.sort(event_times)) # inter-event intervals
bj.freedman_diaconis(intervals) # → float
bj.scott(intervals) # → float
bj.knuth(intervals) # → float
bayesian_blocks takes event positions (not intervals) and returns edges:
edges = bj.bayesian_blocks(event_times, p0=0.05)
# edges: array of variable-width bin boundaries
# p0: false-positive rate for new change points (lower = fewer blocks)
gcd_interval takes integer-valued positions:
bj.gcd_interval([0, 60, 120, 180, 300]) # → 60.0
Choosing a method
Start with auto. If the result looks wrong:
- Heavy tails or outliers →
freedman_diaconis - Known near-normal distribution →
scott - Skewed data →
doane - Event rate changes over time →
bayesian_blocks - Integer sequence with known regular spacing →
gcd_interval - Need provably optimal bins, willing to wait →
knuthorstone
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file binjamin-0.1.0.tar.gz.
File metadata
- Download URL: binjamin-0.1.0.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
973be2a26ab928049ac2e40273f11903d26cb04366e5dbc53019bfca8998fe13
|
|
| MD5 |
2e831a84dd9fedac7dfb0bff54b4efd7
|
|
| BLAKE2b-256 |
af9e67c16dc4f8740bb8c1c957b0ad77815cb5856fafeba2c5240b39ff62c544
|
Provenance
The following attestation bundles were made for binjamin-0.1.0.tar.gz:
Publisher:
publish.yml on adelic-ai/binjamin
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
binjamin-0.1.0.tar.gz -
Subject digest:
973be2a26ab928049ac2e40273f11903d26cb04366e5dbc53019bfca8998fe13 - Sigstore transparency entry: 1186329024
- Sigstore integration time:
-
Permalink:
adelic-ai/binjamin@19d1300a339031bc8e344d062eddcedb1cddd23d -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/adelic-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@19d1300a339031bc8e344d062eddcedb1cddd23d -
Trigger Event:
push
-
Statement type:
File details
Details for the file binjamin-0.1.0-py3-none-any.whl.
File metadata
- Download URL: binjamin-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b4ca1302ed9a726d9fd9d72481c86356cf338389076c664a5d00cdee78b1b5f
|
|
| MD5 |
36b05718fb891e33b935478b3718b6c2
|
|
| BLAKE2b-256 |
3594ce4533b8e5b54a8edb6ed1d4c26d335d841139aae74d2c059dc0782fda7d
|
Provenance
The following attestation bundles were made for binjamin-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on adelic-ai/binjamin
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
binjamin-0.1.0-py3-none-any.whl -
Subject digest:
6b4ca1302ed9a726d9fd9d72481c86356cf338389076c664a5d00cdee78b1b5f - Sigstore transparency entry: 1186329027
- Sigstore integration time:
-
Permalink:
adelic-ai/binjamin@19d1300a339031bc8e344d062eddcedb1cddd23d -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/adelic-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@19d1300a339031bc8e344d062eddcedb1cddd23d -
Trigger Event:
push
-
Statement type: