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