summaryrefslogtreecommitdiff
path: root/lib/igt_stats.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2015-07-01 13:50:02 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2015-07-01 18:58:46 +0100
commit19135a34471ec4da4d7cc8493c371b8c38879f0b (patch)
treea5792c9e39c96d325d1522ee6391d1f0f08b2867 /lib/igt_stats.c
parent669b5da2bc4ef8d80405aef96ebb831a39608db4 (diff)
stats: Add the interquartile mean (IQM)
https://en.wikipedia.org/wiki/Interquartile_mean The IQM is a truncated mean and so is very similar to the scoring method used in sports that are evaluated by a panel of judges: discard the lowest and the highest scores; calculate the mean value of the remaining scores. It's useful to hide outliers in measurements (due to cold cache etc), without having to worry too much about the actual distribution. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'lib/igt_stats.c')
-rw-r--r--lib/igt_stats.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/igt_stats.c b/lib/igt_stats.c
index 9032a685..cec35876 100644
--- a/lib/igt_stats.c
+++ b/lib/igt_stats.c
@@ -491,3 +491,40 @@ double igt_stats_get_std_deviation(igt_stats_t *stats)
return sqrt(stats->variance);
}
+
+/**
+ * igt_stats_get_iqm:
+ * @stats: An #igt_stats_t instance
+ *
+ * Retrieves the interquartile mean of the @stats dataset.
+ *
+ * The interquartile mean is a "statistical measure of central tendency".
+ * It is a truncated mean that discards the lowest and highest 25% of values,
+ * and calculates the mean value of the remaining central values.
+ */
+double igt_stats_get_iqm(igt_stats_t *stats)
+{
+ unsigned int q1, q3, i;
+ double mean;
+
+ igt_stats_ensure_sorted_values(stats);
+
+ q1 = (stats->n_values + 3) / 4;
+ q3 = 3 * stats->n_values / 4;
+
+ mean = 0;
+ for (i = 0; i <= q3 - q1; i++)
+ mean += (stats->sorted[q1 + i] - mean) / (i + 1);
+
+ if (stats->n_values % 4) {
+ double rem = .5 * (stats->n_values % 4) / 4;
+
+ q1 = (stats->n_values) / 4;
+ q3 = (3 * stats->n_values + 3) / 4;
+
+ mean += rem * (stats->sorted[q1] - mean) / i++;
+ mean += rem * (stats->sorted[q3] - mean) / i++;
+ }
+
+ return mean;
+}