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
79edfc7d
Commit
79edfc7d
authored
Oct 27, 2020
by
niklas.baumgarten
Browse files
introducing TestExponents and adaption of EmpiricMeasures
parent
579ff138
Changes
8
Hide whitespace changes
Inline
Side-by-side
mlmc/src/montecarlo/EmpiricMeasureLevelMaps.cpp
View file @
79edfc7d
#include
"EmpiricMeasureLevelMaps.hpp"
#include
"Exponents.hpp"
void
MonteCarloMap
::
UpdateSampleCounter
(
double
epsilon
)
{
int
optimalM
;
...
...
mlmc/src/montecarlo/EmpiricMeasureLevelMaps.hpp
View file @
79edfc7d
...
...
@@ -52,6 +52,21 @@ struct LevelMap : std::map<Level, T> {
dMVector
.
push_back
(
entry
.
dM
);
return
dMVector
;
}
std
::
map
<
Level
,
T
>
SetWithVectors
(
std
::
vector
<
Level
>
levels
,
std
::
vector
<
T
>
entries
)
{
for
(
int
i
=
0
;
i
<
levels
.
size
();
i
++
)
(
*
this
)[
levels
[
i
]]
=
entries
[
i
];
return
*
this
;
}
LevelMap
()
{};
LevelMap
(
std
::
initializer_list
<
std
::
pair
<
Level
,
T
>>
levelMap
)
{
for
(
std
::
pair
<
Level
,
T
>
pair
:
levelMap
)
{
this
->
emplace
(
pair
.
first
,
ConfigEntry
(
pair
.
second
));
}
}
};
struct
Exponents
;
...
...
@@ -64,7 +79,14 @@ struct MonteCarloMap : LevelMap<MonteCarlo *> {
Level
newLevel
,
MonteCarlo
*
newMc
);
};
//SampleCounterMap ctrs = {
//
//};
struct
SampleCounterMap
:
LevelMap
<
SampleCounter
>
{
double
ding
=
1.0
;
SampleCounterMap
()
{};
void
Update
(
const
MonteCarloMap
&
mcMap
);
...
...
mlmc/src/montecarlo/EmpiricMeasures.cpp
View file @
79edfc7d
...
...
@@ -10,11 +10,11 @@ void SampleCounter::Update() {
void
Sums
::
Update
(
SampleSolution
&
fineSolution
,
SampleSolution
&
coarseSolution
)
{
double
diffQ
=
fineSolution
.
Q
-
coarseSolution
.
Q
;
// Todo might be unstable!
Cost
+=
fineSolution
.
Cost
;
Q
1
+=
fineSolution
.
Q
;
Q
+=
fineSolution
.
Q
;
Q2
+=
fineSolution
.
Q
*
fineSolution
.
Q
;
Q3
+=
fineSolution
.
Q
*
fineSolution
.
Q
*
fineSolution
.
Q
;
Q4
+=
fineSolution
.
Q
*
fineSolution
.
Q
*
fineSolution
.
Q
*
fineSolution
.
Q
;
Y
1
+=
diffQ
;
Y
+=
diffQ
;
Y2
+=
diffQ
*
diffQ
;
Y3
+=
diffQ
*
diffQ
*
diffQ
;
Y4
+=
diffQ
*
diffQ
*
diffQ
*
diffQ
;
...
...
@@ -22,11 +22,11 @@ void Sums::Update(SampleSolution &fineSolution, SampleSolution &coarseSolution)
void
Averages
::
Update
(
Sums
sums
,
int
M
)
{
Cost
=
sums
.
Cost
/
M
;
Y
=
abs
(
sums
.
Y
1
/
M
);
Y
=
abs
(
sums
.
Y
/
M
);
Y2
=
sums
.
Y2
/
M
;
Y3
=
sums
.
Y3
/
M
;
Y4
=
sums
.
Y4
/
M
;
Q
=
abs
(
sums
.
Q
1
/
M
);
Q
=
abs
(
sums
.
Q
/
M
);
Q2
=
sums
.
Q2
/
M
;
Q3
=
sums
.
Q3
/
M
;
Q4
=
sums
.
Q4
/
M
;
...
...
mlmc/src/montecarlo/EmpiricMeasures.hpp
View file @
79edfc7d
...
...
@@ -8,15 +8,20 @@ struct SampleCounter {
int
M
=
0
;
int
dM
=
0
;
SampleCounter
()
{};
SampleCounter
(
int
M
,
int
dM
)
:
M
(
M
),
dM
(
dM
)
{}
void
Update
();
};
struct
Sums
{
double
Q
1
=
0.0
;
double
Q
=
0.0
;
double
Q2
=
0.0
;
double
Q3
=
0.0
;
double
Q4
=
0.0
;
double
Y
1
=
0.0
;
double
Y
=
0.0
;
double
Y2
=
0.0
;
double
Y3
=
0.0
;
double
Y4
=
0.0
;
...
...
@@ -26,6 +31,12 @@ struct Sums {
//
// Vector V;
Sums
()
{};
Sums
(
double
Q
,
double
Q2
,
double
Q3
,
double
Q4
,
double
Y
,
double
Y2
,
double
Y3
,
double
Y4
,
double
Cost
)
:
Q
(
Q
),
Q2
(
Q2
),
Q3
(
Q3
),
Q4
(
Q4
),
Y
(
Y
),
Y2
(
Y2
),
Y3
(
Y3
),
Y4
(
Y4
),
Cost
(
Cost
)
{}
void
Update
(
SampleSolution
&
fineSolution
,
SampleSolution
&
coarseSolution
);
};
...
...
@@ -40,6 +51,12 @@ struct Averages {
double
Y4
=
0.0
;
double
Cost
=
0.0
;
Averages
()
{};
Averages
(
double
Q
,
double
Q2
,
double
Q3
,
double
Q4
,
double
Y
,
double
Y2
,
double
Y3
,
double
Y4
,
double
Cost
)
:
Q
(
Q
),
Q2
(
Q2
),
Q3
(
Q3
),
Q4
(
Q4
),
Y
(
Y
),
Y2
(
Y2
),
Y3
(
Y3
),
Y4
(
Y4
),
Cost
(
Cost
)
{}
void
Update
(
Sums
sums
,
int
M
);
};
...
...
@@ -47,6 +64,10 @@ struct Variances {
double
Q
=
0.0
;
double
Y
=
0.0
;
Variances
()
{};
Variances
(
double
Q
,
double
Y
)
:
Q
(
Q
),
Y
(
Y
)
{}
void
Update
(
Averages
avgs
);
};
...
...
tests/TestExponents.cpp
deleted
100644 → 0
View file @
579ff138
#include
"TestExponents.hpp"
#include
"montecarlo/Exponents.hpp"
#include
"TestEnvironment.hpp"
//std::map<Level, SampleCounter> a = {
// {Level(1), SampleCounter()}
//};
//
//const SampleCounterMap ctrs = {
// {Level(1), SampleCounter()}
//};
class
TestExponents
:
Test
{
void
SetUp
()
override
{
Level
level
(
1
);
MultiLevelMonteCarloData
data
{
SampleCounterMap
{},
AveragesMap
{},
VariancesMap
{},
KurtosisMap
{},
};
Exponents
exponents
();
}
void
TearDown
()
override
{
Config
::
close
();
}
};
\ No newline at end of file
tests/TestExponents.hpp
deleted
100644 → 0
View file @
579ff138
#ifndef TESTEXPONENTS_HPP
#define TESTEXPONENTS_HPP
#endif //TESTEXPONENTS_HPP
tests/unit/TestExponents.cpp
0 → 100644
View file @
79edfc7d
#include
"TestExponents.hpp"
#include
"TestEnvironment.hpp"
class
TestExponents
:
public
Test
{
protected:
SampleCounterMap
ctrs
;
AveragesMap
avgs
;
VariancesMap
vars
;
KurtosisMap
kurtosis
;
Exponents
exponents
;
void
SetUp
()
override
{
ctrs
.
SetWithVectors
(
levelVec
,
ctrVec
);
avgs
.
SetWithVectors
(
levelVec
,
avgVec
);
vars
.
SetWithVectors
(
levelVec
,
varVec
);
kurtosis
.
SetWithVectors
(
levelVec
,
kurtosisVec
);
MultiLevelMonteCarloData
data
{
ctrs
,
avgs
,
vars
,
kurtosis
};
}
void
TearDown
()
override
{
Config
::
close
();
}
};
TEST_F
(
TestExponents
,
TestAlpha
)
{
ASSERT_FLOAT_EQ
(
exponents
.
ComputeAlpha
(
avgs
),
1.0
);
}
TEST_F
(
TestExponents
,
TestBeta
)
{
ASSERT_FLOAT_EQ
(
exponents
.
ComputeBeta
(
vars
),
2.0
);
}
TEST_F
(
TestExponents
,
TestGamma
)
{
ASSERT_FLOAT_EQ
(
exponents
.
ComputeGamma
(
avgs
),
1.0
);
}
int
main
(
int
argc
,
char
**
argv
)
{
MppTest
mppTest
=
MppTestBuilder
(
argc
,
argv
);
return
mppTest
.
RUN_ALL_MPP_TESTS
();
}
\ No newline at end of file
tests/unit/TestExponents.hpp
0 → 100644
View file @
79edfc7d
#ifndef TESTEXPONENTS_HPP
#define TESTEXPONENTS_HPP
#include
"montecarlo/Exponents.hpp"
#include
<vector>
std
::
vector
<
Level
>
levelVec
=
{
Level
(
3
),
Level
(
4
),
Level
(
5
),
Level
(
6
)
};
std
::
vector
<
SampleCounter
>
ctrVec
=
{
SampleCounter
(),
SampleCounter
(),
SampleCounter
(),
SampleCounter
()
};
std
::
vector
<
Averages
>
avgVec
=
{
Averages
(
2.0e-02
,
4.0e-04
,
8.0e-06
,
16.0e-08
,
2.0e-02
,
4.0e-04
,
8.0e-06
,
16.0e-08
,
100
),
Averages
(
1.0e-02
,
2.0e-04
,
4.0e-06
,
8.0e-08
,
1.0e-02
,
2.0e-04
,
4.0e-06
,
8.0e-08
,
200
),
Averages
(
0.5e-02
,
1.0e-04
,
2.0e-06
,
4.0e-08
,
0.5e-02
,
1.0e-04
,
2.0e-06
,
4.0e-08
,
400
),
Averages
(
0.25e-02
,
0.5e-04
,
1.0e-06
,
2.0e-08
,
0.25e-02
,
0.5e-04
,
1.0e-06
,
2.0e-08
,
800
)
};
std
::
vector
<
Variances
>
varVec
=
{
Variances
(
64.0e-02
,
64.0e-02
),
Variances
(
16.0e-02
,
16.0e-02
),
Variances
(
4.0e-02
,
4.0e-02
),
Variances
(
1.0e-02
,
1.0e-02
)
};
std
::
vector
<
Kurtosis
>
kurtosisVec
=
{
Kurtosis
(),
Kurtosis
(),
Kurtosis
(),
Kurtosis
()
};
#endif //TESTEXPONENTS_HPP
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