Frequency
A mutable accumulator that counts the frequency of discrete values.
Maintains exact counts for each distinct value of type T, and provides cumulative counts, proportions, and mode queries. This is the discrete counterpart of histogram binning — it counts exact matches rather than grouping values into intervals.
Analogous to Apache Commons Math Frequency.
Example:
val freq = Frequency<String>()
freq.addAll(listOf("a", "a", "b", "b", "b", "c"))
freq.count("b") // 3
freq.proportion("b") // 0.5
freq.cumulativeCount("b") // 5 (a=2 + b=3)
freq.mode // setOf("b")Content copied to clipboard
Type Parameters
T
the type of observed values; must be Comparable for cumulative queries and sorted output.