MultilevelMonteCarlo.h 2.77 KB
Newer Older
1
2
3
#ifndef MULTILEVELMONTECARLO_H
#define MULTILEVELMONTECARLO_H

4
#include "utils/IndentedLogger.hpp"
5
#include "mc/MonteCarloElliptic.h"
6
#include "mc/MonteCarloTransport.h"
7

8

9
class MultilevelMonteCarlo {
10
11
12
13
14
15
16
17
18
private:
    void initializeMapMonteCarlo();

    void initializeValues();

    MonteCarlo *getMonteCarlo(int l, int dM, bool onlyFineLevel);

    void clearMapMonteCarlo();

19
20
21
22
    void wrapUpResults(double &val,
                       double &mlmcCost,
                       vector<int> &listLevels,
                       vector<int> &samples);
23
24
25
26
27
28
29

    void estimateExponents(bool excludeBaseLevel = true);

    bool checkForNewLevel();

    void updateSampleAmount(const double &eps);

niklas.baumgarten's avatar
niklas.baumgarten committed
30
31
32
    void estimateNumericalError();

    void estimateStatisticalError();
33
34
35
36
37

    void appendLevel(double eps);

    static string line();

38
public:
niklas.baumgarten's avatar
..    
niklas.baumgarten committed
39
    int plotting = 0;
40
41
    int verbose = 0;
    IndentedLogger *logger;
42

43
44
45
    int maxLevel, pLevel;
    vector<int> &initLevels, &initSampleAmount;
    map<int, MonteCarlo *> mapMonteCarlo;
46

47
    Meshes *meshes;
48
    MultilevelPlotter &plots;
49
    StochasticField *stochasticField;
50
    Assemble *assemble;
51

52
    vector<int> levels = {}, numsamples = {};
53
    double value = 0.0, cost = 0.0;
54
55
56
57

    bool mcOnly = false;
    vector<vector<int>> levelsOverEpsilon = {}, sampleAmountOverEpsilon = {};
    vector<double> valueOverEpsilon = {}, costOverEpsilon = {};
58

59
    double alpha = 0.0, beta = 0.0, gamma = 0.0;
niklas.baumgarten's avatar
niklas.baumgarten committed
60
    double numErr = 0.0, statErr = 0.0, totalErr = 0.0;
61

62
63
64
    MultilevelMonteCarlo(vector<int> &initLevels,
                         vector<int> &initSampleAmount,
                         Meshes *meshes,
65
                         MultilevelPlotter &plots,
66
67
68
69
70
                         StochasticField *stochasticField,
                         Assemble *assemble) :
        initLevels(initLevels),
        initSampleAmount(initSampleAmount),
        meshes(meshes),
71
        plots(plots),
72
73
        stochasticField(stochasticField),
        assemble(assemble) {
74

75
76
        config.get("MLMCPlotting", plotting);
        config.get("mcOnly", mcOnly);
77

78
79
        config.get("MLMCVerbose", verbose);
        logger = IndentedLogger::GetInstance();
80

81
82
83
        maxLevel = meshes->Level();
        pLevel = meshes->pLevel();

84
        initializeMapMonteCarlo();
85
86
    }

87
88
    ~MultilevelMonteCarlo() {
        delete logger;
89
        clearMapMonteCarlo();
90
91
    }

92
    void Method();
93

94
    void Method(double eps);
niklas.baumgarten's avatar
niklas.baumgarten committed
95

96
    void Method(const vector<double> &epsLst);
97

niklas.baumgarten's avatar
niklas.baumgarten committed
98
99
    void PrintInfo();

100
    static void ShowMCTableHead();
niklas.baumgarten's avatar
niklas.baumgarten committed
101

102
    static void ShowResultsMLMCRunHead();
103

104
    static void ShowTableBottom();
105

106
    void ShowMCTable();
107

108
    void ShowKurtosisWarning();
109

110
    void ShowExponentResults();
111

112
    void ShowResultsMLMCRun(double eps);
113

114
    void ShowResultsOverEpsilon(const vector<double> &epsLst);
115
116
117
};

#endif //MULTILEVELMONTECARLO_H