stats: Add a way to retrieve the standard deviation

Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
This commit is contained in:
Damien Lespiau 2015-06-25 23:59:21 +01:00
parent 05c10f940f
commit 515cec1210
6 changed files with 46 additions and 2 deletions

View File

@ -22,6 +22,8 @@
* *
*/ */
#include <math.h>
#include "igt_core.h" #include "igt_core.h"
#include "igt_stats.h" #include "igt_stats.h"
@ -86,3 +88,10 @@ double igt_stats_get_variance(igt_stats_t *stats)
return stats->variance; return stats->variance;
} }
double igt_stats_get_std_deviation(igt_stats_t *stats)
{
igt_stats_knuth_mean_variance(stats);
return sqrt(stats->variance);
}

View File

@ -37,3 +37,4 @@ void igt_stats_fini(igt_stats_t *stats);
void igt_stats_push(igt_stats_t *stats, uint64_t value); void igt_stats_push(igt_stats_t *stats, uint64_t value);
double igt_stats_get_mean(igt_stats_t *stats); double igt_stats_get_mean(igt_stats_t *stats);
double igt_stats_get_variance(igt_stats_t *stats); double igt_stats_get_variance(igt_stats_t *stats);
double igt_stats_get_std_deviation(igt_stats_t *stats);

View File

@ -15,5 +15,5 @@ AM_CFLAGS = $(DRM_CFLAGS) $(CWARNFLAGS) \
LDADD = ../libintel_tools.la $(PCIACCESS_LIBS) $(DRM_LIBS) $(LIBUNWIND_LIBS) LDADD = ../libintel_tools.la $(PCIACCESS_LIBS) $(DRM_LIBS) $(LIBUNWIND_LIBS)
LDADD += $(CAIRO_LIBS) $(LIBUDEV_LIBS) $(GLIB_LIBS) LDADD += $(CAIRO_LIBS) $(LIBUDEV_LIBS) $(GLIB_LIBS) -lm
AM_CFLAGS += $(CAIRO_CFLAGS) $(LIBUDEV_CFLAGS) $(GLIB_CFLAGS) AM_CFLAGS += $(CAIRO_CFLAGS) $(LIBUDEV_CFLAGS) $(GLIB_CFLAGS)

View File

@ -45,7 +45,40 @@ static void test_mean(void)
igt_stats_fini(&stats); igt_stats_fini(&stats);
} }
/*
* Taken from the "Basic examples" section of:
* https://en.wikipedia.org/wiki/Standard_deviation
*/
static void test_std_deviation(void)
{
igt_stats_t stats;
double mean, variance, std_deviation;
igt_stats_init(&stats, 8);
igt_stats_push(&stats, 2);
igt_stats_push(&stats, 4);
igt_stats_push(&stats, 4);
igt_stats_push(&stats, 4);
igt_stats_push(&stats, 5);
igt_stats_push(&stats, 5);
igt_stats_push(&stats, 7);
igt_stats_push(&stats, 9);
mean = igt_stats_get_mean(&stats);
igt_assert(mean == (2 + 3 * 4 + 2 * 5 + 7 + 9) / 8.);
variance = igt_stats_get_variance(&stats);
igt_assert(variance == 4);
std_deviation = igt_stats_get_std_deviation(&stats);
igt_assert(std_deviation == 2);
igt_stats_fini(&stats);
}
igt_simple_main igt_simple_main
{ {
test_mean(); test_mean();
test_std_deviation();
} }

View File

@ -8,5 +8,5 @@ endif
AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/lib AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/lib
AM_CFLAGS = $(DRM_CFLAGS) $(PCIACCESS_CFLAGS) $(CWARNFLAGS) $(CAIRO_CFLAGS) $(LIBUNWIND_CFLAGS) AM_CFLAGS = $(DRM_CFLAGS) $(PCIACCESS_CFLAGS) $(CWARNFLAGS) $(CAIRO_CFLAGS) $(LIBUNWIND_CFLAGS)
LDADD = $(top_builddir)/lib/libintel_tools.la $(DRM_LIBS) $(PCIACCESS_LIBS) $(CAIRO_LIBS) $(LIBUDEV_LIBS) $(LIBUNWIND_LIBS) LDADD = $(top_builddir)/lib/libintel_tools.la $(DRM_LIBS) $(PCIACCESS_LIBS) $(CAIRO_LIBS) $(LIBUDEV_LIBS) $(LIBUNWIND_LIBS) -lm

View File

@ -15,6 +15,7 @@ I915ChipsetPython_la_LIBADD = \
$(CAIRO_LIBS) \ $(CAIRO_LIBS) \
$(LIBUNWIND_LIBS) \ $(LIBUNWIND_LIBS) \
-lrt \ -lrt \
-lm \
$(NULL) $(NULL)
chipset.py: chipset_wrap_python.c chipset.py: chipset_wrap_python.c