This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
stellar-stellar/decoders/session_flags/onlinemean.c

38 lines
816 B
C

#include <math.h>
#include "onlinemean.h"
void OnlineMean_Init(OnlineMean_t *oMean) {
OnlineMean_Reset(oMean);
}
void OnlineMean_Update(OnlineMean_t *oMean, float newValue) {
oMean->count++;
if (oMean->count > 1) {
float delta = newValue - oMean->mean;
oMean->mean += delta / oMean->count;
oMean->varsum += delta * (newValue - oMean->mean);
} else {
oMean->mean = newValue;
}
}
float OnlineMean_GetMean(OnlineMean_t *oMean) {
return oMean->mean;
}
float OnlineMean_GetStd(OnlineMean_t *oMean) {
if (oMean->count == 0)
return 0;
#if UNBIASED_ESTIMATOR
return sqrt(oMean->varsum / (oMean->count - 1));
#else
return sqrt(oMean->varsum / oMean->count);
#endif /* UNBIASED_ESTIMATOR */
}
void OnlineMean_Reset(OnlineMean_t *oMean) {
oMean->count = 0;
oMean->mean = 0.f;
oMean->varsum = 0.f;
}