summaryrefslogtreecommitdiff
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
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>
-rw-r--r--lib/igt_stats.c37
-rw-r--r--lib/igt_stats.h1
2 files changed, 38 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;
+}
diff --git a/lib/igt_stats.h b/lib/igt_stats.h
index dd04097f..00fb9b1f 100644
--- a/lib/igt_stats.h
+++ b/lib/igt_stats.h
@@ -61,6 +61,7 @@ uint64_t igt_stats_get_range(igt_stats_t *stats);
void igt_stats_get_quartiles(igt_stats_t *stats,
double *q1, double *q2, double *q3);
double igt_stats_get_iqr(igt_stats_t *stats);
+double igt_stats_get_iqm(igt_stats_t *stats);
double igt_stats_get_mean(igt_stats_t *stats);
double igt_stats_get_median(igt_stats_t *stats);
double igt_stats_get_variance(igt_stats_t *stats);