Commit 6dc8d671 authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

moving EstimatorMap to Estimator

parent cba9860d
#include "MultilevelEstimator.hpp"
EstimatorMap CreateCollocationMap(Levels initLevels, Samples initSamples) {
EstimatorMap estimatorMap;
return estimatorMap;
}
void CreateMonteCarloMap(EstimatorMap &estimatorMap,
Levels initLevels, Samples initSamples) {
for (unsigned long i = 0; i < initLevels.size(); i++) {
bool onlyFine = (i == 0);
int M = initSamples[i];
estimatorMap.insert(
{initLevels[i], new MonteCarlo(initLevels[i], M, onlyFine, true)}
);
}
}
void MultilevelEstimator::Method() {
mout.StartBlock("Multilevel Method");
if (epsilon == 0.0) {
vout(1) << "Non adaptive method" << endl;
vout(1) << "Non-Adaptive Method" << endl;
method();
} else {
vout(1) << "eps=" << to_string(epsilon) << endl;
vout(1) << "epsilon=" << to_string(epsilon) << endl;
adaptiveMethod();
}
......@@ -72,12 +56,6 @@ void MultilevelEstimator::adaptiveMethod() {
}
}
void MultilevelEstimator::PrintInfo() const {
mout.PrintInfo("MultilevelEstimator", verbose,
PrintInfoEntry("initLevels", vec2str(initLevels)),
PrintInfoEntry("initSample", vec2str(initSamples)));
}
void MultilevelEstimator::MultilevelResults() const {
data.MultilevelResults();
}
......
......@@ -8,50 +8,13 @@
#include "Estimator.hpp"
struct EstimatorMap : public LevelMap<Estimator *> {
int maxLevel = 10;
EstimatorMap() {
config.get("maxLevel", maxLevel);
};
EstimatorMap(std::initializer_list<std::pair<int, Estimator *>> estimatorMap) :
LevelMap<Estimator *>(estimatorMap) {
config.get("maxLevel", maxLevel);
};
void UpdateSampleCounter(double epsilon);
void AppendLevel(double epsilon, Exponents exponents, int newLevel);
void SetEstimatorMapData(const MultilevelData &_data) {
for (auto &[level, estimator] : _levelMap) {
estimator->aggregate.ctr = _data.ctrs.at(level);
estimator->aggregate.mean = _data.means.at(level);
estimator->aggregate.sVar = _data.sVars.at(level);
estimator->aggregate.kurtosis = _data.kurtosis.at(level);
}
}
};
typedef std::vector<int> Levels;
typedef std::vector<int> Samples;
EstimatorMap CreateCollocationMap(Levels initLevels, Samples initSamples);
void CreateMonteCarloMap(EstimatorMap &estimatorMap,
Levels initLevels,
Samples initSamples);
class MultilevelEstimator : public Estimator {
private:
int verbose = 1;
Levels initLevels{3, 4, 5};
Levels initLevels;
Samples initSamples{12, 6, 3};
Samples initSamples;
void adaptiveMethod();
......@@ -66,17 +29,15 @@ public:
MultilevelErrors mlErrors;
MultilevelEstimator() : Estimator() {
config.get("MLMCVerbose", verbose);
config.get("initLevels", initLevels);
config.get("initSamples", initSamples);
MultilevelEstimator(Levels initLevels, Samples initSamples,
const std::string &estName, bool parallel,
MeshesCreator meshesCreator = MeshesCreator(),
PDESolverCreator pdeCreator = PDESolverCreator()) : Estimator() {
CreateMonteCarloMap(estimatorMap, initLevels, initSamples);
}
MultilevelEstimator(const EstimatorMap &estimatorMap) :
Estimator(), estimatorMap(estimatorMap) {
config.get("MLMCVerbose", verbose);
estimatorMap.Fill(initLevels, initSamples, estName, parallel,
meshesCreator, pdeCreator);
}
~MultilevelEstimator() {
......@@ -89,8 +50,6 @@ public:
void Method() override;
void PrintInfo() const;
void MultilevelResults() const override;
void ExponentResults() const override;
......
Supports Markdown
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