EmpiricMeasures.cpp 1.35 KB
Newer Older
niklas.baumgarten's avatar
niklas.baumgarten committed
1
#include "EmpiricMeasures.hpp"
niklas.baumgarten's avatar
niklas.baumgarten committed
2
#include "utility/Assertion.hpp"
3
4


5
void Sums::Update(SampleSolution &fineSolution, SampleSolution &coarseSolution) {
6
    double diffQ = fineSolution.Q - coarseSolution.Q; // Todo might be unstable!
7
    Cost += fineSolution.Cost;
8
    Q += fineSolution.Q;
9
10
11
    Q2 += fineSolution.Q * fineSolution.Q;
    Q3 += fineSolution.Q * fineSolution.Q * fineSolution.Q;
    Q4 += fineSolution.Q * fineSolution.Q * fineSolution.Q * fineSolution.Q;
12
    Y += diffQ;
13
14
15
16
17
18
19
    Y2 += diffQ * diffQ;
    Y3 += diffQ * diffQ * diffQ;
    Y4 += diffQ * diffQ * diffQ * diffQ;
}

void Averages::Update(Sums sums, int M) {
    Cost = sums.Cost / M;
20
    Y = abs(sums.Y / M);
21
22
23
    Y2 = sums.Y2 / M;
    Y3 = sums.Y3 / M;
    Y4 = sums.Y4 / M;
24
    Q = abs(sums.Q / M);
25
    Q2 = sums.Q2 / M;
26
27
    Q3 = sums.Q3 / M;
    Q4 = sums.Q4 / M;
28
29
30
31
32
33
34
35
}

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) {
36
37
    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;
38
39
40
41
42
    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!")
}