1 2<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 3<html><head><title>Python: module telemetry.util.statistics</title> 4<meta charset="utf-8"> 5</head><body bgcolor="#f0f0f8"> 6 7<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading"> 8<tr bgcolor="#7799ee"> 9<td valign=bottom> <br> 10<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 11><td align=right valign=bottom 12><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> 13 <p><tt>A collection of statistical utility functions to be used by metrics.</tt></p> 14<p> 15<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> 16<tr bgcolor="#aa55cc"> 17<td colspan=3 valign=bottom> <br> 18<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr> 19 20<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td> 21<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="math.html">math</a><br> 22</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> 23<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> 24<tr bgcolor="#eeaa77"> 25<td colspan=3 valign=bottom> <br> 26<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr> 27 28<tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td> 29<td width="100%"><dl><dt><a name="-ArithmeticMean"><strong>ArithmeticMean</strong></a>(data)</dt><dd><tt>Calculates arithmetic mean.<br> 30 <br> 31Args:<br> 32 data: A list of samples.<br> 33 <br> 34Returns:<br> 35 The arithmetic mean value, or 0 if the list is empty.</tt></dd></dl> 36 <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> 37 <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> 38 <br> 39The samples must be sorted. We define the discrepancy of an empty set<br> 40of samples to be zero.<br> 41 <br> 42<a href="http://en.wikipedia.org/wiki/Low-discrepancy_sequence">http://en.wikipedia.org/wiki/Low-discrepancy_sequence</a><br> 43<a href="http://mathworld.wolfram.com/Discrepancy.html">http://mathworld.wolfram.com/Discrepancy.html</a></tt></dd></dl> 44 <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> 45 <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> 46 <br> 47DurationsDiscrepancy computes a jank metric which measures how irregular a<br> 48given sequence of intervals is. In order to minimize jank, each duration<br> 49should be equally long. This is similar to how timestamp jank works,<br> 50and we therefore reuse the timestamp discrepancy function above to compute a<br> 51similar duration discrepancy number.<br> 52 <br> 53Because timestamp discrepancy is defined in terms of timestamps, we first<br> 54convert the list of durations to monotonically increasing timestamps.<br> 55 <br> 56Args:<br> 57 durations: List of interval lengths in milliseconds.<br> 58 absolute: See TimestampsDiscrepancy.<br> 59 interval_multiplier: See TimestampsDiscrepancy.</tt></dd></dl> 60 <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> 61 <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> 62 <dl><dt><a name="-Median"><strong>Median</strong></a>(values)</dt><dd><tt>Gets the median of a list of values.</tt></dd></dl> 63 <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> 64 <br> 65They're mapped such that for the N samples, the first sample is 0.5/N and the<br> 66last sample is (N-0.5)/N.<br> 67 <br> 68Background: The discrepancy of the sample set i/(N-1); i=0, ..., N-1 is 2/N,<br> 69twice the discrepancy of the sample set (i+1/2)/N; i=0, ..., N-1. In our case<br> 70we don't want to distinguish between these two cases, as our original domain<br> 71is not bounded (it is for Monte Carlo integration, where discrepancy was<br> 72first used).</tt></dd></dl> 73 <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> 74 <br> 75For example, if 17% of the values are less than 5.0, then 5.0 is the 17th<br> 76percentile for this set of values. When the percentage doesn't exactly<br> 77match a rank in the list of values, the percentile is computed using linear<br> 78interpolation between closest ranks.<br> 79 <br> 80Args:<br> 81 values: A list of numerical values.<br> 82 percentile: A number between 0 and 100.<br> 83 <br> 84Returns:<br> 85 The Nth percentile for the list of values, where N is the given percentage.</tt></dd></dl> 86 <dl><dt><a name="-StandardDeviation"><strong>StandardDeviation</strong></a>(data)</dt><dd><tt>Calculates the standard deviation.<br> 87 <br> 88Args:<br> 89 data: A list of samples.<br> 90 <br> 91Returns:<br> 92 The standard deviation of the samples provided.</tt></dd></dl> 93 <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> 94 <br> 95TimestampsDiscrepancy quantifies the largest area of jank observed in a series<br> 96of timestamps. Note that this is different from metrics based on the<br> 97max_time_interval. For example, the time stamp series A = [0,1,2,3,5,6] and<br> 98B = [0,1,2,3,5,7] have the same max_time_interval = 2, but<br> 99<a href="#-Discrepancy">Discrepancy</a>(B) > <a href="#-Discrepancy">Discrepancy</a>(A).<br> 100 <br> 101Two variants of discrepancy can be computed:<br> 102 <br> 103Relative discrepancy is following the original definition of<br> 104discrepancy. It characterized the largest area of jank, relative to the<br> 105duration of the entire time stamp series. We normalize the raw results,<br> 106because the best case discrepancy for a set of N samples is 1/N (for<br> 107equally spaced samples), and we want our metric to report 0.0 in that<br> 108case.<br> 109 <br> 110Absolute discrepancy also characterizes the largest area of jank, but its<br> 111value wouldn't change (except for imprecisions due to a low<br> 112|interval_multiplier|) if additional 'good' intervals were added to an<br> 113exisiting list of time stamps. Its range is [0,inf] and the unit is<br> 114milliseconds.<br> 115 <br> 116The time stamp series C = [0,2,3,4] and D = [0,2,3,4,5] have the same<br> 117absolute discrepancy, but D has lower relative discrepancy than C.<br> 118 <br> 119|timestamps| may be a list of lists S = [S_1, S_2, ..., S_N], where each<br> 120S_i is a time stamp series. In that case, the discrepancy D(S) is:<br> 121D(S) = max(D(S_1), D(S_2), ..., D(S_N))</tt></dd></dl> 122 <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> 123 <dl><dt><a name="-TrapezoidalRule"><strong>TrapezoidalRule</strong></a>(data, dx)</dt><dd><tt>Calculate the integral according to the trapezoidal rule<br> 124 <br> 125TrapezoidalRule approximates the definite integral of f from a to b by<br> 126the composite trapezoidal rule, using n subintervals.<br> 127<a href="http://en.wikipedia.org/wiki/Trapezoidal_rule#Uniform_grid">http://en.wikipedia.org/wiki/Trapezoidal_rule#Uniform_grid</a><br> 128 <br> 129Args:<br> 130 data: A list of samples<br> 131 dx: The uniform distance along the x axis between any two samples<br> 132 <br> 133Returns:<br> 134 The area under the curve defined by the samples and the uniform distance<br> 135 according to the trapezoidal rule.</tt></dd></dl> 136</td></tr></table> 137</body></html>