Commit 512e5de1 authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

rename to MultilevelData

parent 429a3dc0
Pipeline #149208 passed with stages
in 51 minutes and 47 seconds
......@@ -68,21 +68,13 @@ void MultilevelMonteCarlo::PrintInfo() const {
}
void MultilevelMonteCarlo::MultilevelResults() const {
mout.PrintInfo("MC Results", verbose,
PrintInfoEntry("E(Qf-Qc)", vec2str(data.avgs.GetYVector())),
PrintInfoEntry("E(Qf)", vec2str(data.avgs.GetQVector())),
PrintInfoEntry("V(Qf-Qc)", vec2str(data.vars.GetYVector())),
PrintInfoEntry("V(Qf)", vec2str(data.vars.GetQVector())),
PrintInfoEntry("kurtosis", vec2str(data.kurtosis.GetYVector())),
PrintInfoEntry("E(cost)", vec2str(data.avgs.GetCostVector())),
PrintInfoEntry("Used Levels", vec2str(data.avgs.GetLevelVector())),
PrintInfoEntry("Used Samples", vec2str(data.ctrs.GetMVector())));
data.MultilevelResults();
}
void MultilevelMonteCarlo::EstimatorResults() const {
mout.PrintInfo("MLMC Results", verbose,
PrintInfoEntry("Value", data.avgs.Q),
PrintInfoEntry("Cost", data.avgs.Cost),
PrintInfoEntry("Value", data.means.Q),
PrintInfoEntry("Cost", data.means.Cost),
PrintInfoEntry("Epsilon", epsilon),
PrintInfoEntry("Total Error", errors.total),
PrintInfoEntry("Statistical Error", errors.stochastic),
......@@ -95,10 +87,3 @@ void MultilevelMonteCarlo::ExponentResults() const {
PrintInfoEntry("Final beta", exponents.beta),
PrintInfoEntry("Final gamma", exponents.gamma));
}
void MultiLevelMonteCarloData::ExtractDataFrom(const MonteCarloMap &mcMap) {
ctrs.Update(mcMap);
avgs.Update(mcMap);
vars.Update(mcMap);
kurtosis.Update(mcMap);
}
......@@ -9,7 +9,6 @@
#include "IEstimator.hpp"
class MultilevelMonteCarlo : public IEstimator {
private:
int verbose = 1;
......@@ -28,7 +27,7 @@ public:
MonteCarloMap mcMap;
// Here Could be EstimatorMap
MultiLevelMonteCarloData data;
MultilevelData data;
Exponents exponents;
......
......@@ -84,32 +84,52 @@ struct KurtosisMap : LevelMap<Kurtosis> {
void Update(const MonteCarloMap &mcMap);
};
struct MultiLevelMonteCarloData {
struct MultilevelData {
SampleCounterMap ctrs;
MeanMap avgs;
SVarMap vars;
MeanMap means;
SVarMap sVars;
KurtosisMap kurtosis;
MultiLevelMonteCarloData() {};
MultilevelData() {};
MultiLevelMonteCarloData(const MonteCarloMap &mcMap) {
MultilevelData(const MonteCarloMap &mcMap) {
ExtractDataFrom(mcMap);
}
MultiLevelMonteCarloData(const SampleCounterMap &ctrs, const MeanMap &avgs,
const SVarMap &vars, const KurtosisMap &kurtosis) :
ctrs(ctrs), avgs(avgs), vars(vars), kurtosis(kurtosis) {};
MultilevelData(const SampleCounterMap &ctrs, const MeanMap &avgs,
const SVarMap &vars, const KurtosisMap &kurtosis) :
ctrs(ctrs), means(avgs), sVars(vars), kurtosis(kurtosis) {};
void ExtractDataFrom(const MonteCarloMap &mcMap);
void ExtractDataFrom(const MonteCarloMap &mcMap) {
ctrs.Update(mcMap);
means.Update(mcMap);
sVars.Update(mcMap);
kurtosis.Update(mcMap);
}
void MultilevelResults() const {
mout.PrintInfo("Multilevel Results", 1,
PrintInfoEntry("E(Qf-Qc)", vec2str(means.GetYVector())),
PrintInfoEntry("E(Qf)", vec2str(means.GetQVector())),
PrintInfoEntry("V(Qf-Qc)", vec2str(sVars.GetYVector())),
PrintInfoEntry("V(Qf)", vec2str(sVars.GetQVector())),
PrintInfoEntry("kurtosis", vec2str(kurtosis.GetYVector())),
PrintInfoEntry("E(cost)", vec2str(means.GetCostVector())),
PrintInfoEntry("Used Levels", vec2str(means.GetLevelVector())),
PrintInfoEntry("Used Samples", vec2str(ctrs.GetMVector())));
}
friend Logging &operator<<(Logging &s, const MultiLevelMonteCarloData &data) {
return s << "E(Qf-Qc)=" << data.avgs.GetYVector() << endl
<< "E(Qf)=" << data.avgs.GetQVector() << endl
<< "V(Qf-Qc)=" << data.vars.GetYVector() << endl
<< "V(Qf)=" << data.vars.GetQVector() << endl
friend Logging &operator<<(Logging &s, const MultilevelData &data) {
return s << "E(Qf-Qc)=" << data.means.GetYVector() << endl
<< "E(Qf)=" << data.means.GetQVector() << endl
<< "V(Qf-Qc)=" << data.sVars.GetYVector() << endl
<< "V(Qf)=" << data.sVars.GetQVector() << endl
<< "kurtosis=" << data.kurtosis.GetYVector() << endl
<< "E(cost)=" << data.avgs.GetCostVector() << endl
<< "Used Levels=" << data.avgs.GetLevelVector() << endl
<< "E(cost)=" << data.means.GetCostVector() << endl
<< "Used Levels=" << data.means.GetLevelVector() << endl
<< "Used Samples" << data.ctrs.GetMVector() << endl;
}
};
......
......@@ -2,19 +2,19 @@
void Errors::Estimate(const MonteCarloMap &mcMap) {
Estimate(MultiLevelMonteCarloData(mcMap));
Estimate(MultilevelData(mcMap));
}
void Errors::Estimate(const MultiLevelMonteCarloData &data) {
void Errors::Estimate(const MultilevelData &data) {
exponents.ComputeExponents(data);
numeric = EstimateNumeric(data);
stochastic = EstimateStochastic(data);
total = numeric + stochastic;
}
double Errors::EstimateNumeric(const MultiLevelMonteCarloData &data) {
double Errors::EstimateNumeric(const MultilevelData &data) {
exponents.ComputeExponents(data);
return EstimateNumeric(data.avgs);
return EstimateNumeric(data.means);
}
double Errors::EstimateNumeric(const MeanMap &avgs) {
......@@ -34,8 +34,8 @@ double Errors::EstimateNumeric(const MeanMap &avgs) {
return err;
}
double Errors::EstimateStochastic(const MultiLevelMonteCarloData &data) {
return EstimateStochastic(data.ctrs, data.vars);
double Errors::EstimateStochastic(const MultilevelData &data) {
return EstimateStochastic(data.ctrs, data.sVars);
}
double Errors::EstimateStochastic(const SampleCounterMap &ctrs, const SVarMap &vars) {
......
......@@ -13,13 +13,13 @@ struct Errors {
void Estimate(const MonteCarloMap &mcMap);
void Estimate(const MultiLevelMonteCarloData &mcMap);
void Estimate(const MultilevelData &mcMap);
double EstimateNumeric(const MultiLevelMonteCarloData &data);
double EstimateNumeric(const MultilevelData &data);
double EstimateNumeric(const MeanMap& avgs);
double EstimateStochastic(const MultiLevelMonteCarloData &data);
double EstimateStochastic(const MultilevelData &data);
double EstimateStochastic(const SampleCounterMap &ctrs, const SVarMap &vars);
};
......
#include "Exponents.hpp"
void Exponents::ComputeExponents(const MonteCarloMap &mcMap) {
ComputeExponents(MultiLevelMonteCarloData(mcMap));
ComputeExponents(MultilevelData(mcMap));
}
void Exponents::ComputeExponents(const MultiLevelMonteCarloData &data) {
ComputeExponents(data.avgs, data.vars);
void Exponents::ComputeExponents(const MultilevelData &data) {
ComputeExponents(data.means, data.sVars);
}
void Exponents::ComputeExponents(const MeanMap &mean, const SVarMap &sVar) {
......
......@@ -15,11 +15,11 @@ struct Exponents {
ComputeExponents(mcMap);
};
Exponents(const MultiLevelMonteCarloData &data) {
Exponents(const MultilevelData &data) {
ComputeExponents(data);
};
void ComputeExponents(const MultiLevelMonteCarloData &data);
void ComputeExponents(const MultilevelData &data);
void ComputeExponents(const MonteCarloMap &mcMap);
......
......@@ -41,7 +41,7 @@ struct TestData {
{6, Kurtosis()}
};
const MultiLevelMonteCarloData _data{_ctrs, _means, _sVars, _kurtosis};
const MultilevelData _data{_ctrs, _means, _sVars, _kurtosis};
MonteCarloMap GenerateMonteCarloMapWithData() {
for (auto &[level, mc] : _mcMap) {
......
......@@ -5,7 +5,7 @@
class TestEmpiricMeasureLevelMaps : public Test {
protected:
MultiLevelMonteCarloData data;
MultilevelData data;
MonteCarloMap mcMap;
void SetUp() override {
......
......@@ -6,7 +6,7 @@
class TestErrors : public Test {
protected:
MultiLevelMonteCarloData data;
MultilevelData data;
Errors errors;
void SetUp() override {
......
......@@ -6,7 +6,7 @@
class TestErrors : public Test {
protected:
MultiLevelMonteCarloData data;
MultilevelData data;
Exponents exponents;
void SetUp() override {
......@@ -18,15 +18,15 @@ protected:
};
TEST_F(TestErrors, TestAlpha) {
EXPECT_FLOAT_EQ(exponents.ComputeAlpha(data.avgs), 1.0);
EXPECT_FLOAT_EQ(exponents.ComputeAlpha(data.means), 1.0);
}
TEST_F(TestErrors, TestBeta) {
EXPECT_FLOAT_EQ(exponents.ComputeBeta(data.vars), 2.0);
EXPECT_FLOAT_EQ(exponents.ComputeBeta(data.sVars), 2.0);
}
TEST_F(TestErrors, TestGamma) {
EXPECT_FLOAT_EQ(exponents.ComputeGamma(data.avgs), 1.0);
EXPECT_FLOAT_EQ(exponents.ComputeGamma(data.means), 1.0);
}
int main(int argc, char **argv) {
......
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