Commit 7ab4b9a2 authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

added test and include restructuring

parent 56661a3e
Pipeline #147210 passed with stages
in 49 minutes and 25 seconds
add_library(GENERATORS STATIC
NormalDistribution.cpp
UniformDistribution.cpp
SampleGeneratorContainer.cpp
algorithms/CirculantEmbedding.cpp
algorithms/HybridFluxGenerator.cpp
algorithms/NormalDistribution.cpp
algorithms/UniformDistribution.cpp
algorithms/SymmetricCovariance.cpp
algorithms/HybridFluxGenerator.cpp
)
target_link_libraries(GENERATORS BASICS PDESOLVER sprng MPP_LIBRARIES)
......@@ -27,6 +27,11 @@ void SampleGeneratorContainer::initWithGenNames(Meshes &meshes, GeneratorNames n
if (genName == "NormalDistributionCMatrix")
cMatrixGenerator = new NormalDistributionCMatrix(meshes);
if (genName == "UniformDistributionReal")
scalarGenerator = new UniformDistributionReal(meshes);
// Todo remaining generators
if (genName == "CirculantEmbedding") {
if (meshes.dim() == 1)
tensorGenerator = new CirculantEmbedding1D(meshes);
......
......@@ -4,8 +4,8 @@
#include "SampleGenerator.hpp"
#include "algorithms/CirculantEmbedding.hpp"
#include "algorithms/HybridFluxGenerator.hpp"
#include "algorithms/NormalDistribution.hpp"
#include "algorithms/UniformDistribution.hpp"
#include "NormalDistribution.hpp"
#include "UniformDistribution.hpp"
typedef std::vector<std::string> GeneratorNames;
......
......@@ -5,7 +5,7 @@
#include "LagrangeDiscretization.hpp"
#include "basics/Utilities.hpp"
#include "Algebra.hpp"
#include "NormalDistribution.hpp"
#include "generators/NormalDistribution.hpp"
#include "Plotting.hpp"
#include "FFT.hpp"
......
......@@ -12,6 +12,7 @@ file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/mlmc/tests/log)
add_mpp_test(basics/TestPlotting BASICS)
add_mpp_test(generators/TestNormalDistribution GENERATORS)
add_mpp_test(generators/TestUniformDistribution GENERATORS)
add_mpp_test(generators/TestCirculantEmbedding GENERATORS)
add_mpp_test(generators/TestSymmetricCovariance GENERATORS)
#add_mpp_test(generators/TestHybridFluxGenerator GENERATORS)
......
TEST_F(TestNormalDistribution, TestUniformlyDistributedRandomNumber) {
double z1, z2;
for (int i = 0; i < testSamples; i++) {
rnm->DrawUniformRandomNumbers(z1, z2);
rns.push_back(z1);
rns.push_back(z1);
}
EXPECT_NEAR(0.5, calc_mean(rns), 1e-2);
EXPECT_NEAR(0.08333333333333333, calc_var(rns), 1e-2);
#include "generators/UniformDistribution.hpp"
#include "basics/Utilities.hpp"
#include "TestEnvironment.hpp"
#include "MeshesCreator.hpp"
typedef std::vector<SampleID> TestSampleIDs;
class TestUniformDistribution : public Test {
protected:
TestSampleIDs sampleIDs;
Meshes *meshes;
int numSamples = 1e6;
void SetUp() override {
meshes = MeshesCreator("Interval").Create();
for (int number = 0; number < numSamples; number++)
sampleIDs.push_back(SampleID(0, number, false));
}
void TearDown() override {
delete meshes;
}
};
TEST_F(TestUniformDistribution, UniformDistributionReal) {
double a = 0.0;
double b = 1.0;
UniformDistributionReal uniformDist(*meshes, a, b);
RVector results;
for (auto &id : sampleIDs) {
uniformDist.DrawSample(id);
results.push_back(uniformDist.EvalSample());
}
double mean = results.Mean();
double var = results.Variance();
EXPECT_NEAR(a + b / 2, mean, sqrt(1.0 / numSamples));
EXPECT_NEAR(pow(b - a, 2) / 12, var, sqrt(1.0 / numSamples));
}
TEST_F(TestUniformDistribution, UniformDistributionReal2) {
double a = -1.0;
double b = 1.0;
UniformDistributionReal uniformDist(*meshes, a, b);
RVector results;
for (auto &id : sampleIDs) {
uniformDist.DrawSample(id);
results.push_back(uniformDist.EvalSample());
}
double mean = results.Mean();
double var = results.Variance();
EXPECT_NEAR((a + b) / 2.0, mean, sqrt(1.0 / numSamples));
EXPECT_NEAR(pow(b - a, 2) / 12.0, var, sqrt(1.0 / numSamples));
}
//TEST_F(TestUniformDistribution, ComplexNormalDistribution) {
// NormalDistributionComplex normalDist(*meshes);
// CVector results;
// for (auto &id : sampleIDs) {
// normalDist.DrawSample(id);
// results.push_back(normalDist.EvalSample());
// }
// Complex mean = results.Mean();
// double var = results.Variance();
// EXPECT_NEAR(0.0, mean.real(), sqrt(1.0 / numSamples));
// EXPECT_NEAR(0.0, mean.imag(), sqrt(1.0 / numSamples));
// EXPECT_NEAR(2.0, var, sqrt(100.0 / numSamples));
//}
//
//TEST_F(TestUniformDistribution, NormalDistributionRVector) {
// NormalDistributionRVector normalDist(*meshes, numSamples);
// normalDist.DrawSample(sampleIDs[0]);
// RVector results = normalDist.EvalSample();
// EXPECT_NEAR(0.0, results.Mean(), sqrt(1.0 / numSamples));
// EXPECT_NEAR(1.0, results.Variance(), sqrt(10.0 / numSamples));
//}
//
//
//TEST_F(TestUniformDistribution, NormalDistributionCVector) {
// NormalDistributionCVector normalDist(*meshes, numSamples);
// normalDist.DrawSample(sampleIDs[0]);
// CVector results = normalDist.EvalSample();
// Complex mean = results.Mean();
// EXPECT_NEAR(0.0, mean.real(), sqrt(1.0 / numSamples));
// EXPECT_NEAR(0.0, mean.imag(), sqrt(1.0 / numSamples));
// EXPECT_NEAR(1.0, results.Variance() / 2.0, sqrt(10.0 / numSamples));
//}
//
//
//TEST_F(TestUniformDistribution, NormalDistributionRMatrix) {
// NormalDistributionRMatrix normalDist(*meshes, sqrt(numSamples), sqrt(numSamples));
// normalDist.DrawSample(sampleIDs[0]);
// RMatrix results = normalDist.EvalSample();
// EXPECT_NEAR(0.0, results.Mean(), sqrt(1.0 / numSamples));
// EXPECT_NEAR(1.0, results.Variance(), sqrt(10.0 / numSamples));
//}
//
//TEST_F(TestUniformDistribution, NormalDistributionCMatrix) {
// NormalDistributionCMatrix normalDist(*meshes, sqrt(numSamples), sqrt(numSamples));
// normalDist.DrawSample(sampleIDs[0]);
// CMatrix results = normalDist.EvalSample();
// Complex mean = results.Mean();
// EXPECT_NEAR(0.0, mean.real(), sqrt(1.0 / numSamples));
// EXPECT_NEAR(0.0, mean.imag(), sqrt(1.0 / numSamples));
// EXPECT_NEAR(1.0, results.Variance() / 2.0, sqrt(10.0 / numSamples));
//}
int main(int argc, char **argv) {
MppTest mppTest = MppTestBuilder(argc, argv);
return mppTest.RUN_ALL_MPP_TESTS();
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