Commit 0da032ee authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

Introduced StatisticMeasures

parent 9793ff71
#include "StatisticMeasures.hpp"
#include "utility/Assertion.h"
#include <math.h>
void Sums::Update(double fineCost, double diffQ, double fineQ) {
Cost += fineCost;
Q1 += fineQ;
Q2 += fineQ * fineQ;
Q3 += fineQ * fineQ * fineQ;
Q4 += fineQ * fineQ * fineQ * fineQ;
Y1 += diffQ;
Y2 += diffQ * diffQ;
Y3 += diffQ * diffQ * diffQ;
Y4 += diffQ * diffQ * diffQ * diffQ;
}
void Averages::Update(Sums sums, int M) {
Cost = sums.Cost / M;
Y = abs(sums.Y1 / M);
Y2 = sums.Y2 / M;
Y3 = sums.Y3 / M;
Y4 = sums.Y4 / M;
Q = abs(sums.Q1 / M);
Q2 = sums.Q2 / M;
}
void Variances::Update(Averages avgs) {
Y = fmax(avgs.Y2 - avgs.Y * avgs.Y, 1e-10);
Q = fmax(avgs.Q2 - avgs.Q * avgs.Q, 1e-10);
}
void Kurtosis::Update(Averages avgs, Variances vars) {
// Q = (avgs.Q4 - 4.0 * avgs.Q3 * avgs.Q + 6.0 * avgs.Q2 * avgs.Q * avgs.Q -
// 3.0 * avgs.Q * avgs.Q * avgs.Q * avgs.Q) / vars.Q / vars.Q;
Y = (avgs.Y4 - 4.0 * avgs.Y3 * avgs.Y + 6.0 * avgs.Y2 * avgs.Y * avgs.Y -
3.0 * avgs.Y * avgs.Y * avgs.Y * avgs.Y) / vars.Y / vars.Y;
if (Y > 100.0)
Warning("Kurtosis of Y above 100!")
}
#ifndef STATISTICMEASURES_HPP
#define STATISTICMEASURES_HPP
struct SampleCounter {
int M = 0;
int dM = 0;
void Update() {
M += dM;
dM = 0;
}
};
struct Sums {
double Cost = 0.0;
double Q1 = 0.0;
double Q2 = 0.0;
double Q3 = 0.0;
double Q4 = 0.0;
double Y1 = 0.0;
double Y2 = 0.0;
double Y3 = 0.0;
double Y4 = 0.0;
void Update(double fineCost, double diffQ, double fineQ);
};
struct Averages {
double Cost = 0.0;
double Y = 0.0;
double Y2 = 0.0;
double Y3 = 0.0;
double Y4 = 0.0;
double Q = 0.0;
double Q2 = 0.0;
void Update(Sums sums, int M);
};
struct Variances {
double Q = 0.0;
double Y = 0.0;
void Update(Averages avgs);
};
struct Kurtosis {
double Q = 0.0;
double Y = 0.0;
void Update(Averages avgs, Variances vars);
};
#endif //STATISTICMEASURES_HPP
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment