From patchwork Sat Jun 27 15:08:03 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lespiau, Damien" X-Patchwork-Id: 6685101 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 79F769F1C1 for ; Sat, 27 Jun 2015 15:08:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8B7C32076E for ; Sat, 27 Jun 2015 15:08:47 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 941552076F for ; Sat, 27 Jun 2015 15:08:46 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0282B6E714; Sat, 27 Jun 2015 08:08:46 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by gabe.freedesktop.org (Postfix) with ESMTP id 4E07A6E72C for ; Sat, 27 Jun 2015 08:08:45 -0700 (PDT) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP; 27 Jun 2015 08:08:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,689,1427785200"; d="scan'208";a="515137052" Received: from kczmudzi-mobl4.amr.corp.intel.com (HELO strange.ger.corp.intel.com) ([10.252.53.243]) by FMSMGA003.fm.intel.com with ESMTP; 27 Jun 2015 08:08:44 -0700 From: Damien Lespiau To: intel-gfx@lists.freedesktop.org Date: Sat, 27 Jun 2015 16:08:03 +0100 Message-Id: <1435417696-28115-6-git-send-email-damien.lespiau@intel.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1435417696-28115-1-git-send-email-damien.lespiau@intel.com> References: <1435417696-28115-1-git-send-email-damien.lespiau@intel.com> Subject: [Intel-gfx] [PATCH i-g-t 05/18] stats: Add a way to specify if the data set is a population or a sample X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-5.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This changes how we compute the variance. We want an unbiased variance when reasoning about a sample. Signed-off-by: Damien Lespiau --- lib/igt_stats.c | 35 ++++++++++++++++++++++++++++++++++- lib/igt_stats.h | 2 ++ lib/tests/igt_stats.c | 1 + tools/skl_compute_wrpll.c | 1 + 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/lib/igt_stats.c b/lib/igt_stats.c index 0bee138..c7d5fbd 100644 --- a/lib/igt_stats.c +++ b/lib/igt_stats.c @@ -92,6 +92,36 @@ void igt_stats_fini(igt_stats_t *stats) } /** + * igt_stats_set_population: + * @stats: An #igt_stats_t instance + * @full_population: Whether we're dealing with sample data or a full + * population + * + * In statistics, we usually deal with a subset of the full data (which may be + * a continuous or infinite set). Data analysis is then done on a sample of + * this population. + * + * This has some importance as only having a sample of the data leads to + * [biased estimators](https://en.wikipedia.org/wiki/Bias_of_an_estimator). We + * currently used the information given by this method to apply + * [Bessel's correction](https://en.wikipedia.org/wiki/Bessel%27s_correction) + * to the variance. + * + * When giving #true to this function, the data set in @stats is considered a + * full population. It's considered a sample of a bigger population otherwise. + * + * When newly created, @stats defaults to holding sample data. + */ +void igt_stats_set_population(igt_stats_t *stats, bool full_population) +{ + if (full_population == stats->is_population) + return; + + stats->is_population = full_population; + stats->mean_variance_valid = false; +} + +/** * igt_stats_push: * @stats: An #igt_stats_t instance * @value: An integer value @@ -129,7 +159,10 @@ static void igt_stats_knuth_mean_variance(igt_stats_t *stats) } stats->mean = mean; - stats->variance = m2 / stats->n_values; + if (stats->n_values > 1 && !stats->is_population) + stats->variance = m2 / (stats->n_values - 1); + else + stats->variance = m2 / stats->n_values; stats->mean_variance_valid = true; } diff --git a/lib/igt_stats.h b/lib/igt_stats.h index c45c819..d2c1cc7 100644 --- a/lib/igt_stats.h +++ b/lib/igt_stats.h @@ -38,12 +38,14 @@ typedef struct { /*< private >*/ unsigned int capacity; + unsigned int is_population : 1; unsigned int mean_variance_valid : 1; double mean, variance; } igt_stats_t; void igt_stats_init(igt_stats_t *stats, unsigned int capacity); void igt_stats_fini(igt_stats_t *stats); +void igt_stats_set_population(igt_stats_t *stats, bool full_population); void igt_stats_push(igt_stats_t *stats, uint64_t value); double igt_stats_get_mean(igt_stats_t *stats); double igt_stats_get_variance(igt_stats_t *stats); diff --git a/lib/tests/igt_stats.c b/lib/tests/igt_stats.c index f76d334..59097c8 100644 --- a/lib/tests/igt_stats.c +++ b/lib/tests/igt_stats.c @@ -89,6 +89,7 @@ static void test_std_deviation(void) double mean, variance, std_deviation; igt_stats_init(&stats, 8); + igt_stats_set_population(&stats, true); igt_stats_push(&stats, 2); igt_stats_push(&stats, 4); diff --git a/tools/skl_compute_wrpll.c b/tools/skl_compute_wrpll.c index cf808c7..8b6fcd3 100644 --- a/tools/skl_compute_wrpll.c +++ b/tools/skl_compute_wrpll.c @@ -867,6 +867,7 @@ static void test_run(struct test_ops *test) igt_stats_t stats; igt_stats_init(&stats, ARRAY_SIZE(modes)); + igt_stats_set_population(&stats, true); for (m = 0; m < ARRAY_SIZE(modes); m++) { struct skl_wrpll_params params = {};