Index: tools/telemetry/telemetry/util/statistics.py |
diff --git a/tools/perf/metrics/statistics.py b/tools/telemetry/telemetry/util/statistics.py |
similarity index 91% |
rename from tools/perf/metrics/statistics.py |
rename to tools/telemetry/telemetry/util/statistics.py |
index 84ffc164a333035d2f40a2c2c596b41edc19c126..1c988cd2e958597b72aaa4cdda70974ee4e71ebf 100644 |
--- a/tools/perf/metrics/statistics.py |
+++ b/tools/telemetry/telemetry/util/statistics.py |
@@ -159,7 +159,7 @@ def DurationsDiscrepancy(durations, absolute=True, |
return TimestampsDiscrepancy(timestamps, absolute, interval_multiplier) |
-def ArithmeticMean(numerator, denominator): |
+def ArithmeticMean(data): |
"""Calculates arithmetic mean. |
Both numerator and denominator can be given as either individual |
tonyg
2014/03/12 15:28:38
Nit: update the bit about the denominator.
|
@@ -172,11 +172,46 @@ def ArithmeticMean(numerator, denominator): |
Returns: |
The arithmetic mean value, or 0 if the denominator value was 0. |
""" |
- numerator_total = Total(numerator) |
- denominator_total = Total(denominator) |
+ numerator_total = Total(data) |
+ denominator_total = Total(len(data)) |
return DivideIfPossibleOrZero(numerator_total, denominator_total) |
+def StandardDeviation(data): |
tonyg
2014/03/12 15:28:38
Even though these are really common concepts, I re
|
+ if len(data) == 1: |
+ return 0.0 |
+ |
+ mean = ArithmeticMean(data) |
+ variances = [float(x) - mean for x in data] |
+ variances = [x * x for x in variances] |
+ std_dev = math.sqrt(ArithmeticMean(variances)) |
+ |
+ return std_dev |
+ |
+ |
+def StandardErrorOfMean(data): |
+ if len(data) <= 1: |
+ return 0.0 |
+ |
+ std_dev = StandardDeviation(data) |
+ |
+ return std_dev / math.sqrt(len(data)) |
+ |
+ |
+def TrapezoidalRule(data, dx): |
+ """ Calculate the integral according to trapezoidal rule |
+ 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 |
+ """ |
tonyg
2014/03/12 15:28:38
The content of this comment is perfect, but please
|
+ n = len(data) - 1 |
+ s = data[0] + data[n] |
+ |
+ for i in range(1, n): |
+ s += 2 * data[i] |
+ |
+ return s * dx / 2.0 |
+ |
def Total(data): |
"""Returns the float value of a number or the sum of a list.""" |
if type(data) == float: |