NormalDistribution.hpp 3.12 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
#ifndef NORMALDISTRIBUTION_HPP
#define NORMALDISTRIBUTION_HPP

#include "SampleGenerator.hpp"
#include "sprng_cpp.h"
#include <math.h>


#define SEED 985456376

11
class NormalDistribution : public SampleGenerator<Scalar> {
12
13
14
15
16
17
18
19
20
private:
    Sprng *randNumberGen;

    Scalar firstSample;

    Scalar secondSample;

    int internalCounter = 0;

21
    void drawSample(const SampleID &id) override;
22

23
    void updateCounter();;
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

public:
    NormalDistribution(Meshes &meshes,
                       int streamID = 0,
                       int numStreams = 1,
                       int gType = 0,
                       int seed = SEED) :
        SampleGenerator(meshes) {
        this->randNumberGen = SelectType(gType);
        this->randNumberGen->init_sprng(streamID, numStreams,
                                        seed, SPRNG_DEFAULT);
    }

    ~NormalDistribution() { randNumberGen->free_sprng(); };

39
    Scalar EvalSample() override;
40
41
42
43
44
45

    string Name() const override {
        return "NormalDistribution";
    };
};

46
class ComplexNormalDistribution : public SampleGenerator<Complex> {
47
48
49
50
51
52
53
private:
    NormalDistribution normalDist;

    Complex sample;

    void drawSample(const SampleID &id) override {
        normalDist.DrawSample(id);
54
        Scalar real = normalDist.EvalSample();
55
        normalDist.DrawSample(id);
56
        Scalar imag = normalDist.EvalSample();
57
58
59
60
61
62
63
64
        sample = {real, imag};
    }

public:
    ComplexNormalDistribution(Meshes &meshes) :
        SampleGenerator(meshes),
        normalDist(meshes) {}

65
    Complex EvalSample() override {
66
67
68
69
70
71
72
73
        return sample;
    }

    string Name() const override {
        return "ComplexNormalDistribution";
    };
};

74
class NormalDistributionScalarSequence1D : public SampleGenerator<ScalarSequence1D> {
75
76
77
private:
    NormalDistribution normalDist;

78
    ScalarSequence1D sample;
79
80
81
82

    void drawSample(const SampleID &id) override {
        for (int i = 0; i < sample.size(); i++) {
            normalDist.DrawSample(id);
83
            sample[i] = normalDist.EvalSample();
84
85
86
87
        }
    }

public:
88
    NormalDistributionScalarSequence1D(Meshes &meshes) :
89
90
91
92
93
94
95
        SampleGenerator(meshes),
        normalDist(meshes) {}

    void Resize(int sizeN) {
        sample.resize(sizeN);
    }

96
    ScalarSequence1D EvalSample() override {
97
98
99
100
101
102
103
104
        return sample;
    }

    string Name() const override {
        return "NormalDistributionScalar1DField";
    };
};

105
class NormalDistributionComplexSequence1D : public SampleGenerator<ComplexSequence1D> {
106
107
108
private:
    ComplexNormalDistribution normalDist;

109
    ComplexSequence1D sample;
110
111
112
113

    void drawSample(const SampleID &id) override {
        for (int i = 0; i < sample.size(); i++) {
            normalDist.DrawSample(id);
114
            sample[i] = normalDist.EvalSample();
115
116
117
118
        }
    }

public:
119
    NormalDistributionComplexSequence1D(Meshes &meshes) :
120
121
122
123
124
125
126
        SampleGenerator(meshes),
        normalDist(meshes) {}

    void Resize(int sizeN) {
        sample.resize(sizeN);
    }

127
    ComplexSequence1D EvalSample() override {
128
129
130
131
132
133
134
135
        return sample;
    }

    string Name() const override {
        return "NormalDistributionComplex1DField";
    };
};

136
#endif //NORMALDISTRIBUTION_HPP