shared_bin_edges
Mojo function 🡭
shared_bin_edges
fn def shared_bin_edges(samples: List[List[Float64]], bins: Int = Int(10)) -> List[Float64]One set of boundaries covering every sample in samples: the smallest value anywhere to the largest value anywhere, in bins equal intervals.
Two histograms only compare if their bars line up. Binning each
sample against its own range gives each one different edges, so a
bar in one chart covers a different interval than the bar drawn
beside it – the comparison the reader makes is then between two
quantities that were never measured the same way. Feeding these
edges to histogram_bins() for each sample makes the bins
identical by construction.
Args:
- samples (
List[List[Float64]]): One list of observations per group. Empty groups are allowed and contribute nothing to the range, as long as at least one group has a value. - bins (
Int): How many intervals to divide the combined range into; must be positive.
Returns:
List[Float64]: bins + 1 strictly ascending boundaries, the same for every
group.
Raises:
Error: samples is empty or every group is, bins is not
positive, or any value is NaN/infinite.
fn def shared_bin_edges(samples: List[List[Float64]], rule: BinRule) -> List[Float64]One set of boundaries covering every sample in samples, with the count chosen by rule – shared_bin_edges()’s BinRule overload.
The rule runs on the pooled observations, not on any one group and not on a per-group answer combined afterward. That is the only choice that keeps the result a single set of edges: two groups generally want different counts, and there is no honest way to reconcile them into the one grid that makes the two charts comparable. Pooling asks the rule the question actually being answered – how finely can this combined evidence be cut.
Args:
- samples (
List[List[Float64]]): One list of observations per group. Empty groups are allowed and contribute nothing, as long as at least one group has a value. - rule (
BinRule): Which rule picks the count. SeeBinRule.
Returns:
List[Float64]: n + 1 strictly ascending boundaries, the same for every group.
Raises:
Error: samples is empty or every group is, any value is
NaN/infinite, or the rule asks for an unusably large
number of bins.