SST  10.1.0
StructuralSimulationToolkit
poisson.h
1 // Copyright 2009-2020 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-2020, 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 _H_SST_CORE_RNG_POISSON
13 #define _H_SST_CORE_RNG_POISSON
14 
15 #include "math.h"
16 
17 #include "distrib.h"
18 #include "mersenne.h"
19 
20 using namespace SST::RNG;
21 
22 namespace SST {
23 namespace RNG {
24 
25 /**
26  \class SSTPoissonDistribution 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  public:
34  /**
35  Creates an Poisson distribution with a specific lambda
36  \param mn The lambda of the Poisson distribution
37  */
38  SSTPoissonDistribution(const double mn) :
39  SSTRandomDistribution(), lambda(mn) {
40 
41  baseDistrib = new MersenneRNG();
42  deleteDistrib = true;
43  }
44 
45  /**
46  Creates an Poisson distribution with a specific lambda and a base random number generator
47  \param lambda The lambda of the Poisson distribution
48  \param baseDist The base random number generator to take the distribution from.
49  */
50  SSTPoissonDistribution(const double mn, SSTRandom* baseDist) :
51  SSTRandomDistribution(), lambda(mn) {
52 
53  baseDistrib = baseDist;
54  deleteDistrib = false;
55  }
56 
57  /**
58  Destroys the Poisson distribution
59  */
61  if(deleteDistrib) {
62  delete baseDistrib;
63  }
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  const double L = exp(-lambda);
72  double p = 1.0;
73  int k = 0;
74 
75  do {
76  k++;
77  p *= baseDistrib->nextUniform();
78  } while(p > L);
79 
80  return k - 1;
81  }
82 
83  /**
84  Gets the lambda with which the distribution was created
85  \return The lambda which the user created the distribution with
86  */
87  double getLambda() {
88  return lambda;
89  }
90 
91  protected:
92  /**
93  Sets the lambda of the Poisson distribution.
94  */
95  const double lambda;
96  /**
97  Sets the base random number generator for the distribution.
98  */
100 
101  /**
102  Controls whether the base distribution should be deleted when this class is destructed.
103  */
105 
106 };
107 
108 }
109 }
110 
111 #endif
Base class of statistical distributions in SST.
Definition: distrib.h:24
SSTRandom * baseDistrib
Sets the base random number generator for the distribution.
Definition: poisson.h:99
double getLambda()
Gets the lambda with which the distribution was created.
Definition: poisson.h:87
SSTPoissonDistribution(const double mn, SSTRandom *baseDist)
Creates an Poisson distribution with a specific lambda and a base random number generator.
Definition: poisson.h:50
const double lambda
Sets the lambda of the Poisson distribution.
Definition: poisson.h:95
bool deleteDistrib
Controls whether the base distribution should be deleted when this class is destructed.
Definition: poisson.h:104
Implements a Mersenne-based RNG for use in the SST core or components.
Definition: mersenne.h:34
Creates an Poisson distribution for use within SST.
Definition: poisson.h:31
~SSTPoissonDistribution()
Destroys the Poisson distribution.
Definition: poisson.h:60
Implements the base class for random number generators for the SST core.
Definition: sstrng.h:27
double getNextDouble()
Gets the next (random) double value in the distribution.
Definition: poisson.h:70
SSTPoissonDistribution(const double mn)
Creates an Poisson distribution with a specific lambda.
Definition: poisson.h:38