Commit 68111e28 authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

refactoring of mlmc method and of console output

parent d05092df
......@@ -153,17 +153,17 @@ void MLMCMain::run() {
}
void MLMCMain::printParameters() {
mout << "Problem = \t" << problemName << endl;
mout << "Model = \t" << modelName << endl;
mout << "Experiment = \t" << experimentName << endl;
mout << "StochField = \t" << fieldName << endl;
mout << "l_init = \t" << vec2str(l_init) << endl;
mout << "M_init = \t" << vec2str(M_init) << endl;
mout << "Problem \t=\t" << problemName << endl;
mout << "Model \t=\t" << modelName << endl;
mout << "Experiment\t=\t" << experimentName << endl;
mout << "StochField\t=\t" << fieldName << endl;
mout << "l_init \t=\t" << vec2str(l_init) << endl;
mout << "M_init \t=\t" << vec2str(M_init) << endl;
if (experimentName == "MLMCExperiment")
mout << "eps = \t" << epsilon << endl;
mout << "eps \t=\t" << epsilon << endl;
if (experimentName == "MLMCOverEpsilon")
mout << "eps_lst = \t" << vec2str(epsilon_lst) << endl;
mout << "Lmax = \t" << Lmax << endl;
mout << "plevel = \t" << plevel << endl;
mout << "enablePy = \t" << enablePython << endl;
mout << "eps_lst \t=\t" << vec2str(epsilon_lst) << endl;
mout << "Lmax \t=\t" << Lmax << endl;
mout << "plevel \t=\t" << plevel << endl;
mout << "enablePy \t=\t" << enablePython << endl;
}
......@@ -51,26 +51,13 @@ void MultilevelMonteCarlo::method(const double eps) {
for (auto &mc : map_mc)
if (mc.second->dM > 0)
mc.second->method();
estimateExponents();
updateNumSamples(eps);
if (checkForNewLevel()) {
double err = estimateNumericalError();
if (err > eps / sqrt(2.0)) {
int L = map_mc.rbegin()->first + 1;
if (L > Lmax) {
Exit ("Maximum level has been reached.")
} else {
logger->logMSGV2("append level " + to_string(L));
map_mc[L] = getMonteCarlo(L, 0, false);
map_mc[L]->var_Y = map_mc[L - 1]->var_Y / pow(2.0, beta);
map_mc[L]->avg_cost = map_mc[L - 1]->avg_cost * pow(2.0, gamma);
updateNumSamples(eps);
}
} else {
if (estimateNumericalError() > eps / sqrt(2.0))
appendLevel(eps);
else
converged = true;
}
}
}
Vector u((*graphs)[map_mc.rbegin()->first - pLevel]);
......@@ -81,7 +68,7 @@ void MultilevelMonteCarlo::method(const double eps) {
void MultilevelMonteCarlo::method(const vector<double> &eps_lst) {
logger->startMethodMSG();
logger->increase_indent();
// logger->increase_indent();
for (auto &eps : eps_lst) {
initializeMapMC();
initializeValuesMLMC();
......@@ -91,7 +78,7 @@ void MultilevelMonteCarlo::method(const vector<double> &eps_lst) {
value_vs_eps.push_back(value);
cost_vs_eps.push_back(cost);
}
logger->decrease_indent();
// logger->decrease_indent();
logger->endMethodMSG();
}
......@@ -115,10 +102,9 @@ void MultilevelMonteCarlo::estimateExponents(bool excludeBaseLevel) {
v = linear_fit(level_lst, costs);
gamma = v.front();
string msg = "alpha: " + to_string(alpha) +
" beta: " + to_string(beta) +
" gamma: " + to_string(gamma);
logger->logMSGV2(msg);
logger->logMSGV2("alpha: " + to_string(alpha) +
" beta: " + to_string(beta) +
" gamma: " + to_string(gamma));
}
void MultilevelMonteCarlo::updateNumSamples(const double &eps) {
......@@ -159,9 +145,24 @@ double MultilevelMonteCarlo::estimateNumericalError() {
maxErr);
exponent--;
}
logger->logMSGV2("err: " + to_string(maxErr));
return maxErr;
}
void MultilevelMonteCarlo::appendLevel(double eps) {
int L = map_mc.rbegin()->first + 1;
if (L > Lmax) {
Exit ("Maximum level has been reached.")
} else {
logger->logMSGV2("new level: " + to_string(L));
map_mc[L] = getMonteCarlo(L, 0, false);
map_mc[L]->var_Y = map_mc[L - 1]->var_Y / pow(2.0, beta);
map_mc[L]->avg_cost = map_mc[L - 1]->avg_cost * pow(2.0, gamma);
updateNumSamples(eps);
}
}
void MultilevelMonteCarlo::wrapUpResults(Vector &u, double &val, double &mlmc_cost,
vector<int> &level_lst, vector<int> &samples) {
int L = map_mc.rbegin()->first;
......
......@@ -63,6 +63,8 @@ public:
double estimateNumericalError();
void appendLevel(double eps);
void wrapUpResults(Vector &u, double &val, double &mlmc_cost,
vector<int> &level_lst, vector<int> &samples);
......
......@@ -88,7 +88,6 @@ public:
virtual void upscale(const Vector &uc, Vector &uc_up) = 0;
virtual void method() = 0;
};
#endif //MLMC_MC_HPP
\ No newline at end of file
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