Commit 79edfc7d authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

introducing TestExponents and adaption of EmpiricMeasures

parent 579ff138
#include "EmpiricMeasureLevelMaps.hpp"
#include "Exponents.hpp"
void MonteCarloMap::UpdateSampleCounter(double epsilon) {
int optimalM;
......
......@@ -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);
......
......@@ -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;
Q1 += 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;
Y1 += 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.Y1 / M);
Y = abs(sums.Y / M);
Y2 = sums.Y2 / M;
Y3 = sums.Y3 / M;
Y4 = sums.Y4 / M;
Q = abs(sums.Q1 / M);
Q = abs(sums.Q / M);
Q2 = sums.Q2 / M;
Q3 = sums.Q3 / M;
Q4 = sums.Q4 / M;
......
......@@ -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 Q1 = 0.0;
double Q = 0.0;
double Q2 = 0.0;
double Q3 = 0.0;
double Q4 = 0.0;
double Y1 = 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);
};
......
#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
#ifndef TESTEXPONENTS_HPP
#define TESTEXPONENTS_HPP
#endif //TESTEXPONENTS_HPP
#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
#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
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