aggregation#


class RelativeFrequencyCounter[source]#

Bases: ToStringMixin

Counts the absolute and relative frequency of an event

count(is_relevant_event) None[source]#

Adds to the count. The nominator is incremented only if we are counting a relevant event. The denominator is always incremented.

Parameters:

is_relevant_event – whether we are counting a relevant event

add(relative_frequency_counter: RelativeFrequencyCounter) None[source]#

Adds the counts of the given counter to this object

Parameters:

relative_frequency_counter – the counter whose data to add

get_relative_frequency() Optional[float][source]#
Returns:

the relative frequency (between 0 and 1) or None if nothing was counted (0 events considered)

class DistributionCounter[source]#

Bases: ToStringMixin

Supports the counting of the frequencies with which (mutually exclusive) events occur

count(event: Hashable) None[source]#

Increments the count of the given event

Parameters:

event – the event/key whose count to increment, which must be hashable

get_distribution() Dict[Hashable, float][source]#
Returns:

a dictionary mapping events (as previously passed to count) to their relative frequencies

class WeightedMean[source]#

Bases: ToStringMixin

Computes a weighted mean of values

add(value, weight=1) None[source]#

Adds the given value with the given weight to the calculation

Parameters:
  • value – the value

  • weight – the weight with which to consider the value

get_weighted_mean()[source]#
Returns:

the weighted mean of all values that have been added