Commit e986c755 authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

minor fixes and refactorings

parent 20630b52
Pipeline #149284 failed with stages
in 13 minutes and 41 seconds
......@@ -32,6 +32,7 @@ smoothing = 1.0
PDESolverPlotting = 0
# ----- Verbose -----
precision = 3
MCVerbose = 1
MLMCVerbose = 1
MainVerbose = 1
......
......@@ -10,8 +10,14 @@ struct Exponents;
class Estimator {
protected:
int verbose = 1;
double epsilon = 0.0;
double value;
double cost;
Errors errors;
public:
......@@ -31,7 +37,16 @@ public:
virtual std::string Name() const { return "Estimator"; };
virtual void EstimatorResults() const {};
virtual void EstimatorResults() const {
mout.PrintInfo("Estimator Results", verbose,
PrintInfoEntry("Value", value),
PrintInfoEntry("Cost", cost),
PrintInfoEntry("Epsilon", epsilon),
PrintInfoEntry("Total Error", errors.total),
PrintInfoEntry("Numerical Error", errors.numeric),
PrintInfoEntry("Stochastical Error", errors.stochastic)
);
};
virtual void MultilevelResults() const {};
......
......@@ -30,6 +30,10 @@ void MultilevelEstimator::Method() {
data.ExtractDataFrom(estimatorMap);
exponents.ComputeExponents(data);
mlErrors.Estimate(data);
value = data.means.Q;
cost = data.means.Cost;
errors = mlErrors;
mout.EndBlock(verbose == 0);
}
......@@ -54,14 +58,14 @@ void MultilevelEstimator::adaptiveMethod() {
vout(1) << "dM=" << vec2str(data.ctrs.GetdMVector()) << endl;
if (data.ctrs.NoSamplesLeft()) {
errors.Estimate(data);
vout(1) << "numErr=" << errors.numeric << endl;
mlErrors.Estimate(data);
vout(1) << "numErr=" << mlErrors.numeric << endl;
if (errors.numeric > epsilon / 2) {
if (mlErrors.numeric > epsilon / 2) {
estimatorMap.AppendLevel(epsilon, exponents, estimatorMap.rbegin()->first + 1);
} else {
errors.Estimate(data);
vout(1) << "statErr=" << errors.stochastic << endl;
mlErrors.Estimate(data);
vout(1) << "statErr=" << mlErrors.stochastic << endl;
converged = true;
}
}
......@@ -78,16 +82,6 @@ void MultilevelEstimator::MultilevelResults() const {
data.MultilevelResults();
}
void MultilevelEstimator::EstimatorResults() const {
mout.PrintInfo("MLMC Results", verbose,
PrintInfoEntry("Value", data.means.Q),
PrintInfoEntry("Cost", data.means.Cost),
PrintInfoEntry("Epsilon", epsilon),
PrintInfoEntry("Total Error", errors.total),
PrintInfoEntry("Statistical Error", errors.stochastic),
PrintInfoEntry("Numerical Error", errors.numeric));
}
void MultilevelEstimator::ExponentResults() const {
mout.PrintInfo("Exponents", verbose,
PrintInfoEntry("Final alpha", exponents.alpha),
......
......@@ -64,7 +64,7 @@ public:
Exponents exponents;
MultilevelErrors errors;
MultilevelErrors mlErrors;
MultilevelEstimator() : Estimator() {
config.get("MLMCVerbose", verbose);
......@@ -82,14 +82,14 @@ public:
estimatorMap.clear();
}
std::string Name() const override { return "MultilevelMonteCarlo"; }
std::string Name() const override {
return "Multilevel" + estimatorMap.begin()->second->Name();
}
void Method() override;
void PrintInfo() const;
void EstimatorResults() const override;
void MultilevelResults() const override;
void ExponentResults() const override;
......
......@@ -21,8 +21,7 @@ std::string vec2str<double>(std::vector<double> vec) {
if (i != vec.size() - 1) {
streamObj << vec[i];
str += streamObj.str() + ", ";
}
else {
} else {
streamObj << vec[i];
str += streamObj.str();
}
......@@ -113,8 +112,9 @@ void MultilevelData::MultilevelResults() const {
PrintInfoEntry("E(Qf)", vec2str(means.GetQVector())),
PrintInfoEntry("V(Qf-Qc)", vec2str(sVars.GetYVector())),
PrintInfoEntry("V(Qf)", vec2str(sVars.GetQVector())),
PrintInfoEntry("kurtosis", vec2str(kurtosis.GetYVector())),
PrintInfoEntry("kurtosis", vec2str(kurtosis.GetYVector()), 2),
PrintInfoEntry("E(cost)", vec2str(means.GetCostVector())),
// PrintInfoEntry("Cost per Level", vec2str(means.GetCostVector() )),
PrintInfoEntry("Used Levels", vec2str(means.GetLevelVector())),
PrintInfoEntry("Used Samples", vec2str(ctrs.GetMVector())));
}
This diff is collapsed.
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