EmpiricMeasures.cpp 1.59 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
6
void Sums::Update(SampleSolution &fineSolution, SampleSolution &coarseSolution) {
    Cost += fineSolution.Cost;
7
8
9
10
11
12
13
    double Qf = fineSolution.Q;
    double Qc = coarseSolution.Q;
    double diffQ = Qf - Qc;
    Q += Qf;
    Q2 += Qf * Qf;
    Q3 += Qf * Qf * Qf;
    Q4 += Qf * Qf * Qf * Qf;
14
    Y += diffQ;
15
16
17
18
19
20
21
    Y2 += diffQ * diffQ;
    Y3 += diffQ * diffQ * diffQ;
    Y4 += diffQ * diffQ * diffQ * diffQ;
}

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

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) {
38
39
    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;
40
41
    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;
42
    if (Y > 100.0) Warning("Kurtosis of Y above 100!")
43
}
niklas.baumgarten's avatar
niklas.baumgarten committed
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

void SampleCounter::UpdateSampleCounter(int dM) {
  this->dM = dM;
  if (parallel) {
    for (int i = 0; i < ceil(log2(PPM->Size(0))) + 1; i++) {
      if (dM >= PPM->Size(i)) {
        dMComm = ceil((double) dM / PPM->Size(i));
        commSplit = PPM->MaxCommSplit() - i;
        break;
      }
    }
  } else {
    dMComm = dM;
    commSplit = 0;
  }
}