OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
Normal.h
Go to the documentation of this file.
1//
2// Class Normal
3// This class provides normally distributed samples.
4//
5// Copyright (c) 2018, Christof Metzger-Kraus, Open Sourcerer
6// All rights reserved
7//
8// This file is part of OPAL.
9//
10// OPAL is free software: you can redistribute it and/or modify
11// it under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// You should have received a copy of the GNU General Public License
16// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
17//
18#ifndef OPAL_NORMAL_RANDOM_SAMPLING_H
19#define OPAL_NORMAL_RANDOM_SAMPLING_H
20
22#include "Sample/RNGStream.h"
23
24#include <type_traits>
25
26class Normal : public SamplingMethod
27{
28
29public:
30 typedef std::normal_distribution<double> dist_t;
31
32
33 Normal(double lower, double upper)
34 : dist_m(0.5 * (lower + upper), (upper - lower) / 10)
35 , RNGInstance_m(RNGStream::getInstance())
36 , seed_m(RNGStream::getGlobalSeed())
37 {}
38
39 Normal(double lower, double upper, std::size_t seed)
40 : dist_m(0.5 * (lower + upper), (upper - lower) / 10)
41 , RNGInstance_m(nullptr)
42 , seed_m(seed)
43 {}
44
46 if ( RNGInstance_m)
48 }
49
50 void create(boost::shared_ptr<SampleIndividual>& ind, size_t i) {
51 ind->genes[i] = RNGInstance_m->getNext(dist_m);
52 }
53
54 void allocate(const CmdArguments_t& /*args*/, const Comm::Bundle_t& comm) {
55 if ( !RNGInstance_m )
57 }
58
59private:
61
63
64 std::size_t seed_m;
65};
66
67#endif
boost::shared_ptr< CmdArguments > CmdArguments_t
Definition: CmdArguments.h:176
int seed
The current random seed.
Definition: Options.cpp:37
Definition: Normal.h:27
void allocate(const CmdArguments_t &, const Comm::Bundle_t &comm)
Definition: Normal.h:54
~Normal()
Definition: Normal.h:45
Normal(double lower, double upper, std::size_t seed)
Definition: Normal.h:39
std::size_t seed_m
Definition: Normal.h:64
dist_t dist_m
Definition: Normal.h:60
void create(boost::shared_ptr< SampleIndividual > &ind, size_t i)
Definition: Normal.h:50
RNGStream * RNGInstance_m
Definition: Normal.h:62
Normal(double lower, double upper)
Definition: Normal.h:33
std::normal_distribution< double > dist_t
Definition: Normal.h:30
static RNGStream * getInstance()
Definition: RNGStream.cpp:26
static void deleteInstance(RNGStream *&generator)
Definition: RNGStream.cpp:38
DISTR::result_type getNext(DISTR &RNGDist)
Definition: RNGStream.h:37
bundles all communicators for a specific role/pid
Definition: types.h:32
int island_id
Definition: types.h:33