OPAL (Object Oriented Parallel Accelerator Library)
2024.2
OPAL
src
Sample
SampleGaussianSequence.h
Go to the documentation of this file.
1
//
2
// Class SampleGaussianSequence
3
// This class provides a sequence of sampling points that have a Gaussian distribution
4
// with
5
// mean = 0.5 * (upper + lower)
6
// sigma = (upper - lower) / 10
7
// This can be achieved if the integral of the Gaussian between the sampling
8
// points are all equal. The sampling points are therefore computed using
9
// the inverse error function at equally distributed arguments between
10
// -1 and 1.
11
//
12
// Copyright (c) 2018, Christof Metzger-Kraus, Open Sourcerer
13
// All rights reserved
14
//
15
// This file is part of OPAL.
16
//
17
// OPAL is free software: you can redistribute it and/or modify
18
// it under the terms of the GNU General Public License as published by
19
// the Free Software Foundation, either version 3 of the License, or
20
// (at your option) any later version.
21
//
22
// You should have received a copy of the GNU General Public License
23
// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
24
//
25
#ifndef OPAL_SAMPLE_GAUSSIAN_SEQUENCE_H
26
#define OPAL_SAMPLE_GAUSSIAN_SEQUENCE_H
27
28
#include "
Sample/SamplingMethod.h
"
29
#include "
Utilities/Util.h
"
30
31
#ifdef WITH_UNIT_TESTS
32
#include <gtest/gtest_prod.h>
33
#endif
34
35
class
SampleGaussianSequence
:
public
SamplingMethod
36
{
37
38
public
:
39
40
SampleGaussianSequence
(
double
lower,
double
upper,
size_t
modulo,
int
nSample)
41
:
numSamples_m
(nSample)
42
,
volumeLowerDimensions_m
(modulo)
43
{
44
double
mean = 0.5 * (lower + upper);
45
double
sigma = (upper - lower) / 10;
// +- 5 sigma
46
double
factor = sigma / std::sqrt(2);
47
double
dx = 2.0 / nSample;
48
for
(
long
i = 0; i < nSample; ++ i) {
49
double
x = -1.0 + (i + 0.5) * dx;
50
double
y =
Util::erfinv
(x);
51
sampleChain_m
.push_back(mean + factor * y);
52
}
53
}
54
55
void
create
(std::shared_ptr<SampleIndividual>& ind,
size_t
i) {
56
ind->genes[i] =
getNext
(ind->id);
57
}
58
59
double
getNext
(
unsigned
int
id
) {
60
int
bin = int(
id
/
volumeLowerDimensions_m
) %
numSamples_m
;
61
62
double
sample =
sampleChain_m
[bin];
63
return
sample;
64
}
65
66
private
:
67
#ifdef WITH_UNIT_TESTS
68
FRIEND_TEST(GaussianSampleTest, ChainTest);
69
#endif
70
std::vector<double>
sampleChain_m
;
71
unsigned
int
numSamples_m
;
// size of this "dimension"
72
size_t
volumeLowerDimensions_m
;
// the "volume" of the sampling space of the lower "dimensions"
73
};
74
75
#endif
Util.h
SamplingMethod.h
Util::erfinv
double erfinv(double x)
Definition
Util.cpp:62
SampleGaussianSequence
Definition
SampleGaussianSequence.h:36
SampleGaussianSequence::create
void create(std::shared_ptr< SampleIndividual > &ind, size_t i)
Definition
SampleGaussianSequence.h:55
SampleGaussianSequence::sampleChain_m
std::vector< double > sampleChain_m
Definition
SampleGaussianSequence.h:70
SampleGaussianSequence::numSamples_m
unsigned int numSamples_m
Definition
SampleGaussianSequence.h:71
SampleGaussianSequence::SampleGaussianSequence
SampleGaussianSequence(double lower, double upper, size_t modulo, int nSample)
Definition
SampleGaussianSequence.h:40
SampleGaussianSequence::getNext
double getNext(unsigned int id)
Definition
SampleGaussianSequence.h:59
SampleGaussianSequence::volumeLowerDimensions_m
size_t volumeLowerDimensions_m
Definition
SampleGaussianSequence.h:72
SamplingMethod
Definition
SamplingMethod.h:33
Generated on Wed Sep 30 2026 07:14:52 for OPAL (Object Oriented Parallel Accelerator Library) by
1.9.8