Browse Source

Include missing header and fix stddev

Standard deviation on a non complete population sample is divided by n-1, not n
v2
Xerbo 1 year ago
parent
commit
c551e70335
No known key found for this signature in database GPG Key ID: 34103F6D8F11CEB0
2 changed files with 4 additions and 6 deletions
  1. +3
    -6
      libaptdec/algebra.c
  2. +1
    -0
      libaptdec/effects.c

+ 3
- 6
libaptdec/algebra.c View File

@@ -52,12 +52,9 @@ linear_t linear_regression(const float *independent, const float *dependent, siz
return (linear_t){a, b}; return (linear_t){a, b};
} }


// "Sample" standard deviation
float standard_deviation(const float *data, size_t len) { 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; float deviation_mean = 0.0f;
for (size_t i = 0; i < len; i++) { 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; 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) { float sumf(const float *x, size_t len) {


+ 1
- 0
libaptdec/effects.c View File

@@ -20,6 +20,7 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <math.h> #include <math.h>
#include <stdlib.h>


#include "algebra.h" #include "algebra.h"
#include "util.h" #include "util.h"


Loading…
Cancel
Save