Commit b41ca6f2 authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

fixed tests

parent 08b02796
Pipeline #149274 failed with stages
in 10 minutes and 27 seconds
...@@ -50,8 +50,6 @@ public: ...@@ -50,8 +50,6 @@ public:
MonteCarlo() : MonteCarlo() :
pdeSolverCreator(PDESolverCreator()), pdeSolverCreator(PDESolverCreator()),
meshesCreator(MeshesCreator(pdeSolverCreator.GetMeshName())) { meshesCreator(MeshesCreator(pdeSolverCreator.GetMeshName())) {
config.get("maxLevel", level);
} }
std::string Name() const override { std::string Name() const override {
......
...@@ -24,6 +24,15 @@ struct EstimatorMap : public LevelMap<Estimator *> { ...@@ -24,6 +24,15 @@ struct EstimatorMap : public LevelMap<Estimator *> {
void UpdateSampleCounter(double epsilon); void UpdateSampleCounter(double epsilon);
void AppendLevel(double epsilon, Exponents exponents, int newLevel); void AppendLevel(double epsilon, Exponents exponents, int newLevel);
void SetEstimatorMapData(const MultilevelData &_data) {
for (auto &[level, estimator] : _levelMap) {
estimator->aggregate.ctr = _data.ctrs.at(level);
estimator->aggregate.mean = _data.means.at(level);
estimator->aggregate.sVar = _data.sVars.at(level);
estimator->aggregate.kurtosis = _data.kurtosis.at(level);
}
}
}; };
typedef std::vector<int> Levels; typedef std::vector<int> Levels;
......
...@@ -97,7 +97,7 @@ public: ...@@ -97,7 +97,7 @@ public:
auto operator[](int level) { return _levelMap[level]; } auto operator[](int level) { return _levelMap[level]; }
auto at(int level) { return _levelMap.at(level); } auto at(int level) const { return _levelMap.at(level); }
auto find(int level) { return _levelMap.find(level); } auto find(int level) { return _levelMap.find(level); }
......
...@@ -18,7 +18,7 @@ add_mpp_test(generators/TestSymmetricCovariance GENERATORS) ...@@ -18,7 +18,7 @@ add_mpp_test(generators/TestSymmetricCovariance GENERATORS)
add_mpp_test(estimators/datastructure/TestLevelMaps MONTECARLO) add_mpp_test(estimators/datastructure/TestLevelMaps MONTECARLO)
add_mpp_test(estimators/datastructure/TestExponents MONTECARLO) add_mpp_test(estimators/datastructure/TestExponents MONTECARLO)
add_mpp_test(estimators/datastructure/TestErrors MONTECARLO) add_mpp_test(estimators/datastructure/TestMultilevelErrors MONTECARLO)
add_mpp_test(pdesolver/TestPDESolver PDESOLVER) add_mpp_test(pdesolver/TestPDESolver PDESOLVER)
......
...@@ -9,8 +9,6 @@ int main(int argc, char **argv) { ...@@ -9,8 +9,6 @@ int main(int argc, char **argv) {
WithConfigEntry("degree", 1). WithConfigEntry("degree", 1).
WithConfigEntry("maxLevel", 8). WithConfigEntry("maxLevel", 8).
WithConfigEntry("MCParallel", false). WithConfigEntry("MCParallel", false).
WithConfigEntry("initLevels", "[3, 4, 5]").
WithConfigEntry("initSampleAmount", "[12, 6, 3]").
WithConfigEntry("StochasticField", "LogNormal"). WithConfigEntry("StochasticField", "LogNormal").
WithConfigEntry("lambda", "[0.15, 0.15]"). WithConfigEntry("lambda", "[0.15, 0.15]").
WithConfigEntry("Mean", 0.0). WithConfigEntry("Mean", 0.0).
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
struct TestStruct { struct TestStruct {
Levels levels{3, 4, 5};
Samples samples{12, 6, 3};
}; };
class TestEllipticMultilevelMonteCarlo : public TestWithParam<TestStruct> { class TestEllipticMultilevelMonteCarlo : public TestWithParam<TestStruct> {
...@@ -16,10 +18,9 @@ protected: ...@@ -16,10 +18,9 @@ protected:
MultilevelEstimator mlmc; MultilevelEstimator mlmc;
TestEllipticMultilevelMonteCarlo() : TestEllipticMultilevelMonteCarlo() :
mlmc(estimatorMap) { estimatorMap(CreateMonteCarloMap(GetParam().levels, GetParam().samples)),
mlmc(MultilevelEstimator(estimatorMap)) {
// estimatorMap = mlmc.Method();
} }
}; };
......
...@@ -2,25 +2,25 @@ ...@@ -2,25 +2,25 @@
INSTANTIATE_TEST_SUITE_P(TestMonteCarlo, TestMonteCarloSeriellInterval, Values( INSTANTIATE_TEST_SUITE_P(TestMonteCarlo, TestMonteCarloSeriellInterval, Values(
"StochasticDummyScalarGeneratorProblem" TestStruct{"StochasticDummyScalarGeneratorProblem", 0.0, 0.0, 1.0, 1.0}
)); ));
INSTANTIATE_TEST_SUITE_P(TestMonteCarlo, TestMonteCarloParallelInterval, Values( INSTANTIATE_TEST_SUITE_P(TestMonteCarlo, TestMonteCarloParallelInterval, Values(
"StochasticDummyScalarGeneratorProblem" TestStruct{"StochasticDummyScalarGeneratorProblem", 0.0, 0.0, 1.0, 1.0}
)); ));
TEST_P(TestMonteCarloSeriellInterval, TestMethodOnlyFine) { TEST_P(TestMonteCarloSeriellInterval, TestMethodOnlyFine) {
EXPECT_NEAR(mc.aggregate.mean.Q, 0.0, sqrt(1.0 / dM)); EXPECT_NEAR(mc.aggregate.mean.Q, GetParam().MeanQ, sqrt(1.0 / dM));
EXPECT_NEAR(mc.aggregate.mean.Y, 0.0, sqrt(1.0 / dM)); EXPECT_NEAR(mc.aggregate.mean.Y, GetParam().MeanY, sqrt(1.0 / dM));
EXPECT_NEAR(mc.aggregate.sVar.Q, 1.0, sqrt(10.0 / dM)); EXPECT_NEAR(mc.aggregate.sVar.Q, GetParam().SVarQ, sqrt(10.0 / dM));
EXPECT_NEAR(mc.aggregate.sVar.Y, 1.0, sqrt(10.0 / dM)); EXPECT_NEAR(mc.aggregate.sVar.Y, GetParam().SVarY, sqrt(10.0 / dM));
} }
TEST_P(TestMonteCarloParallelInterval, TestMethodOnlyFine) { TEST_P(TestMonteCarloParallelInterval, TestMethodOnlyFine) {
EXPECT_NEAR(mc.aggregate.mean.Q, 0.0, sqrt(1.0 / dM)); EXPECT_NEAR(mc.aggregate.mean.Q, GetParam().MeanQ, sqrt(1.0 / dM));
EXPECT_NEAR(mc.aggregate.mean.Y, 0.0, sqrt(1.0 / dM)); EXPECT_NEAR(mc.aggregate.mean.Y, GetParam().MeanY, sqrt(1.0 / dM));
EXPECT_NEAR(mc.aggregate.sVar.Q, 1.0, sqrt(10.0 / dM)); EXPECT_NEAR(mc.aggregate.sVar.Q, GetParam().SVarQ, sqrt(10.0 / dM));
EXPECT_NEAR(mc.aggregate.sVar.Y, 1.0, sqrt(10.0 / dM)); EXPECT_NEAR(mc.aggregate.sVar.Y, GetParam().SVarY, sqrt(10.0 / dM));
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
......
...@@ -7,8 +7,21 @@ ...@@ -7,8 +7,21 @@
#include "MeshesCreator.hpp" #include "MeshesCreator.hpp"
#include "TestEnvironment.hpp" #include "TestEnvironment.hpp"
struct TestStruct {
std::string name;
class TestMonteCarlo : public TestWithParam<std::string> { double MeanQ;
double MeanY;
double SVarQ;
double SVarY;
};
class TestMonteCarlo : public TestWithParam<TestStruct> {
protected: protected:
bool onlyFine = true; bool onlyFine = true;
...@@ -27,7 +40,7 @@ protected: ...@@ -27,7 +40,7 @@ protected:
WithDistribute("RCB"). WithDistribute("RCB").
WithoutOverlap()), WithoutOverlap()),
pdeSolverCreator(PDESolverCreator(). pdeSolverCreator(PDESolverCreator().
WithProblem(GetParam()). WithProblem(GetParam().name).
WithQuantity("GeneratorValue"). WithQuantity("GeneratorValue").
WithModel("DummyPDESolver")), WithModel("DummyPDESolver")),
mc(MonteCarlo(level, dM, onlyFine, parallel, mc(MonteCarlo(level, dM, onlyFine, parallel,
......
...@@ -3,54 +3,35 @@ ...@@ -3,54 +3,35 @@
#include "MultilevelEstimator.hpp" #include "MultilevelEstimator.hpp"
struct TestData {
const SampleCounterMap _ctrs = {
EstimatorMap _estimatorMap = { {3, SampleCounter{1600, 0, 0, 0}},
{3, new MonteCarlo(3, 0, true, true)}, {4, SampleCounter{400, 0, 0, 0}},
{4, new MonteCarlo(4, 0, true, true)}, {5, SampleCounter{100, 0, 0, 0}},
{5, new MonteCarlo(5, 0, true, true)}, {6, SampleCounter{25, 0, 0, 0}}
{6, new MonteCarlo(6, 0, true, true)} };
};
const MeanMap _means = {
SampleCounterMap _ctrs = { {3, Mean{400, 2.0e-02, 2.0e-02}},
{3, SampleCounter{1600, 0, 0, 0}}, {4, Mean{800, 1.0e-02, 1.0e-02}},
{4, SampleCounter{400, 0, 0, 0}}, {5, Mean{1600, 0.5e-02, 0.5e-02}},
{5, SampleCounter{100, 0, 0, 0}}, {6, Mean{3200, 0.25e-02, 0.25e-02}}
{6, SampleCounter{25, 0, 0, 0}} };
};
const SVarMap _sVars = {
MeanMap _means = { {3, SVar{0.0, 64.0e-02, 64.0e-02}},
{3, Mean{400, 2.0e-02, 2.0e-02}}, {4, SVar{0.0, 16.0e-02, 16.0e-02}},
{4, Mean{800, 1.0e-02, 1.0e-02}}, {5, SVar{0.0, 4.0e-02, 4.0e-02}},
{5, Mean{1600, 0.5e-02, 0.5e-02}}, {6, SVar{0.0, 1.0e-02, 1.0e-02}}
{6, Mean{3200, 0.25e-02, 0.25e-02}} };
};
const KurtosisMap _kurtosis = {
SVarMap _sVars = { {3, Kurtosis()},
{3, SVar{0.0, 64.0e-02, 64.0e-02}}, {4, Kurtosis()},
{4, SVar{0.0, 16.0e-02, 16.0e-02}}, {5, Kurtosis()},
{5, SVar{0.0, 4.0e-02, 4.0e-02}}, {6, Kurtosis()}
{6, SVar{0.0, 1.0e-02, 1.0e-02}}
};
KurtosisMap _kurtosis = {
{3, Kurtosis()},
{4, Kurtosis()},
{5, Kurtosis()},
{6, Kurtosis()}
};
const MultilevelData _data{_ctrs, _means, _sVars, _kurtosis};
EstimatorMap GenerateMonteCarloMapWithData() {
for (auto &[level, estimator] : _estimatorMap) {
estimator->aggregate.ctr = _ctrs[level];
estimator->aggregate.mean = _means[level];
estimator->aggregate.sVar = _sVars[level];
estimator->aggregate.kurtosis = _kurtosis[level];
}
return _estimatorMap;
}
}; };
const MultilevelData _data{_ctrs, _means, _sVars, _kurtosis};
#endif //TESTDATA_HPP #endif //TESTDATA_HPP
#include "TestData.hpp"
#include "MultilevelErrors.hpp"
#include "TestEnvironment.hpp"
class TestErrors : public Test {
protected:
MultilevelData data;
MultilevelErrors errors;
void SetUp() override {
TestData testData;
data = testData._data;
}
void TearDown() override {}
};
TEST_F(TestErrors, TestNumeric) {
EXPECT_FLOAT_EQ(errors.EstimateNumeric(data), 0.25e-02);
}
TEST_F(TestErrors, TestStochastic) {
EXPECT_FLOAT_EQ(errors.EstimateStochastic(data), 4.0e-2);
}
int main(int argc, char **argv) {
return MppTest(
MppTestBuilder(argc, argv).
WithPPM()
).RUN_ALL_MPP_TESTS();
}
\ No newline at end of file
...@@ -4,29 +4,21 @@ ...@@ -4,29 +4,21 @@
#include "TestEnvironment.hpp" #include "TestEnvironment.hpp"
class TestErrors : public Test { class TestMultilevelErrors : public Test {
protected: protected:
MultilevelData data;
Exponents exponents; Exponents exponents;
void SetUp() override {
TestData testData;
data = testData._data;
}
void TearDown() override {}
}; };
TEST_F(TestErrors, TestAlpha) { TEST_F(TestMultilevelErrors, TestAlpha) {
EXPECT_FLOAT_EQ(exponents.ComputeAlpha(data.means), 1.0); EXPECT_FLOAT_EQ(exponents.ComputeAlpha(_data.means), 1.0);
} }
TEST_F(TestErrors, TestBeta) { TEST_F(TestMultilevelErrors, TestBeta) {
EXPECT_FLOAT_EQ(exponents.ComputeBeta(data.sVars), 2.0); EXPECT_FLOAT_EQ(exponents.ComputeBeta(_data.sVars), 2.0);
} }
TEST_F(TestErrors, TestGamma) { TEST_F(TestMultilevelErrors, TestGamma) {
EXPECT_FLOAT_EQ(exponents.ComputeGamma(data.means), 1.0); EXPECT_FLOAT_EQ(exponents.ComputeGamma(_data.means), 1.0);
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
......
...@@ -5,32 +5,34 @@ ...@@ -5,32 +5,34 @@
class TestLevelMaps : public Test { class TestLevelMaps : public Test {
protected: protected:
MultilevelData data; EstimatorMap estimatorMap = {
{3, new MonteCarlo(3, 0, true, true)},
EstimatorMap estimatorMap; {4, new MonteCarlo(4, 0, true, true)},
{5, new MonteCarlo(5, 0, true, true)},
{6, new MonteCarlo(6, 0, true, true)}
};
void SetUp() override { void SetUp() override {
TestData testData; estimatorMap.SetEstimatorMapData(_data);
data = testData._data;
estimatorMap = testData.GenerateMonteCarloMapWithData();
} }
}; };
TEST_F(TestLevelMaps, TestMonteCarloMapUpdateSampleCounter) { TEST_F(TestLevelMaps, TestMonteCarloMapUpdateSampleCounter) {
estimatorMap.UpdateSampleCounter(0.01); estimatorMap.UpdateSampleCounter(0.01);
for (auto &[level, ctr] : data.ctrs) { for (auto &[level, ctr] : _data.ctrs) {
EXPECT_TRUE(data.ctrs[level].dM == 0); EXPECT_TRUE(_data.ctrs.at(level).dM == 0);
EXPECT_TRUE(estimatorMap.find(level)->second->aggregate.ctr.dM != 0); EXPECT_TRUE(estimatorMap.find(level)->second->aggregate.ctr.dM != 0);
EXPECT_TRUE(data.ctrs[level].M == estimatorMap.find(level)->second->aggregate.ctr.M); EXPECT_EQ(_data.ctrs.at(level).M, estimatorMap.find(level)->second->aggregate.ctr.M);
} }
} }
TEST_F(TestLevelMaps, TestMonteCarloMapAppendLevel) { TEST_F(TestLevelMaps, TestMonteCarloMapAppendLevel) {
int newLevel = 7; int newLevel = 7;
estimatorMap.AppendLevel(0.1, Exponents(data), 7); estimatorMap.AppendLevel(0.1, Exponents(_data), 7);
EXPECT_FLOAT_EQ(estimatorMap.find(newLevel)->second->aggregate.sVar.Y, 0.0025); EXPECT_FLOAT_EQ(estimatorMap.find(newLevel)->second->aggregate.sVar.Y, 0.25e-02);
EXPECT_FLOAT_EQ(estimatorMap.find(newLevel)->second->aggregate.mean.C, 6400.0); EXPECT_FLOAT_EQ(estimatorMap.find(newLevel)->second->aggregate.mean.C, 6400.0);
EXPECT_TRUE(data.ctrs[newLevel].dM == 0); // floor(25 /4)
EXPECT_FLOAT_EQ(estimatorMap.find(newLevel)->second->aggregate.ctr.dM, 6);
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
......
#include "TestData.hpp"
#include "MultilevelErrors.hpp"
#include "TestEnvironment.hpp"
class TestMultilevelErrors : public Test {
protected:
MultilevelErrors errors;
};
TEST_F(TestMultilevelErrors, TestNumeric) {
EXPECT_FLOAT_EQ(errors.EstimateNumeric(_data), 0.25e-02);
}
TEST_F(TestMultilevelErrors, TestStochastic) {
EXPECT_FLOAT_EQ(errors.EstimateStochastic(_data), 4.0e-2);
}
int main(int argc, char **argv) {
return MppTest(
MppTestBuilder(argc, argv).
WithPPM()
).RUN_ALL_MPP_TESTS();
}
\ No newline at end of file
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