From c551e7033513369e1cc57b0473d9ee2712b5e163 Mon Sep 17 00:00:00 2001 From: Xerbo Date: Tue, 24 Jan 2023 14:21:56 +0000 Subject: [PATCH] Include missing header and fix stddev Standard deviation on a non complete population sample is divided by n-1, not n --- libaptdec/algebra.c | 9 +++------ libaptdec/effects.c | 1 + 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/libaptdec/algebra.c b/libaptdec/algebra.c index e922a1e..20f4160 100644 --- a/libaptdec/algebra.c +++ b/libaptdec/algebra.c @@ -52,12 +52,9 @@ linear_t linear_regression(const float *independent, const float *dependent, siz return (linear_t){a, b}; } +// "Sample" standard deviation float standard_deviation(const float *data, size_t len) { - float mean = 0.0f; - for (size_t i = 0; i < len; i++) { - mean += data[i]; - } - mean /= (float)len; + float mean = meanf(data, len); float deviation_mean = 0.0f; for (size_t i = 0; i < len; i++) { @@ -65,7 +62,7 @@ float standard_deviation(const float *data, size_t len) { deviation_mean += deviation * deviation; } - return sqrtf(deviation_mean / (float)len); + return sqrtf(deviation_mean / (float)(len-1)); } float sumf(const float *x, size_t len) { diff --git a/libaptdec/effects.c b/libaptdec/effects.c index e48e584..61ab0ae 100644 --- a/libaptdec/effects.c +++ b/libaptdec/effects.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "algebra.h" #include "util.h"