EmpiricMeasureLevelMaps.hpp 2.96 KB
Newer Older
1
2
3
#ifndef EMPIRICMEASURELEVELMAPS_HPP
#define EMPIRICMEASURELEVELMAPS_HPP

4
#include "WelfordAggregate.hpp"
5
#include "basics/Level.hpp"
niklas.baumgarten's avatar
niklas.baumgarten committed
6
#include "montecarlo/MonteCarlo.hpp"
7
8
9
10
11
#include <math.h>


struct Exponents;

niklas.baumgarten's avatar
niklas.baumgarten committed
12
struct MonteCarloMap : public LevelMap<MonteCarlo> {
13

niklas.baumgarten's avatar
niklas.baumgarten committed
14
15
16
17
18
    int maxLevel = 10;

    MonteCarloMap() {
        config.get("maxLevel", maxLevel);
    };
19

niklas.baumgarten's avatar
niklas.baumgarten committed
20
    MonteCarloMap(std::initializer_list<std::pair<int, MonteCarlo>> mcMap) :
niklas.baumgarten's avatar
niklas.baumgarten committed
21
        LevelMap<MonteCarlo>(mcMap) {
niklas.baumgarten's avatar
niklas.baumgarten committed
22
23
        config.get("maxLevel", maxLevel);
    };
24

25
26
    void UpdateSampleCounter(double epsilon);

niklas.baumgarten's avatar
niklas.baumgarten committed
27
    void AppendLevel(double epsilon, Exponents exponents, int newLevel);
28
29
};

niklas.baumgarten's avatar
niklas.baumgarten committed
30
struct SampleCounterMap : public LevelMap<SampleCounter> {
31
32

    SampleCounterMap() {};
33

niklas.baumgarten's avatar
niklas.baumgarten committed
34
    SampleCounterMap(std::initializer_list<std::pair<int, SampleCounter>> ctrs) :
35
36
        LevelMap<SampleCounter>(ctrs) {};

37
38
39
40
41
    void Update(const MonteCarloMap &mcMap);

    bool NoSamplesLeft();
};

niklas.baumgarten's avatar
niklas.baumgarten committed
42
struct MeanMap : public LevelMap<Mean> {
43
44
45
    double Q = 0.0;
    double Cost = 0.0;

niklas.baumgarten's avatar
niklas.baumgarten committed
46
    MeanMap() {};
47

niklas.baumgarten's avatar
niklas.baumgarten committed
48
49
    MeanMap(std::initializer_list<std::pair<int, Mean>> avgs) :
        LevelMap<Mean>(avgs) {};
50

niklas.baumgarten's avatar
niklas.baumgarten committed
51
    MeanMap(const MonteCarloMap &mcMap) {
52
53
54
55
56
57
        Update(mcMap);
    };

    void Update(const MonteCarloMap &mcMap);
};

niklas.baumgarten's avatar
niklas.baumgarten committed
58
struct SVarMap : public LevelMap<SVar> {
59

niklas.baumgarten's avatar
niklas.baumgarten committed
60
    SVarMap() {};
61

niklas.baumgarten's avatar
niklas.baumgarten committed
62
63
    SVarMap(std::initializer_list<std::pair<int, SVar>> vars) :
        LevelMap<SVar>(vars) {};
64

niklas.baumgarten's avatar
niklas.baumgarten committed
65
    SVarMap(const MonteCarloMap &mcMap) {
66
67
68
69
70
71
72
73
74
75
        Update(mcMap);
    };

    void Update(const MonteCarloMap &mcMap);
};

struct KurtosisMap : LevelMap<Kurtosis> {

    KurtosisMap() {};

niklas.baumgarten's avatar
niklas.baumgarten committed
76
    KurtosisMap(std::initializer_list<std::pair<int, Kurtosis>> kurtosis) :
77
78
        LevelMap<Kurtosis>(kurtosis) {};

79
80
81
82
83
84
85
86
87
    KurtosisMap(const MonteCarloMap &mcMap) {
        Update(mcMap);
    };

    void Update(const MonteCarloMap &mcMap);
};

struct MultiLevelMonteCarloData {
    SampleCounterMap ctrs;
niklas.baumgarten's avatar
niklas.baumgarten committed
88
89
    MeanMap avgs;
    SVarMap vars;
90
91
92
93
94
95
96
97
    KurtosisMap kurtosis;

    MultiLevelMonteCarloData() {};

    MultiLevelMonteCarloData(const MonteCarloMap &mcMap) {
        ExtractDataFrom(mcMap);
    }

niklas.baumgarten's avatar
niklas.baumgarten committed
98
99
    MultiLevelMonteCarloData(const SampleCounterMap &ctrs, const MeanMap &avgs,
                             const SVarMap &vars, const KurtosisMap &kurtosis) :
niklas.baumgarten's avatar
niklas.baumgarten committed
100
101
        ctrs(ctrs), avgs(avgs), vars(vars), kurtosis(kurtosis) {};

102
    void ExtractDataFrom(const MonteCarloMap &mcMap);
niklas.baumgarten's avatar
niklas.baumgarten committed
103
104
105
106
107
108
109
110
111
112
113

    friend Logging &operator<<(Logging &s, const MultiLevelMonteCarloData &data) {
        return s << "E(Qf-Qc)=" << data.avgs.GetYVector() << endl
            << "E(Qf)=" << data.avgs.GetQVector() << endl
            << "V(Qf-Qc)=" << data.vars.GetYVector() << endl
            << "V(Qf)=" << data.vars.GetQVector() << endl
            << "kurtosis=" << data.kurtosis.GetYVector() << endl
            << "E(cost)=" << data.avgs.GetCostVector() << endl
            << "Used Levels=" << data.avgs.GetLevelVector() << endl
            << "Used Samples" << data.ctrs.GetMVector() << endl;
    }
114
115
116
};

#endif //EMPIRICMEASURELEVELMAPS_HPP