Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Mpp
MLUQ
Commits
b42bc922
Commit
b42bc922
authored
Mar 11, 2020
by
niklas.baumgarten
Browse files
added error functions
parent
1625dfd7
Changes
4
Hide whitespace changes
Inline
Side-by-side
mlmc/src/MultilevelMonteCarlo.C
View file @
b42bc922
...
@@ -28,6 +28,7 @@ void MultilevelMonteCarlo::initializeValues() {
...
@@ -28,6 +28,7 @@ void MultilevelMonteCarlo::initializeValues() {
levels
=
{},
numsamples
=
{};
levels
=
{},
numsamples
=
{};
value
=
0
.
0
,
cost
=
0
.
0
;
value
=
0
.
0
,
cost
=
0
.
0
;
alpha
=
0
.
0
,
beta
=
0
.
0
,
gamma
=
0
.
0
;
alpha
=
0
.
0
,
beta
=
0
.
0
,
gamma
=
0
.
0
;
numErr
=
0
.
0
,
statErr
=
0
.
0
,
totalErr
=
0
.
0
;
}
}
void
MultilevelMonteCarlo
::
clearMapMonteCarlo
()
{
void
MultilevelMonteCarlo
::
clearMapMonteCarlo
()
{
...
@@ -55,10 +56,14 @@ void MultilevelMonteCarlo::Method(const double eps) {
...
@@ -55,10 +56,14 @@ void MultilevelMonteCarlo::Method(const double eps) {
estimateExponents
();
estimateExponents
();
updateSampleAmount
(
eps
);
updateSampleAmount
(
eps
);
if
(
checkForNewLevel
())
{
if
(
checkForNewLevel
())
{
if
(
estimateNumericalError
()
>
eps
/
sqrt
(
2
.
0
))
estimateNumericalError
();
if
(
numErr
>
eps
)
{
appendLevel
(
eps
);
appendLevel
(
eps
);
else
}
else
{
estimateStatisticalError
();
totalErr
=
statErr
+
numErr
;
converged
=
true
;
converged
=
true
;
}
}
}
}
}
wrapUpResults
(
value
,
cost
,
levels
,
numsamples
);
wrapUpResults
(
value
,
cost
,
levels
,
numsamples
);
...
@@ -132,19 +137,25 @@ bool MultilevelMonteCarlo::checkForNewLevel() {
...
@@ -132,19 +137,25 @@ bool MultilevelMonteCarlo::checkForNewLevel() {
return
newLevel
;
return
newLevel
;
}
}
double
MultilevelMonteCarlo
::
estimateNumericalError
()
{
void
MultilevelMonteCarlo
::
estimateNumericalError
()
{
double
max
Err
=
0
.
0
;
num
Err
=
0
.
0
;
unsigned
long
exponent
=
mapMonteCarlo
.
size
()
-
2
;
unsigned
long
exponent
=
mapMonteCarlo
.
size
()
-
2
;
for
(
auto
&
mc
:
mapMonteCarlo
)
{
for
(
auto
&
mc
:
mapMonteCarlo
)
{
if
(
mc
.
first
==
mapMonteCarlo
.
begin
()
->
first
)
continue
;
if
(
mc
.
first
==
mapMonteCarlo
.
begin
()
->
first
)
continue
;
maxErr
=
max
(
mc
.
second
->
avgY
/
(
pow
(
2
.
0
,
alpha
)
-
1
)
/
numErr
=
max
(
mc
.
second
->
avgY
/
(
pow
(
2
.
0
,
alpha
)
-
1
)
/
(
pow
(
2
.
0
,
exponent
)),
(
pow
(
2
.
0
,
exponent
)),
numErr
);
maxErr
);
exponent
--
;
exponent
--
;
}
}
logger
->
InnerMsg
(
"err: "
+
to_string
(
maxErr
),
verbose
);
logger
->
InnerMsg
(
"estimated numerical error: "
+
to_string
(
numErr
),
verbose
);
return
maxErr
;
}
void
MultilevelMonteCarlo
::
estimateStatisticalError
()
{
statErr
=
0
.
0
;
for
(
auto
&
mc
:
mapMonteCarlo
)
{
statErr
+=
mc
.
second
->
varY
/
mc
.
second
->
M
;
}
statErr
=
sqrt
(
statErr
);
}
}
void
MultilevelMonteCarlo
::
appendLevel
(
double
eps
)
{
void
MultilevelMonteCarlo
::
appendLevel
(
double
eps
)
{
...
@@ -231,12 +242,18 @@ void MultilevelMonteCarlo::ShowKurtosisWarning() {
...
@@ -231,12 +242,18 @@ void MultilevelMonteCarlo::ShowKurtosisWarning() {
void
MultilevelMonteCarlo
::
ShowExponentResults
()
{
void
MultilevelMonteCarlo
::
ShowExponentResults
()
{
estimateExponents
();
estimateExponents
();
mout
<<
endl
<<
"alpha = "
<<
setw
(
8
)
<<
alpha
mout
<<
endl
<<
"alpha = "
<<
setw
(
10
)
<<
alpha
<<
" (exponent for the weak convergence of the FEM)"
<<
" (exponent for the weak convergence of the FEM)"
<<
endl
<<
" beta = "
<<
setw
(
8
)
<<
beta
<<
endl
<<
" beta = "
<<
setw
(
10
)
<<
beta
<<
" (exponent for the decay of the variance)"
<<
" (exponent for the decay of the variance)"
<<
endl
<<
"gamma = "
<<
setw
(
8
)
<<
gamma
<<
endl
<<
"gamma = "
<<
setw
(
10
)
<<
gamma
<<
" (exponent for the growth of the cost)"
<<
" (exponent for the growth of the cost)"
<<
endl
<<
"numErr = "
<<
setw
(
10
)
<<
numErr
<<
" (estimated numerical error)"
<<
endl
<<
"statErr = "
<<
setw
(
10
)
<<
statErr
<<
" (estimated statistical error)"
<<
endl
<<
"error = "
<<
setw
(
10
)
<<
totalErr
<<
" (estimated total error)"
<<
endl
;
<<
endl
;
}
}
...
...
mlmc/src/MultilevelMonteCarlo.h
View file @
b42bc922
...
@@ -27,7 +27,9 @@ private:
...
@@ -27,7 +27,9 @@ private:
void
updateSampleAmount
(
const
double
&
eps
);
void
updateSampleAmount
(
const
double
&
eps
);
double
estimateNumericalError
();
void
estimateNumericalError
();
void
estimateStatisticalError
();
void
appendLevel
(
double
eps
);
void
appendLevel
(
double
eps
);
...
@@ -55,6 +57,7 @@ public:
...
@@ -55,6 +57,7 @@ public:
vector
<
double
>
valueOverEpsilon
=
{},
costOverEpsilon
=
{};
vector
<
double
>
valueOverEpsilon
=
{},
costOverEpsilon
=
{};
double
alpha
=
0.0
,
beta
=
0.0
,
gamma
=
0.0
;
double
alpha
=
0.0
,
beta
=
0.0
,
gamma
=
0.0
;
double
numErr
=
0.0
,
statErr
=
0.0
,
totalErr
=
0.0
;
MultilevelMonteCarlo
(
vector
<
int
>
&
initLevels
,
MultilevelMonteCarlo
(
vector
<
int
>
&
initLevels
,
vector
<
int
>
&
initSampleAmount
,
vector
<
int
>
&
initSampleAmount
,
...
...
mlmc/src/mc/MonteCarloElliptic.C
View file @
b42bc922
...
@@ -22,8 +22,6 @@ void MonteCarloElliptic::method() {
...
@@ -22,8 +22,6 @@ void MonteCarloElliptic::method() {
assemble
->
plot
=
finePlot
;
assemble
->
plot
=
finePlot
;
assemble
->
problem
->
LoadNewSample
(
&
finePermeability
);
assemble
->
problem
->
LoadNewSample
(
&
finePermeability
);
mout
<<
finePermeability
<<
endl
;
solvePDE
(
l
,
m
,
true
,
fineQ
,
fineCost
,
fineSolution
);
solvePDE
(
l
,
m
,
true
,
fineQ
,
fineCost
,
fineSolution
);
if
(
plotting
)
assemble
->
PlotResults
(
fineSolution
);
if
(
plotting
)
assemble
->
PlotResults
(
fineSolution
);
...
...
mlmc/src/mc/MonteCarloTransport.C
View file @
b42bc922
...
@@ -71,7 +71,7 @@ void MonteCarloTransport::solvePDE(int l,
...
@@ -71,7 +71,7 @@ void MonteCarloTransport::solvePDE(int l,
if
(
functional
==
"Energy"
)
valueQ
=
assemble
->
Energy
(
solution
);
if
(
functional
==
"Energy"
)
valueQ
=
assemble
->
Energy
(
solution
);
if
(
functional
==
"Outflow"
)
if
(
functional
==
"Outflow"
)
valueQ
=
assemble
->
InFlowOutFlowRate
(
solution
).
second
;
valueQ
=
assemble
->
InFlowOutFlowRate
(
solution
).
second
;
mout
<<
endl
;
logger
->
EndMethod
(
verbose
);
logger
->
EndMethod
(
verbose
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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