SST  12.0.1
StructuralSimulationToolkit
poisson.h
1 // Copyright 2009-2022 NTESS. Under the terms
2 // of Contract DE-NA0003525 with NTESS, the U.S.
3 // Government retains certain rights in this software.
4 //
5 // Copyright (c) 2009-2022, NTESS
6 // All rights reserved.
7 //
8 // This file is part of the SST software package. For license
9 // information, see the LICENSE file in the top level directory of the
10 // distribution.
11 
12 #ifndef SST_CORE_RNG_POISSON_H
13 #define SST_CORE_RNG_POISSON_H
14 
15 #include "distrib.h"
16 #include "math.h"
17 #include "mersenne.h"
18 #include "rng.h"
19 
20 using namespace SST::RNG;
21 
22 namespace SST {
23 namespace RNG {
24 
25 /**
26  \class PoissonDistribution poisson.h "sst/core/rng/poisson.h"
27 
28  Creates an Poisson distribution for use within SST. This distribution is the same across
29  platforms and compilers.
30 */
32 {
33 
34 public:
35  /**
36  Creates an Poisson distribution with a specific lambda
37  \param mn The lambda of the Poisson distribution
38  */
39  PoissonDistribution(const double mn) : RandomDistribution(), lambda(mn)
40  {
41 
42  baseDistrib = new MersenneRNG();
43  deleteDistrib = true;
44  }
45 
46  /**
47  Creates an Poisson distribution with a specific lambda and a base random number generator
48  \param lambda The lambda of the Poisson distribution
49  \param baseDist The base random number generator to take the distribution from.
50  */
51  PoissonDistribution(const double mn, SST::RNG::Random* baseDist) : RandomDistribution(), lambda(mn)
52  {
53 
54  baseDistrib = baseDist;
55  deleteDistrib = false;
56  }
57 
58  /**
59  Destroys the Poisson distribution
60  */
62  {
63  if ( deleteDistrib ) { delete baseDistrib; }
64  }
65 
66  /**
67  Gets the next (random) double value in the distribution
68  \return The next random double from the distribution
69  */
70  double getNextDouble()
71  {
72  const double L = exp(-lambda);
73  double p = 1.0;
74  int k = 0;
75 
76  do {
77  k++;
78  p *= baseDistrib->nextUniform();
79  } while ( p > L );
80 
81  return k - 1;
82  }
83 
84  /**
85  Gets the lambda with which the distribution was created
86  \return The lambda which the user created the distribution with
87  */
88  double getLambda() { return lambda; }
89 
90 protected:
91  /**
92  Sets the lambda of the Poisson distribution.
93  */
94  const double lambda;
95  /**
96  Sets the base random number generator for the distribution.
97  */
99 
100  /**
101  Controls whether the base distribution should be deleted when this class is destructed.
102  */
104 };
105 
107 
108 } // namespace RNG
109 } // namespace SST
110 
111 #endif // SST_CORE_RNG_POISSON_H
Implements the base class for random number generators for the SST core.
Definition: rng.h:27
bool deleteDistrib
Controls whether the base distribution should be deleted when this class is destructed.
Definition: poisson.h:103
PoissonDistribution(const double mn, SST::RNG::Random *baseDist)
Creates an Poisson distribution with a specific lambda and a base random number generator.
Definition: poisson.h:51
~PoissonDistribution()
Destroys the Poisson distribution.
Definition: poisson.h:61
double getNextDouble()
Gets the next (random) double value in the distribution.
Definition: poisson.h:70
const double lambda
Sets the lambda of the Poisson distribution.
Definition: poisson.h:94
Implements a Mersenne-based RNG for use in the SST core or components.
Definition: mersenne.h:34
double getLambda()
Gets the lambda with which the distribution was created.
Definition: poisson.h:88
SST::RNG::Random * baseDistrib
Sets the base random number generator for the distribution.
Definition: poisson.h:98
PoissonDistribution(const double mn)
Creates an Poisson distribution with a specific lambda.
Definition: poisson.h:39
Creates an Poisson distribution for use within SST.
Definition: poisson.h:31
Base class of statistical distributions in SST.
Definition: distrib.h:22