Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Mpp
MLUQ
Commits
8f2f51ac
Commit
8f2f51ac
authored
Sep 13, 2019
by
niklas.baumgarten
Browse files
added python tools for printing
parent
cb450abc
Changes
9
Hide whitespace changes
Inline
Side-by-side
CMakeLists.txt
View file @
8f2f51ac
...
...
@@ -34,10 +34,11 @@ find_package(LAPACK REQUIRED)
#---------------------------------------------------------------------------------------#
# 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/py
)
file
(
MAKE_DIRECTORY
${
PROJECT_BINARY_DIR
}
/data/vtk
)
file
(
MAKE_DIRECTORY
${
PROJECT_BINARY_DIR
}
/log
)
file
(
MAKE_DIRECTORY
${
PROJECT_BINARY_DIR
}
/data/dual
)
#---------------------------------------------------------------------------------------#
# Include directories
...
...
mlmc/conf/mlmc.conf
View file @
8f2f51ac
#
Model = LinearFEM
Model
=
LinearFEM
#Model = QuadraticFEM
#Model = MixedFEM
#Model = HybridFEM
Model
=
FVFEM
#
Model = FVFEM
#Model = LinearDGFEM
#Model = QuadraticDGFEM
...
...
@@ -16,13 +16,14 @@ StochasticField = LogNormal
#Experiment = MLMCExperiment
Experiment
=
MLMCOverEpsilon
init
=
3
size_
init
=
3
l_init
=
3
4
5
M_init
=
8
4
2
Lmax
=
8
M_init
=
12
6
3
Lmax
=
9
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
functional
=
L2
...
...
@@ -34,3 +35,5 @@ MCVerbose = 1
MLMCVerbose
=
2
MCPlotting
=
0
MLMCPlotting
=
0
enablePython
=
1
\ No newline at end of file
mlmc/src/MLMCMain.C
View file @
8f2f51ac
...
...
@@ -96,6 +96,9 @@ void MLMCMain::run() {
mlmc
->
showMCTable
();
mlmc
->
showKurtosisWarning
();
mlmc
->
showExponentResults
();
if
(
enablePython
==
1
)
{
system
(
"python3 ../tools/plot_statistics.py ConvergenceTest"
);
}
}
else
if
(
experimentName
==
"MLMCExperiment"
)
{
headMLMCExperiment
();
mlmc
->
method
(
epsilon
);
...
...
@@ -103,9 +106,18 @@ void MLMCMain::run() {
mlmc
->
showResultsMLMCRun
(
epsilon
);
mlmc
->
showKurtosisWarning
();
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"
)
{
headMLMCOverEpsilon
();
mlmc
->
method
(
epsilon_lst
);
mlmc
->
showMCTable
();
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
mlmc/src/MLMCMain.h
View file @
8f2f51ac
...
...
@@ -9,9 +9,10 @@
class
MLMCMain
{
public:
int
enablePython
=
1
;
double
epsilon
=
0.1
;
int
init
=
3
,
plevel
=
2
,
Lmax
=
8
;
vector
<
int
>
l_init
=
{
3
,
4
,
5
},
M_init
=
{
8
,
4
,
2
};
int
size_
init
=
3
,
plevel
=
2
,
Lmax
=
8
,
size_lst
=
3
;
vector
<
int
>
l_init
=
{
3
,
4
,
5
},
M_init
=
{
12
,
6
,
3
};
vector
<
double
>
epsilon_lst
=
{
0.1
,
0.05
,
0.01
};
string
problemName
=
""
,
modelName
=
""
;
string
fieldName
=
""
,
experimentName
=
""
;
...
...
@@ -26,13 +27,15 @@ public:
MultilevelMonteCarlo
*
mlmc
=
nullptr
;
MLMCMain
()
{
ReadConfig
(
Settings
,
"enablePython"
,
enablePython
);
ReadConfig
(
Settings
,
"epsilon"
,
epsilon
);
ReadConfig
(
Settings
,
"plevel"
,
plevel
);
ReadConfig
(
Settings
,
"Lmax"
,
Lmax
);
ReadConfig
(
Settings
,
"init"
,
init
);
ReadConfig
(
Settings
,
"l_init"
,
l_init
,
init
);
ReadConfig
(
Settings
,
"M_init"
,
M_init
,
init
);
ReadConfig
(
Settings
,
"epsilon_lst"
,
epsilon_lst
,
init
);
ReadConfig
(
Settings
,
"size_init"
,
size_init
);
ReadConfig
(
Settings
,
"l_init"
,
l_init
,
size_init
);
ReadConfig
(
Settings
,
"M_init"
,
M_init
,
size_init
);
ReadConfig
(
Settings
,
"size_lst"
,
size_lst
);
ReadConfig
(
Settings
,
"epsilon_lst"
,
epsilon_lst
,
size_lst
);
ReadConfig
(
Settings
,
"Problem"
,
problemName
);
ReadConfig
(
Settings
,
"Model"
,
modelName
);
ReadConfig
(
Settings
,
"StochasticField"
,
fieldName
);
...
...
mlmc/src/Main.C
View file @
8f2f51ac
#include
"m++.h"
#include
"MLMCMain.h"
#ifdef COMPLEX
#error undef COMPLEX in src/Compiler.h
#endif
#include
"MLMCMain.h"
int
main
(
int
argv
,
char
**
argc
)
{
SetSearchPath
(
"../mlmc"
,
argv
,
argc
);
DPO
dpo
(
&
argv
,
&
argc
);
...
...
@@ -13,5 +12,6 @@ int main(int argv, char **argc) {
auto
mlmcMain
=
new
MLMCMain
();
mlmcMain
->
run
();
delete
mlmcMain
;
return
0
;
}
mlmc/src/MultilevelMonteCarlo.C
View file @
8f2f51ac
...
...
@@ -94,7 +94,7 @@ void MultilevelMonteCarlo::method(const double eps) {
void
MultilevelMonteCarlo
::
method
(
const
vector
<
double
>
&
eps_lst
)
{
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
)
{
initializeMapMC
();
...
...
mlmc/src/Utils.C
View file @
8f2f51ac
...
...
@@ -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
)
{
int
N2
=
in
.
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
j
=
0
;
j
<
N1
;
j
++
)
{
in_arr
[
i
*
N2
+
j
][
REAL
]
=
in
[
i
][
j
].
real
();
...
...
tools/plot_mlmc.py
View file @
8f2f51ac
import
r
e
from
datetime
import
datetim
e
import
pandas
as
pd
import
numpy
as
np
import
sys
import
re
L1
=
" eps value MLMC cost l M
\n
"
L2
=
"--------------------------------------------------------------------------------
\n
"
def
read_log
():
...
...
@@ -14,12 +19,15 @@ def read_log():
columns
=
[
"eps"
,
"value"
,
"MLMC cost"
,
"MC cost"
,
"l"
,
"M"
]
df
=
pd
.
DataFrame
(
columns
=
columns
)
reading
=
False
ctr
=
0
for
line
in
content
:
if
line
[
0
:
3
]
==
"---"
:
reading
=
not
reading
if
line
==
L1
:
ctr
+=
1
continue
if
reading
:
if
0
<
ctr
<
3
:
if
line
==
L2
:
ctr
+=
1
continue
matches
=
pattern
.
findall
(
line
)
eps
=
float
(
matches
[
0
])
...
...
@@ -31,19 +39,23 @@ def read_log():
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
):]]
column
=
[
eps
,
value
,
MLMC_cost
,
MC_cost
,
l
,
M
]
df_to_append
=
pd
.
DataFrame
([
column
],
columns
=
columns
)
df_row
=
[
eps
,
value
,
MLMC_cost
,
MC_cost
,
l
,
M
]
df_to_append
=
pd
.
DataFrame
([
df_row
],
columns
=
columns
)
df
=
df
.
append
(
df_to_append
)
df
=
df
.
set_index
(
'eps'
)
return
df
def
plot_content
(
df
):
def
plot_content
(
df
,
plot_name
):
if
df
.
empty
:
return
import
matplotlib.pyplot
as
plt
# M vs l over epsilon
fig
=
plt
.
figure
(
figsize
=
(
13
,
5
))
# M vs l over epsilon
ax1
=
fig
.
add_subplot
(
1
,
2
,
1
)
for
eps
in
df
.
index
:
plt
.
plot
(
df
.
loc
[
eps
,
'l'
],
df
.
loc
[
eps
,
'M'
],
...
...
@@ -79,9 +91,13 @@ def plot_content(df):
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__"
:
df
=
read_log
()
plot_content
(
df
)
argv
=
sys
.
argv
argv1
=
argv
[
1
]
results
=
read_log
()
plot_content
(
results
,
argv1
)
tools/plot_statistics.py
View file @
8f2f51ac
from
datetime
import
datetime
import
pandas
as
pd
import
sys
import
re
L1
=
" l M E[Qf-Qc] E[Qf] V[Qf-Qc] V[Qf] kurtosis cost
\n
"
...
...
@@ -48,7 +50,7 @@ def read_log():
return
df
def
plot_content
(
df
):
def
plot_content
(
df
,
plot_name
):
if
df
.
empty
:
return
...
...
@@ -90,9 +92,13 @@ def plot_content(df):
ax2
.
set_xticks
(
df
.
index
)
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
()
plot_content
(
statistics
)
plot_content
(
statistics
,
argv1
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment