Commit 8f2f51ac authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

added python tools for printing

parent cb450abc
...@@ -34,10 +34,11 @@ find_package(LAPACK REQUIRED) ...@@ -34,10 +34,11 @@ find_package(LAPACK REQUIRED)
#---------------------------------------------------------------------------------------# #---------------------------------------------------------------------------------------#
# Manage folder structure build folder # Manage folder structure build folder
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/data/vtk) file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/data/dual)
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/data/gp) file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/data/gp)
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/data/py)
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/data/vtk)
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/log) file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/log)
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/data/dual)
#---------------------------------------------------------------------------------------# #---------------------------------------------------------------------------------------#
# Include directories # Include directories
......
#Model = LinearFEM Model = LinearFEM
#Model = QuadraticFEM #Model = QuadraticFEM
#Model = MixedFEM #Model = MixedFEM
#Model = HybridFEM #Model = HybridFEM
Model = FVFEM #Model = FVFEM
#Model = LinearDGFEM #Model = LinearDGFEM
#Model = QuadraticDGFEM #Model = QuadraticDGFEM
...@@ -16,13 +16,14 @@ StochasticField = LogNormal ...@@ -16,13 +16,14 @@ StochasticField = LogNormal
#Experiment = MLMCExperiment #Experiment = MLMCExperiment
Experiment = MLMCOverEpsilon Experiment = MLMCOverEpsilon
init = 3 size_init = 3
l_init = 3 4 5 l_init = 3 4 5
M_init = 8 4 2 M_init = 12 6 3
Lmax = 8 Lmax = 9
epsilon = 0.01 epsilon = 0.01
epsilon_lst = 0.01 0.005 0.003 size_lst = 4
epsilon_lst = 0.01 0.005 0.003 0.001
plevel = 2 plevel = 2
functional = L2 functional = L2
...@@ -34,3 +35,5 @@ MCVerbose = 1 ...@@ -34,3 +35,5 @@ MCVerbose = 1
MLMCVerbose = 2 MLMCVerbose = 2
MCPlotting = 0 MCPlotting = 0
MLMCPlotting = 0 MLMCPlotting = 0
enablePython = 1
\ No newline at end of file
...@@ -96,6 +96,9 @@ void MLMCMain::run() { ...@@ -96,6 +96,9 @@ void MLMCMain::run() {
mlmc->showMCTable(); mlmc->showMCTable();
mlmc->showKurtosisWarning(); mlmc->showKurtosisWarning();
mlmc->showExponentResults(); mlmc->showExponentResults();
if (enablePython == 1) {
system("python3 ../tools/plot_statistics.py ConvergenceTest");
}
} else if (experimentName == "MLMCExperiment") { } else if (experimentName == "MLMCExperiment") {
headMLMCExperiment(); headMLMCExperiment();
mlmc->method(epsilon); mlmc->method(epsilon);
...@@ -103,9 +106,18 @@ void MLMCMain::run() { ...@@ -103,9 +106,18 @@ void MLMCMain::run() {
mlmc->showResultsMLMCRun(epsilon); mlmc->showResultsMLMCRun(epsilon);
mlmc->showKurtosisWarning(); mlmc->showKurtosisWarning();
mlmc->showExponentResults(); mlmc->showExponentResults();
if (enablePython == 1 && PPM->master()) {
system("python3 ../tools/plot_statistics.py MLMCExperiment");
system("python3 ../tools/plot_mlmc.py MLMCExperiment");
}
} else if (experimentName == "MLMCOverEpsilon") { } else if (experimentName == "MLMCOverEpsilon") {
headMLMCOverEpsilon(); headMLMCOverEpsilon();
mlmc->method(epsilon_lst); mlmc->method(epsilon_lst);
mlmc->showMCTable();
mlmc->showResultsOverEpsilon(epsilon_lst); mlmc->showResultsOverEpsilon(epsilon_lst);
if (enablePython == 1 && PPM->master()) {
system("python3 ../tools/plot_statistics.py MLMCOverEpsilon");
system("python3 ../tools/plot_mlmc.py MLMCOverEpsilon");
}
} }
} }
\ No newline at end of file
...@@ -9,9 +9,10 @@ ...@@ -9,9 +9,10 @@
class MLMCMain { class MLMCMain {
public: public:
int enablePython = 1;
double epsilon = 0.1; double epsilon = 0.1;
int init = 3, plevel = 2, Lmax = 8; int size_init = 3, plevel = 2, Lmax = 8, size_lst = 3;
vector<int> l_init = {3, 4, 5}, M_init = {8, 4, 2}; vector<int> l_init = {3, 4, 5}, M_init = {12, 6, 3};
vector<double> epsilon_lst = {0.1, 0.05, 0.01}; vector<double> epsilon_lst = {0.1, 0.05, 0.01};
string problemName = "", modelName = ""; string problemName = "", modelName = "";
string fieldName = "", experimentName = ""; string fieldName = "", experimentName = "";
...@@ -26,13 +27,15 @@ public: ...@@ -26,13 +27,15 @@ public:
MultilevelMonteCarlo *mlmc = nullptr; MultilevelMonteCarlo *mlmc = nullptr;
MLMCMain() { MLMCMain() {
ReadConfig(Settings, "enablePython", enablePython);
ReadConfig(Settings, "epsilon", epsilon); ReadConfig(Settings, "epsilon", epsilon);
ReadConfig(Settings, "plevel", plevel); ReadConfig(Settings, "plevel", plevel);
ReadConfig(Settings, "Lmax", Lmax); ReadConfig(Settings, "Lmax", Lmax);
ReadConfig(Settings, "init", init); ReadConfig(Settings, "size_init", size_init);
ReadConfig(Settings, "l_init", l_init, init); ReadConfig(Settings, "l_init", l_init, size_init);
ReadConfig(Settings, "M_init", M_init, init); ReadConfig(Settings, "M_init", M_init, size_init);
ReadConfig(Settings, "epsilon_lst", epsilon_lst, init); ReadConfig(Settings, "size_lst", size_lst);
ReadConfig(Settings, "epsilon_lst", epsilon_lst, size_lst);
ReadConfig(Settings, "Problem", problemName); ReadConfig(Settings, "Problem", problemName);
ReadConfig(Settings, "Model", modelName); ReadConfig(Settings, "Model", modelName);
ReadConfig(Settings, "StochasticField", fieldName); ReadConfig(Settings, "StochasticField", fieldName);
......
#include "m++.h" #include "m++.h"
#include "MLMCMain.h"
#ifdef COMPLEX #ifdef COMPLEX
#error undef COMPLEX in src/Compiler.h #error undef COMPLEX in src/Compiler.h
#endif #endif
#include "MLMCMain.h"
int main(int argv, char **argc) { int main(int argv, char **argc) {
SetSearchPath("../mlmc", argv, argc); SetSearchPath("../mlmc", argv, argc);
DPO dpo(&argv, &argc); DPO dpo(&argv, &argc);
...@@ -13,5 +12,6 @@ int main(int argv, char **argc) { ...@@ -13,5 +12,6 @@ int main(int argv, char **argc) {
auto mlmcMain = new MLMCMain(); auto mlmcMain = new MLMCMain();
mlmcMain->run(); mlmcMain->run();
delete mlmcMain; delete mlmcMain;
return 0; return 0;
} }
...@@ -94,7 +94,7 @@ void MultilevelMonteCarlo::method(const double eps) { ...@@ -94,7 +94,7 @@ void MultilevelMonteCarlo::method(const double eps) {
void MultilevelMonteCarlo::method(const vector<double> &eps_lst) { void MultilevelMonteCarlo::method(const vector<double> &eps_lst) {
Date Start; Date Start;
vout (1) << "Start multilevel Monte Carlo method only for initial values" << endl; vout (1) << "Start multilevel Monte Carlo method for several epsilon" << endl;
for (auto &eps : eps_lst) { for (auto &eps : eps_lst) {
initializeMapMC(); initializeMapMC();
......
...@@ -83,7 +83,7 @@ void fft2(int N2, int N1, fftw_complex *in, fftw_complex *out) { ...@@ -83,7 +83,7 @@ void fft2(int N2, int N1, fftw_complex *in, fftw_complex *out) {
void fft2(const vector<vector<complex<double>>> &in, vector<vector<complex<double>>> &out) { void fft2(const vector<vector<complex<double>>> &in, vector<vector<complex<double>>> &out) {
int N2 = in.size(); int N2 = in.size();
int N1 = in[0].size(); int N1 = in[0].size();
fftw_complex in_arr[N2 * N1], out_arr[N2 * N1]; //Todo: Strange crash on Level 9 fftw_complex in_arr[N2 * N1], out_arr[N2 * N1]; //Todo: Strange crash for N1 = N2 =1023
for (int i = 0; i < N2; i++) { for (int i = 0; i < N2; i++) {
for (int j = 0; j < N1; j++) { for (int j = 0; j < N1; j++) {
in_arr[i * N2 + j][REAL] = in[i][j].real(); in_arr[i * N2 + j][REAL] = in[i][j].real();
......
import re from datetime import datetime
import pandas as pd import pandas as pd
import numpy as np import numpy as np
import sys
import re
L1 = " eps value MLMC cost l M\n"
L2 = "--------------------------------------------------------------------------------\n"
def read_log(): def read_log():
...@@ -14,12 +19,15 @@ def read_log(): ...@@ -14,12 +19,15 @@ def read_log():
columns = ["eps", "value", "MLMC cost", "MC cost", "l", "M"] columns = ["eps", "value", "MLMC cost", "MC cost", "l", "M"]
df = pd.DataFrame(columns=columns) df = pd.DataFrame(columns=columns)
reading = False ctr = 0
for line in content: for line in content:
if line[0:3] == "---": if line == L1:
reading = not reading ctr += 1
continue continue
if reading: if 0 < ctr < 3:
if line == L2:
ctr += 1
continue
matches = pattern.findall(line) matches = pattern.findall(line)
eps = float(matches[0]) eps = float(matches[0])
...@@ -31,19 +39,23 @@ def read_log(): ...@@ -31,19 +39,23 @@ def read_log():
l = [int(match) for match in matches[3:3 + int(rest_length / 2)]] l = [int(match) for match in matches[3:3 + int(rest_length / 2)]]
M = [int(match) for match in matches[3 + int(rest_length / 2):]] M = [int(match) for match in matches[3 + int(rest_length / 2):]]
column = [eps, value, MLMC_cost, MC_cost, l, M] df_row = [eps, value, MLMC_cost, MC_cost, l, M]
df_to_append = pd.DataFrame([column], columns=columns) df_to_append = pd.DataFrame([df_row], columns=columns)
df = df.append(df_to_append) df = df.append(df_to_append)
df = df.set_index('eps') df = df.set_index('eps')
return df return df
def plot_content(df): def plot_content(df, plot_name):
if df.empty:
return
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
# M vs l over epsilon
fig = plt.figure(figsize=(13, 5)) fig = plt.figure(figsize=(13, 5))
# M vs l over epsilon
ax1 = fig.add_subplot(1, 2, 1) ax1 = fig.add_subplot(1, 2, 1)
for eps in df.index: for eps in df.index:
plt.plot(df.loc[eps, 'l'], df.loc[eps, 'M'], plt.plot(df.loc[eps, 'l'], df.loc[eps, 'M'],
...@@ -79,9 +91,13 @@ def plot_content(df): ...@@ -79,9 +91,13 @@ def plot_content(df):
ax2.grid(which='major') ax2.grid(which='major')
plt.show() now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
path = '../build/data/py/Overview{} {}.png'.format(plot_name, now)
plt.savefig(path)
if __name__ == "__main__": if __name__ == "__main__":
df = read_log() argv = sys.argv
plot_content(df) argv1 = argv[1]
results = read_log()
plot_content(results, argv1)
from datetime import datetime
import pandas as pd import pandas as pd
import sys
import re import re
L1 = " l M E[Qf-Qc] E[Qf] V[Qf-Qc] V[Qf] kurtosis cost\n" L1 = " l M E[Qf-Qc] E[Qf] V[Qf-Qc] V[Qf] kurtosis cost\n"
...@@ -48,7 +50,7 @@ def read_log(): ...@@ -48,7 +50,7 @@ def read_log():
return df return df
def plot_content(df): def plot_content(df, plot_name):
if df.empty: if df.empty:
return return
...@@ -90,9 +92,13 @@ def plot_content(df): ...@@ -90,9 +92,13 @@ def plot_content(df):
ax2.set_xticks(df.index) ax2.set_xticks(df.index)
ax2.grid(which='major') ax2.grid(which='major')
plt.show() now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
path = '../build/data/py/Statistics{} {}.png'.format(plot_name, now)
plt.savefig(path)
if __name__ == "__main__": if __name__ == '__main__':
argv = sys.argv
argv1 = argv[1]
statistics = read_log() statistics = read_log()
plot_content(statistics) plot_content(statistics, argv1)
Markdown is supported
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