Commit 08e0a17b authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

refactoring of test problems

parent 6690bce1
#ifndef ISTOCHASTICPROBLEM_HPP
#define ISTOCHASTICPROBLEM_HPP
#include <utility>
#include "NormalDistribution.hpp"
#include "UniformDistribution.hpp"
#include "SparseGridGenerator.hpp"
......@@ -23,6 +25,8 @@ public:
virtual void DrawSample(const SampleID &id) = 0;
virtual double SumOfWeights() { return 1.0; }
virtual int NumOfSamples() { return 0; };
virtual string Name() const = 0;
......@@ -190,44 +194,48 @@ public:
}
};
class SparseGrid1DGeneratorProblem : public StochasticDummyProblem {
class SparseGridGeneratorProblem : public StochasticDummyProblem {
protected:
SparseGridGenerator generator;
public:
explicit SparseGrid1DGeneratorProblem(const Meshes &meshes) :
StochasticDummyProblem(meshes),
generator(SparseGridGenerator(meshes, 1, 0, 6)) {}
SparseGridGeneratorProblem(const Meshes &meshes, SparseGridGenerator generator) :
StochasticDummyProblem(meshes), generator(std::move(generator)) {}
void DrawSample(const SampleID &id) override {
generator.DrawSample(id);
}
double FunctionEvaluation() override {
return std::exp(this->generator.EvalSample() * this->generator.EvalSample());
double SampleWeight(const SampleID &id) override {
return generator.SampleWeight(id);
}
string Name() const override {
return "SparseGrid1DGeneratorProblem";
double SumOfWeights() override {
return generator.SumOfWeights();
}
int NumOfSamples() override {
return generator.GetNumPoints();
}
};
class SparseGrid2DGeneratorProblem : public StochasticDummyProblem {
SparseGridGenerator generator;
class SparseGrid1DGeneratorProblem : public SparseGridGeneratorProblem {
public:
explicit SparseGrid2DGeneratorProblem(const Meshes &meshes) :
StochasticDummyProblem(meshes),
generator(SparseGridGenerator(meshes, 2, 0, 6)) {}
explicit SparseGrid1DGeneratorProblem(const Meshes &meshes) :
SparseGridGeneratorProblem(meshes, SparseGridGenerator(meshes, 1, 0, 6)) {}
void DrawSample(const SampleID &id) override {
generator.DrawSample(id);
double FunctionEvaluation() override {
return std::exp(this->generator.EvalSample() * this->generator.EvalSample());
}
double SampleWeight(const SampleID &id) override {
return generator.SampleWeight(id);
string Name() const override {
return "SparseGrid1DGeneratorProblem";
}
};
int NumOfSamples() override {
return generator.GetNumPoints();
}
class SparseGrid2DGeneratorProblem : public SparseGridGeneratorProblem {
public:
explicit SparseGrid2DGeneratorProblem(const Meshes &meshes) :
SparseGridGeneratorProblem(meshes, SparseGridGenerator(meshes, 2, 0, 6)) {}
double FunctionEvaluation() override {
RVector sample = this->generator.EvalSample();
......
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