COPASI API  4.16.103
CRandom.h
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2014 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2008 - 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 // Copyright (C) 2002 - 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 #ifndef COPASI_CRandom
16 #define COPASI_CRandom
17 
18 #include <string>
19 
20 class CRandom
21 {
22  // Attributes
23 public:
24  /**
25  * The valid types of a function
26  */
27  struct PoissonVars
28  {
40 
42 
43  C_FLOAT64 b1, b2, c, c0, c1, c2, c3, d, del, difmuk, e, fk, fx, fy, g, omega, p, p0, px, py, q, s,
44  t, u, v, x, xx, pp[35];
45  };
46 
47  struct ExpVars
48  {
53  };
54 
55  enum Type
56  {
57  r250 = 0,
61  };
62 
63  /**
64  * String literals for the GUI to display type names of random number
65  * generators known to COPASI.
66  */
67  static const std::string TypeName[];
68 
69  /**
70  * XML type names of random number generators known to COPASI.
71  */
72  static const char * XMLType[];
73 
74 protected:
75  /**
76  * A unsigned 32-bit integer random number.
77  */
78  unsigned C_INT32 mNumberU;
79 
80  /**
81  * A signed 32-bit integer random number.
82  */
84 
85  /**
86  * A 64-bit floating point random number.
87  */
89 
90  /**
91  * The type of the generator
92  */
94 
95  /**
96  *
97  */
98  unsigned C_INT32 mModulus;
99 
100  /**
101  *
102  */
104 
105  /**
106  *
107  */
109 
110 private:
111 
114  C_FLOAT64 fsign(C_FLOAT64 num, C_FLOAT64 sign);
115  unsigned int& syscall(int arg1);
116 
117  // Operations
118 protected:
119  /**
120  * Default/Named constructor.
121  * Seeds the random number generator with the given seed.
122  */
123  CRandom();
124 
125 public:
126  /**
127  * get a system dependend seed (hopefully random)
128  */
129  static unsigned C_INT32 getSystemSeed();
130 
131  /**
132  * Create a Generator.
133  * Note: the returned object has to be released after use with delete
134  * @param CRandom::Type type (default Mersenne Twister)
135  * @param const C_INT32 & seed (default system generated seed)
136  * @return CRandom * randomGenerator
137  */
139  unsigned C_INT32 seed = 0);
140 
141  /**
142  * The destructor.
143  */
144  virtual ~CRandom();
145 
146  /**
147  * Retreive the type of the generator
148  * @return const CRandom::Type & type
149  */
150  const CRandom::Type & getType() const;
151 
152  /**
153  * Retreive the method dependend modulus
154  * @return const unsigned C_INT32 & modulus
155  */
156  const unsigned C_INT32 & getModulus() const;
157 
158  /**
159  * Initialize or reinitialize the random number generator with
160  * the given seed.
161  * @param unsigned C_INT32 seed (default system seed)
162  */
163  virtual void initialize(unsigned C_INT32 seed = CRandom::getSystemSeed());
164 
165  /**
166  * Get a random number in 0 <= n <= Modulus
167  * @return unsigned C_INT32 random
168  */
169  virtual unsigned C_INT32 getRandomU();
170 
171  /**
172  * Get a random number in 0 <= n <= (Modulus & 0x7ffffff)
173  * @return C_INT32 random
174  */
175  virtual C_INT32 getRandomS();
176 
177  /**
178  * Get a random number in 0 <= n <= max
179  * Note: max must be smaller than Modulus (no check for performance)
180  * @param const unsigned C_INT32 & max
181  * @return unsigned C_INT32 random
182  */
183  virtual unsigned C_INT32 getRandomU(const unsigned C_INT32 & max);
184 
185  /**
186  * Get a random number in 0 <= n <= max
187  * Note: max must be smaller than Modulus (no check for performance)
188  * @param const C_INT32 & max
189  * @return C_INT32 random
190  */
191  virtual C_INT32 getRandomS(const C_INT32 & max);
192 
193  /**
194  * Produces a uniformly distributed random number in 0 <= x <= 1.
195  * @return C_FLOAT64 random
196  */
197  virtual C_FLOAT64 getRandomCC();
198 
199  /**
200  * Produces a uniformly distributed random number in 0 <= x < 1.
201  * Note: 0 < x <= 1 may be achieved by 1.0 - getRandomCO().
202  * @return C_FLOAT64 random
203  */
204  virtual C_FLOAT64 getRandomCO();
205 
206  /**
207  * Produces a uniformly distributed random number in 0 < x < 1.
208  * @return C_FLOAT64 random
209  */
210  virtual C_FLOAT64 getRandomOO();
211 
212  /**
213  * Produces a Normally distributed random number with mean=0 and SD=1
214  * @return C_FLOAT64 random
215  */
216  virtual C_FLOAT64 getRandomNormal01();
217 
218  /**
219  * Produces a Normally distributed random number with Mean=mean and SD=sd
220  * @param const C_FLOAT64 & mean
221  * @param const C_FLOAT64 & sd
222  * @return C_FLOAT64 random
223  */
224  virtual C_FLOAT64 getRandomNormal(const C_FLOAT64 & mean,
225  const C_FLOAT64 & sd);
226 
227  /**
228  * Produces a Strictly Positive Normally distributed random number
229  * with Mean=mean and SD=sd
230  * @param const C_FLOAT64 & mean
231  * @param const C_FLOAT64 & sd
232  * @return C_FLOAT64 random
233  */
234  virtual C_FLOAT64 getRandomNormalPositive(const C_FLOAT64 & mean,
235  const C_FLOAT64 & sd);
236 
237  /**
238  * Produces a Normally distributed random number with Mean=mean and SD=sd
239  * in Logarithmic scale
240  * @return C_FLOAT64 random
241  */
242  virtual C_FLOAT64 getRandomNormalLog(const C_FLOAT64 & mean,
243  const C_FLOAT64 & sd);
244 
245  /**
246  * Produces a Poisson distributed random number with Mean=mean
247  * @param const C_FLOAT64 & mean
248  * @return C_FLOAT64 random
249  */
250 
251  virtual C_FLOAT64 getRandomPoisson(const C_FLOAT64 & mean);
252  virtual C_FLOAT64 getRandomExp();
253  /* Added on Jan 31, 2005 */
254 
255  virtual C_FLOAT64 getRandomGamma(C_FLOAT64 shape, C_FLOAT64 scale);
256  virtual C_FLOAT64 getRandomStdGamma(C_FLOAT64 shape);
257 
258 protected:
259 
260  /**
261  * Set the Modulus
262  * @param
263  */
264 
265  void setModulus(const unsigned C_INT32 & modulus);
266 };
267 
268 #include "Cr250.h"
269 #include "Cmt19937.h"
270 
271 #endif // COPASI_CRandom
virtual ~CRandom()
Definition: CRandom.cpp:125
C_FLOAT64 q[8]
Definition: CRandom.h:49
unsigned int & syscall(int arg1)
C_FLOAT64 xx
Definition: CRandom.h:43
C_FLOAT64 sexpo
Definition: CRandom.h:51
static unsigned C_INT32 getSystemSeed()
Definition: CRandom.cpp:136
C_FLOAT64 del
Definition: CRandom.h:43
virtual C_FLOAT64 getRandomNormal(const C_FLOAT64 &mean, const C_FLOAT64 &sd)
Definition: CRandom.cpp:292
C_FLOAT64 u
Definition: CRandom.h:51
C_FLOAT64 mFloat
Definition: CRandom.h:88
virtual C_FLOAT64 getRandomOO()
Definition: CRandom.cpp:254
C_FLOAT64 a7
Definition: CRandom.h:36
virtual C_FLOAT64 getRandomExp()
Definition: CRandom.cpp:473
virtual C_FLOAT64 getRandomStdGamma(C_FLOAT64 shape)
Definition: CRandom.cpp:508
const CRandom::Type & getType() const
Definition: CRandom.cpp:126
C_FLOAT64 a
Definition: CRandom.h:51
virtual C_INT32 getRandomS()
Definition: CRandom.cpp:184
C_INT32 i
Definition: CRandom.h:50
C_FLOAT64 c3
Definition: CRandom.h:43
C_FLOAT64 pp[35]
Definition: CRandom.h:43
C_INT32 mNumberS
Definition: CRandom.h:83
C_FLOAT64 a0
Definition: CRandom.h:29
#define C_INT32
Definition: copasi.h:90
C_FLOAT64 muold
Definition: CRandom.h:37
C_FLOAT64 a6
Definition: CRandom.h:35
C_FLOAT64 px
Definition: CRandom.h:43
static const char * XMLType[]
Definition: CRandom.h:72
C_FLOAT64 umin
Definition: CRandom.h:51
C_FLOAT64 c2
Definition: CRandom.h:43
C_FLOAT64 a1
Definition: CRandom.h:30
virtual C_FLOAT64 getRandomNormal01()
Definition: CRandom.cpp:261
const unsigned C_INT32 & getModulus() const
Definition: CRandom.cpp:127
static const std::string TypeName[]
Definition: CRandom.h:67
C_FLOAT64 mModulusInv1
Definition: CRandom.h:108
static CRandom * createGenerator(CRandom::Type type=CRandom::mt19937, unsigned C_INT32 seed=0)
Definition: CRandom.cpp:49
C_FLOAT64 a2
Definition: CRandom.h:31
virtual C_FLOAT64 getRandomPoisson(const C_FLOAT64 &mean)
Definition: CRandom.cpp:314
C_FLOAT64 fact[10]
Definition: CRandom.h:39
virtual C_FLOAT64 getRandomCC()
Definition: CRandom.cpp:235
virtual C_FLOAT64 getRandomNormalPositive(const C_FLOAT64 &mean, const C_FLOAT64 &sd)
Definition: CRandom.cpp:298
virtual unsigned C_INT32 getRandomU()
Definition: CRandom.cpp:173
C_FLOAT64 mModulusInv
Definition: CRandom.h:103
C_FLOAT64 p0
Definition: CRandom.h:43
C_FLOAT64 muprev
Definition: CRandom.h:38
C_FLOAT64 b2
Definition: CRandom.h:43
C_FLOAT64 ustar
Definition: CRandom.h:51
C_FLOAT64 a3
Definition: CRandom.h:32
C_FLOAT64 c0
Definition: CRandom.h:43
PoissonVars varp
Definition: CRandom.h:112
void setModulus(const unsigned C_INT32 &modulus)
Definition: CRandom.cpp:129
C_FLOAT64 difmuk
Definition: CRandom.h:43
C_FLOAT64 fy
Definition: CRandom.h:43
CRandom()
Definition: CRandom.cpp:83
C_FLOAT64 omega
Definition: CRandom.h:43
C_FLOAT64 * q1
Definition: CRandom.h:52
virtual C_FLOAT64 getRandomCO()
Definition: CRandom.cpp:245
C_FLOAT64 fsign(C_FLOAT64 num, C_FLOAT64 sign)
Definition: CRandom.cpp:466
virtual C_FLOAT64 getRandomNormalLog(const C_FLOAT64 &mean, const C_FLOAT64 &sd)
Definition: CRandom.cpp:310
C_FLOAT64 c1
Definition: CRandom.h:43
#define C_FLOAT64
Definition: copasi.h:92
C_FLOAT64 a4
Definition: CRandom.h:33
ExpVars vare
Definition: CRandom.h:113
C_FLOAT64 a5
Definition: CRandom.h:34
CRandom::Type mType
Definition: CRandom.h:93
C_FLOAT64 fx
Definition: CRandom.h:43
virtual C_FLOAT64 getRandomGamma(C_FLOAT64 shape, C_FLOAT64 scale)
Definition: CRandom.cpp:572
unsigned C_INT32 mModulus
Definition: CRandom.h:98
unsigned C_INT32 mNumberU
Definition: CRandom.h:78
C_FLOAT64 py
Definition: CRandom.h:43
C_FLOAT64 b1
Definition: CRandom.h:43
C_FLOAT64 fk
Definition: CRandom.h:43
virtual void initialize(unsigned C_INT32 seed=CRandom::getSystemSeed())
Definition: CRandom.cpp:162
#define max(a, b)
Definition: f2c.h:176