telemetry.util.statistics
index
telemetry/util/statistics.py

A collection of statistical utility functions to be used by metrics.

 
Modules
       
math

 
Functions
       
ArithmeticMean(data)
Calculates arithmetic mean.
 
Args:
  data: A list of samples.
 
Returns:
  The arithmetic mean value, or 0 if the list is empty.
Clamp(value, low=0.0, high=1.0)
Clamp a value between some low and high value.
Discrepancy(samples, location_count=None)
Computes the discrepancy of a set of 1D samples from the interval [0,1].
 
The samples must be sorted. We define the discrepancy of an empty set
of samples to be zero.
 
http://en.wikipedia.org/wiki/Low-discrepancy_sequence
http://mathworld.wolfram.com/Discrepancy.html
DivideIfPossibleOrZero(numerator, denominator)
Returns the quotient, or zero if the denominator is zero.
DurationsDiscrepancy(durations, absolute=True, location_count=None)
A discrepancy based metric for measuring duration jank.
 
DurationsDiscrepancy computes a jank metric which measures how irregular a
given sequence of intervals is. In order to minimize jank, each duration
should be equally long. This is similar to how timestamp jank works,
and we therefore reuse the timestamp discrepancy function above to compute a
similar duration discrepancy number.
 
Because timestamp discrepancy is defined in terms of timestamps, we first
convert the list of durations to monotonically increasing timestamps.
 
Args:
  durations: List of interval lengths in milliseconds.
  absolute: See TimestampsDiscrepancy.
  interval_multiplier: See TimestampsDiscrepancy.
GeneralizedMean(values, exponent)
See http://en.wikipedia.org/wiki/Generalized_mean
GeometricMean(values)
Compute a rounded geometric mean from an array of values.
Median(values)
Gets the median of a list of values.
NormalizeSamples(samples)
Sorts the samples, and map them linearly to the range [0,1].
 
They're mapped such that for the N samples, the first sample is 0.5/N and the
last sample is (N-0.5)/N.
 
Background: The discrepancy of the sample set i/(N-1); i=0, ..., N-1 is 2/N,
twice the discrepancy of the sample set (i+1/2)/N; i=0, ..., N-1. In our case
we don't want to distinguish between these two cases, as our original domain
is not bounded (it is for Monte Carlo integration, where discrepancy was
first used).
Percentile(values, percentile)
Calculates the value below which a given percentage of values fall.
 
For example, if 17% of the values are less than 5.0, then 5.0 is the 17th
percentile for this set of values. When the percentage doesn't exactly
match a rank in the list of values, the percentile is computed using linear
interpolation between closest ranks.
 
Args:
  values: A list of numerical values.
  percentile: A number between 0 and 100.
 
Returns:
  The Nth percentile for the list of values, where N is the given percentage.
StandardDeviation(data)
Calculates the standard deviation.
 
Args:
  data: A list of samples.
 
Returns:
  The standard deviation of the samples provided.
TimestampsDiscrepancy(timestamps, absolute=True, location_count=None)
A discrepancy based metric for measuring timestamp jank.
 
TimestampsDiscrepancy quantifies the largest area of jank observed in a series
of timestamps.  Note that this is different from metrics based on the
max_time_interval. For example, the time stamp series A = [0,1,2,3,5,6] and
B = [0,1,2,3,5,7] have the same max_time_interval = 2, but
Discrepancy(B) > Discrepancy(A).
 
Two variants of discrepancy can be computed:
 
Relative discrepancy is following the original definition of
discrepancy. It characterized the largest area of jank, relative to the
duration of the entire time stamp series.  We normalize the raw results,
because the best case discrepancy for a set of N samples is 1/N (for
equally spaced samples), and we want our metric to report 0.0 in that
case.
 
Absolute discrepancy also characterizes the largest area of jank, but its
value wouldn't change (except for imprecisions due to a low
|interval_multiplier|) if additional 'good' intervals were added to an
exisiting list of time stamps.  Its range is [0,inf] and the unit is
milliseconds.
 
The time stamp series C = [0,2,3,4] and D = [0,2,3,4,5] have the same
absolute discrepancy, but D has lower relative discrepancy than C.
 
|timestamps| may be a list of lists S = [S_1, S_2, ..., S_N], where each
S_i is a time stamp series. In that case, the discrepancy D(S) is:
D(S) = max(D(S_1), D(S_2), ..., D(S_N))
Total(data)
Returns the float value of a number or the sum of a list.
TrapezoidalRule(data, dx)
Calculate the integral according to the trapezoidal rule
 
TrapezoidalRule approximates the definite integral of f from a to b by
the composite trapezoidal rule, using n subintervals.
http://en.wikipedia.org/wiki/Trapezoidal_rule#Uniform_grid
 
Args:
  data: A list of samples
  dx: The uniform distance along the x axis between any two samples
 
Returns:
  The area under the curve defined by the samples and the uniform distance
  according to the trapezoidal rule.