cumulativeHistogram function

List<int> cumulativeHistogram(
  1. List<num> values,
  2. List<num> edges
)

Cumulative histogram: the running total of histogramFixed(values, edges), so bin i holds the count of samples in bins 0..i — the CDF in bin form. Returns an empty list when edges has fewer than two entries.

Example:

cumulativeHistogram(<num>[1, 2, 3, 4], <num>[0, 2, 4, 6]); // [1, 3, 4]

Audited: 2026-06-12 11:26 EDT

Implementation

List<int> cumulativeHistogram(List<num> values, List<num> edges) {
  final List<int> counts = histogramFixed(values, edges);
  final List<int> cumulative = List<int>.filled(counts.length, 0);
  int running = 0;
  for (int i = 0; i < counts.length; i++) {
    running += counts[i];
    cumulative[i] = running;
  }
  return cumulative;
}