Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
GSLRndmEngines.h
Go to the documentation of this file.
1// @(#)root/mathmore:$Id$
2// Author: L. Moneta, A. Zsenei 08/2005
3
4 /**********************************************************************
5 * *
6 * Copyright (c) 2004 ROOT Foundation, CERN/PH-SFT *
7 * *
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU General Public License *
10 * as published by the Free Software Foundation; either version 2 *
11 * of the License, or (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16 * General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU General Public License *
19 * along with this library (see file COPYING); if not, write *
20 * to the Free Software Foundation, Inc., 59 Temple Place, Suite *
21 * 330, Boston, MA 02111-1307 USA, or contact the author. *
22 * *
23 **********************************************************************/
24
25// Header file for class GSLRandom
26//
27// Created by: moneta at Sun Nov 21 16:26:03 2004
28//
29// Last update: Sun Nov 21 16:26:03 2004
30//
31#ifndef ROOT_Math_GSLRndmEngines
32#define ROOT_Math_GSLRndmEngines
33
34#include <string>
35#include <vector>
36
37
38namespace ROOT {
39namespace Math {
40
41
42 class GSLRngWrapper;
43 class GSLMCIntegrator;
44
45 //_________________________________________________________________
46 /**
47 GSLRandomEngine
48 Base class for all GSL random engines,
49 normally user instantiate the derived classes
50 which creates internally the generator.
51
52 The main GSL generators (see
53 <A HREF="http://www.gnu.org/software/gsl/manual/html_node/Random-number-generator-algorithms.html">
54 here</A>) are available as derived classes
55 In addition to generate uniform numbers it provides method for
56 generating numbers according to pre-defined distributions
57 using the GSL functions from
58 <A HREF="http://www.gnu.org/software/gsl/manual/html_node/Random-Number-Distributions.html">
59 GSL random number distributions</A>.
60
61
62
63 @ingroup Random
64 */
66
67 friend class GSLMCIntegrator;
68
69 public:
70
71 /**
72 default constructor. No creation of rng is done.
73 If then Initialize() is called an engine is created
74 based on default GSL type (MT)
75 */
77
78 /**
79 create from an existing rng.
80 User manage the rng pointer which is then deleted olny by calling Terminate()
81 */
83
84 /**
85 Copy constructor : clone the contained GSL generator
86 */
88
89 /**
90 Assignment operator : make a deep copy of the contained GSL generator
91 */
93
94 /**
95 initialize the generator
96 If no rng is present the default one based on Mersenne and Twister is created
97 */
98 void Initialize();
99
100 /**
101 delete pointer to contained rng
102 */
103 void Terminate();
104
105 /**
106 call Terminate()
107 */
108 virtual ~GSLRandomEngine();
109
110 /**
111 Generate a random number between ]0,1]
112 0 is excluded and 1 is included
113 */
114 double operator() () const;
115
116 /**
117 Generate a random number between ]0,1]
118 0 is excluded and 1 is included
119 */
120 double Rndm() const { return (*this)(); }
121
122 /**
123 Generate an integer number between [0,max-1] (including 0 and max-1)
124 if max is larger than available range of algorithm
125 an error message is printed and zero is returned
126 */
127 unsigned long RndmInt(unsigned long max) const;
128 /**
129 Generate an integer number between [0,max_generator-1] (including 0 and max-1)
130 if max is larger than available range of algorithm
131 an error message is printed and zero is returned
132 */
133 unsigned long IntRndm() const {
134 return RndmInt(MaxInt()); // max return the largest value the generator can give +1
135 }
136
137 /**
138 Generate an array of random numbers.
139 The iterators points to the random numbers
140 */
141 template<class Iterator>
142 void RandomArray(Iterator begin, Iterator end) const {
143 for ( Iterator itr = begin; itr != end; ++itr ) {
144 *itr = this->operator()();
145 }
146 }
147
148 /**
149 Generate an array of random numbers
150 The iterators points to the random numbers
151 */
152 void RandomArray(double * begin, double * end) const;
153
154 /**
155 return name of generator
156 */
157 std::string Name() const;
158
159 /**
160 return the state size of generator
161 */
162 unsigned int Size() const;
163
164 /**
165 return the minimum integer a generator can handle
166 typically this value is 0
167 */
168 unsigned long MinInt() const;
169
170 /**
171 return the maximum integer +1 a generator can handle
172
173 */
174 unsigned long MaxInt() const;
175
176 /**
177 set the random generator seed
178 */
179 void SetSeed(unsigned int seed) const;
180
181
182 /** @name Random Distributions
183 Implemented using the
184 <A HREF="http://www.gnu.org/software/gsl/manual/html_node/Random-Number-Distributions.html">
185 GSL Random number Distributions</A>
186 **/
187 //@{
188 /**
189 Gaussian distribution - default method is Box-Muller (polar method)
190 */
191 double Gaussian(double sigma) const;
192
193 /**
194 Gaussian distribution - Ziggurat method
195 */
196 double GaussianZig(double sigma) const;
197
198 /**
199 Gaussian distribution - Ratio method
200 */
201 double GaussianRatio(double sigma) const;
202 /**
203 Gaussian Tail distribution
204 */
205 double GaussianTail(double a, double sigma) const;
206
207 /**
208 Bivariate Gaussian distribution with correlation
209 */
210 void Gaussian2D(double sigmaX, double sigmaY, double rho, double &x, double &y) const;
211
212 /**
213 Multivariate Gaussian distribution
214 */
215 void GaussianND(const int dim, double *pars, double *covmat, double *genpars) const;
216
217 /**
218 Exponential distribution
219 */
220 double Exponential(double mu) const;
221
222 /**
223 Cauchy distribution
224 */
225 double Cauchy(double a) const;
226
227 /**
228 Landau distribution
229 */
230 double Landau() const;
231
232 /**
233 Gamma distribution
234 */
235 double Gamma(double a, double b) const;
236
237 /**
238 Beta distribution
239 */
240 double Beta(double a, double b) const;
241
242 /**
243 Log Normal distribution
244 */
245 double LogNormal(double zeta, double sigma) const;
246
247 /**
248 Chi square distribution
249 */
250 double ChiSquare(double nu) const;
251
252 /**
253 F distrbution
254 */
255 double FDist(double nu1, double nu2) const;
256
257 /**
258 t student distribution
259 */
260 double tDist(double nu) const;
261
262 /**
263 Rayleigh distribution
264 */
265 double Rayleigh(double sigma) const;
266
267 /**
268 Logistic distribution
269 */
270 double Logistic(double a) const;
271
272 /**
273 Pareto distribution
274 */
275 double Pareto(double a, double b) const;
276
277 /**
278 generate random numbers in a 2D circle of radious 1
279 */
280 void Dir2D(double &x, double &y) const;
281
282 /**
283 generate random numbers in a 3D sphere of radious 1
284 */
285 void Dir3D(double &x, double &y, double &z) const;
286
287 /**
288 Poisson distribution
289 */
290 unsigned int Poisson(double mu) const;
291
292 /**
293 Binomial distribution
294 */
295 unsigned int Binomial(double p, unsigned int n) const;
296
297 /**
298 Negative Binomial distribution
299 */
300 unsigned int NegativeBinomial(double p, double n) const;
301
302 /**
303 Multinomial distribution
304 */
305 std::vector<unsigned int> Multinomial( unsigned int ntot, const std::vector<double> & p ) const;
306
307 //@}
308
309
310
311 protected:
312
313 /// internal method used by the derived class to set the type of generators
315 fRng = r;
316 }
317
318 /// internal method to return the engine
319 /// Used by class like GSLMCIntegrator to set the engine
321 return fRng;
322 }
323
324 private:
325
326 GSLRngWrapper * fRng; // pointer to GSL generator wrapper (managed by the class)
327 mutable unsigned int fCurTime; // current time used to seed the generator
328
329
330 };
331
332 //_____________________________________________________________________________________
333 /**
334 Mersenne-Twister generator
335 gsl_rng_mt19937 from
336 <A HREF="http://www.gnu.org/software/gsl/manual/html_node/Random-number-generator-algorithms.html">here</A>
337
338
339 @ingroup Random
340 */
341 class GSLRngMT : public GSLRandomEngine {
342 public:
344 GSLRngMT();
345 };
346
347 //_____________________________________________________________________________________
348 /**
349 Old Ranlux generator (James, Luscher) (default luxury level, p = 223)
350 (This is eequivalent to TRandom1 with default luxury level)
351 see <A HREF="http://www.gnu.org/software/gsl/manual/html_node/Random-number-generator-algorithms.html">here</A>
352
353 @ingroup Random
354 */
356 public:
358 GSLRngRanLux();
359 };
360
361 //_____________________________________________________________________________________
362 /**
363 Second generation of Ranlux generator for single precision with luxury level of 1
364 (It throws away 202 values for every 12 used)
365 see <A HREF="http://www.gnu.org/software/gsl/manual/html_node/Random-number-generator-algorithms.html">here</A>
366
367 @ingroup Random
368 */
370 public:
373 };
374 typedef GSLRngRanLuxS1 GSLRngRanLux1; // for backward compatibility
375
376 //_____________________________________________________________________________________
377 /**
378 Second generation of Ranlux generator for Single precision with luxury level of 2
379 (It throws away 397 value for every 12 used)
380 see <A HREF="http://www.gnu.org/software/gsl/manual/html_node/Random-number-generator-algorithms.html">here</A>
381
382 @ingroup Random
383 */
385 public:
388 };
389 typedef GSLRngRanLuxS2 GSLRngRanLux2; // for backward compatibility
390
391 //_____________________________________________________________________________________
392 /**
393 Double precision (48 bits) version of Second generation of Ranlux generator with luxury level of 1
394 (It throws away 202 value for every 12 used)
395 see <A HREF="http://www.gnu.org/software/gsl/manual/html_node/Random-number-generator-algorithms.html">here</A>
396
397 @ingroup Random
398 */
400 public:
403 };
404
405 //_____________________________________________________________________________________
406 /**
407 Double precision (48 bits) version of Second generation of Ranlux generator with luxury level of 2
408 (It throws away 397 value for every 12 used)
409 see <A HREF="http://www.gnu.org/software/gsl/manual/html_node/Random-number-generator-algorithms.html">here</A>
410
411 @ingroup Random
412 */
414 public:
417 };
418 typedef GSLRngRanLuxD2 GSLRngRanLux48; // for backward compatibility
419
420
421 //_____________________________________________________________________________________
422 /**
423 Tausworthe generator by L'Ecuyer
424 see <A HREF="http://www.gnu.org/software/gsl/manual/html_node/Random-number-generator-algorithms.html">here</A>
425
426 @ingroup Random
427 */
429 public:
431 GSLRngTaus();
432 };
433
434 //_____________________________________________________________________________________
435 /**
436 Lagged Fibonacci generator by Ziff
437 see <A HREF="http://www.gnu.org/software/gsl/manual/html_node/Random-number-generator-algorithms.html">here</A>
438
439 @ingroup Random
440 */
442 public:
444 GSLRngGFSR4();
445 };
446
447 //_____________________________________________________________________________________
448 /**
449 Combined multiple recursive generator (L'Ecuyer)
450 see <A HREF="http://www.gnu.org/software/gsl/manual/html_node/Random-number-generator-algorithms.html">here</A>
451
452 @ingroup Random
453 */
455 public:
457 GSLRngCMRG();
458 };
459
460 //_____________________________________________________________________________________
461 /**
462 5-th order multiple recursive generator (L'Ecuyer, Blouin and Coutre)
463 see <A HREF="http://www.gnu.org/software/gsl/manual/html_node/Random-number-generator-algorithms.html">here</A>
464
465 @ingroup Random
466 */
467 class GSLRngMRG : public GSLRandomEngine {
468 public:
470 GSLRngMRG();
471 };
472
473 //_____________________________________________________________________________________
474 /**
475 BSD rand() generator
476 gsl_rmg_rand from
477 <A HREF="http://www.gnu.org/software/gsl/manual/html_node/Unix-random-number-generators.html">here</A>
478
479 @ingroup Random
480 */
482 public:
484 GSLRngRand();
485 };
486
487 //_____________________________________________________________________________________
488 /**
489 RANMAR generator
490 see <A HREF="http://www.gnu.org/software/gsl/manual/html_node/Unix-random-number-generators.html">here</A>
491
492 @ingroup Random
493 */
495 public:
497 GSLRngRanMar();
498 };
499
500 //_____________________________________________________________________________________
501 /**
502 MINSTD generator (Park and Miller)
503 see <A HREF="http://www.gnu.org/software/gsl/manual/html_node/Unix-random-number-generators.html">here</A>
504
505 @ingroup Random
506 */
508 public:
510 GSLRngMinStd();
511 };
512
513 /** MixMax generator based on ROOT::Math::MixMaxEngine of N=240
514
515 @ingroup Random
516 */
518 public:
520 GSLRngMixMax();
521 ~GSLRngMixMax() override; // we need a dtcor since is not a standard GSL engine
522 };
523
524} // namespace Math
525} // namespace ROOT
526
527// random functions specialization for GSL
528// needs to be defined after defining GSLRandomEngine class
529
531
532#endif /* ROOT_Math_GSLRndmEngines */
533
#define b(i)
Definition RSha256.hxx:100
#define a(i)
Definition RSha256.hxx:99
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
GSLRandomEngine Base class for all GSL random engines, normally user instantiate the derived classes ...
double operator()() const
Generate a random number between ]0,1] 0 is excluded and 1 is included.
void Dir3D(double &x, double &y, double &z) const
generate random numbers in a 3D sphere of radious 1
void SetSeed(unsigned int seed) const
set the random generator seed
void Gaussian2D(double sigmaX, double sigmaY, double rho, double &x, double &y) const
Bivariate Gaussian distribution with correlation.
unsigned int Poisson(double mu) const
Poisson distribution.
double ChiSquare(double nu) const
Chi square distribution.
double FDist(double nu1, double nu2) const
F distrbution.
GSLRngWrapper * Engine()
internal method to return the engine Used by class like GSLMCIntegrator to set the engine
double Gamma(double a, double b) const
Gamma distribution.
GSLRandomEngine()
default constructor.
double Exponential(double mu) const
Exponential distribution.
double GaussianTail(double a, double sigma) const
Gaussian Tail distribution.
double Rayleigh(double sigma) const
Rayleigh distribution.
std::vector< unsigned int > Multinomial(unsigned int ntot, const std::vector< double > &p) const
Multinomial distribution.
unsigned long MaxInt() const
return the maximum integer +1 a generator can handle
double Cauchy(double a) const
Cauchy distribution.
double GaussianZig(double sigma) const
Gaussian distribution - Ziggurat method.
unsigned long MinInt() const
return the minimum integer a generator can handle typically this value is 0
double Gaussian(double sigma) const
Gaussian distribution - default method is Box-Muller (polar method)
double Beta(double a, double b) const
Beta distribution.
double Landau() const
Landau distribution.
unsigned int NegativeBinomial(double p, double n) const
Negative Binomial distribution.
void RandomArray(Iterator begin, Iterator end) const
Generate an array of random numbers.
unsigned int Size() const
return the state size of generator
double Pareto(double a, double b) const
Pareto distribution.
double LogNormal(double zeta, double sigma) const
Log Normal distribution.
unsigned int Binomial(double p, unsigned int n) const
Binomial distribution.
void Dir2D(double &x, double &y) const
generate random numbers in a 2D circle of radious 1
unsigned long IntRndm() const
Generate an integer number between [0,max_generator-1] (including 0 and max-1) if max is larger than ...
void GaussianND(const int dim, double *pars, double *covmat, double *genpars) const
Multivariate Gaussian distribution.
void Terminate()
delete pointer to contained rng
std::string Name() const
return name of generator
double GaussianRatio(double sigma) const
Gaussian distribution - Ratio method.
double Logistic(double a) const
Logistic distribution.
unsigned long RndmInt(unsigned long max) const
Generate an integer number between [0,max-1] (including 0 and max-1) if max is larger than available ...
void SetType(GSLRngWrapper *r)
internal method used by the derived class to set the type of generators
void Initialize()
initialize the generator If no rng is present the default one based on Mersenne and Twister is create...
double tDist(double nu) const
t student distribution
GSLRandomEngine & operator=(const GSLRandomEngine &eng)
Assignment operator : make a deep copy of the contained GSL generator.
double Rndm() const
Generate a random number between ]0,1] 0 is excluded and 1 is included.
virtual ~GSLRandomEngine()
call Terminate()
Combined multiple recursive generator (L'Ecuyer) see here
GSLRandomEngine BaseType
Lagged Fibonacci generator by Ziff see here
5-th order multiple recursive generator (L'Ecuyer, Blouin and Coutre) see here
GSLRandomEngine BaseType
Mersenne-Twister generator gsl_rng_mt19937 from here
GSLRandomEngine BaseType
MINSTD generator (Park and Miller) see here
MixMax generator based on ROOT::Math::MixMaxEngine of N=240.
Double precision (48 bits) version of Second generation of Ranlux generator with luxury level of 1 (I...
Double precision (48 bits) version of Second generation of Ranlux generator with luxury level of 2 (I...
Second generation of Ranlux generator for single precision with luxury level of 1 (It throws away 202...
Second generation of Ranlux generator for Single precision with luxury level of 2 (It throws away 397...
Old Ranlux generator (James, Luscher) (default luxury level, p = 223) (This is eequivalent to TRandom...
RANMAR generator see here
BSD rand() generator gsl_rmg_rand from here
GSLRandomEngine BaseType
Tausworthe generator by L'Ecuyer see here
GSLRandomEngine BaseType
GSLRngWrapper class to wrap gsl_rng structure.
const Double_t sigma
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
Namespace for new Math classes and functions.
GSLRngRanLuxS1 GSLRngRanLux1
GSLRngRanLuxS2 GSLRngRanLux2
GSLRngRanLuxD2 GSLRngRanLux48
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.