[3602] | 1 | #ifndef RANDOMGENERATORINTERFACE_H_SEEN
|
---|
| 2 | #define RANDOMGENERATORINTERFACE_H_SEEN
|
---|
| 3 |
|
---|
| 4 | // Classes RandomGeneratorInterface
|
---|
| 5 | //
|
---|
| 6 | // R. Ansari (C) UPS+LAL IN2P3/CNRS 2009
|
---|
| 7 | // C. Magneville (C) DAPNIA/SPP CEA 2009
|
---|
| 8 |
|
---|
| 9 |
|
---|
| 10 | #include "machdefs.h"
|
---|
| 11 | #include "anydataobj.h"
|
---|
| 12 | #include <complex>
|
---|
| 13 | #include <vector>
|
---|
| 14 |
|
---|
| 15 | namespace SOPHYA {
|
---|
| 16 |
|
---|
[3604] | 17 | //! enum definition for the type of algorithm used for Gaussian distribution generation
|
---|
| 18 | enum GaussianGenAlgo {
|
---|
| 19 | C_Gaussian_BoxMuller = 0,
|
---|
| 20 | C_Gaussian_RandLibSNorm = 1,
|
---|
| 21 | C_Gaussian_PolarBoxMuller = 2,
|
---|
| 22 | C_Gaussian_RatioUnif = 3,
|
---|
| 23 | C_Gaussian_LevaRatioUnif = 4
|
---|
| 24 | };
|
---|
| 25 |
|
---|
| 26 | //! enum definition for the type of algorithm used for Poisson distribution generation
|
---|
| 27 | enum PoissonGenAlgo {
|
---|
| 28 | C_Poisson_Simple = 0,
|
---|
| 29 | C_Poisson_Ahrens = 1
|
---|
| 30 | };
|
---|
| 31 |
|
---|
| 32 | //! enum definition for the type of algorithm used for exponential distribution generation
|
---|
| 33 | enum ExponentialGenAlgo {
|
---|
| 34 | C_Exponential_Simple = 0,
|
---|
| 35 | C_Exponential_Ahrens = 1
|
---|
| 36 | };
|
---|
| 37 |
|
---|
| 38 | // Definition de l'interface pour les classes generateur aleatoire
|
---|
[3602] | 39 | class RandomGeneratorInterface : public AnyDataObj {
|
---|
| 40 | public:
|
---|
| 41 | RandomGeneratorInterface();
|
---|
| 42 | virtual ~RandomGeneratorInterface();
|
---|
| 43 |
|
---|
[3604] | 44 | //! Select Gaussian generation algorithm
|
---|
| 45 | inline void SelectGaussianAlgo(GaussianGenAlgo typ=C_Gaussian_BoxMuller)
|
---|
| 46 | { usegaussian_ = typ; }
|
---|
| 47 | //! Select Poisson generation algorithm
|
---|
| 48 | inline void SelectPoissonAlgo(PoissonGenAlgo typ=C_Poisson_Simple)
|
---|
| 49 | { usepoisson_ = typ; }
|
---|
| 50 | //! Select Exponential generation algorithm
|
---|
| 51 | inline void SelectExponentialAlgo(ExponentialGenAlgo typ=C_Exponential_Simple)
|
---|
| 52 | { useexpo_ = typ; }
|
---|
[3602] | 53 |
|
---|
[3604] | 54 | //! Return the Gaussian generation algorithm type
|
---|
| 55 | inline GaussianGenAlgo GetGaussianAlgo()
|
---|
| 56 | { return usegaussian_; }
|
---|
| 57 | //! Return the Poisson generation algorithm type
|
---|
| 58 | inline PoissonGenAlgo GetPoissonAlgo()
|
---|
| 59 | { return usepoisson_; }
|
---|
| 60 | //! Return the Exponential generation algorithm type
|
---|
| 61 | //! Select Exponential generation algorithm
|
---|
| 62 | inline ExponentialGenAlgo GetExponentialAlgo()
|
---|
| 63 | { return useexpo_; }
|
---|
[3602] | 64 |
|
---|
[3604] | 65 | virtual void GenerateSeedVector(int nseed,vector<uint_2>& seed,int lp=0);
|
---|
| 66 |
|
---|
[3602] | 67 | // --- Le tirage sur une distribution plate
|
---|
| 68 | /*! \brief Return a random number \b r with a flat distribution 0<=r<1 */
|
---|
| 69 | inline r_8 Flat01() {return Next();}
|
---|
| 70 | /*! \brief Return a random number \b r with a flat distribution -1<=r<1 */
|
---|
| 71 | inline r_8 Flatpm1() {return 2.*Next()-1.;}
|
---|
| 72 |
|
---|
| 73 | // --- Le tirage sur une distribution gaussienne
|
---|
| 74 | /*! \brief Return a random number following a gaussian distribution (sigma=1, mean=0)*/
|
---|
[3604] | 75 | virtual r_8 Gaussian();
|
---|
| 76 |
|
---|
[3602] | 77 | virtual r_8 GaussianBoxMuller();
|
---|
| 78 | virtual r_8 GaussianSNorm();
|
---|
| 79 | virtual r_8 GaussianPolarBoxMuller();
|
---|
| 80 | virtual r_8 GaussianRatioUnif();
|
---|
| 81 | virtual r_8 GaussianLevaRatioUnif();
|
---|
| 82 | /*! \brief Return a random number following a gaussian distribution "sigma", (mean=0)*/
|
---|
| 83 | inline r_8 Gaussian(double sigma) {return sigma*Gaussian();}
|
---|
| 84 | /*! \brief Return a random number following a gaussian distribution with mean=mu, and sigma */
|
---|
| 85 | inline r_8 Gaussian(double sigma,double mu) {return sigma*Gaussian()+mu;}
|
---|
| 86 |
|
---|
| 87 | /*! \brief Return a random number following a gaussian tail distribution for x>sdev */
|
---|
| 88 | virtual r_8 GaussianTail(double sdev);
|
---|
| 89 |
|
---|
| 90 | // --- Le tirage sur une distribution de poisson
|
---|
| 91 | /*! \brief Return a random number following a poisson distribution with mean mu */
|
---|
[3604] | 92 | virtual uint_8 Poisson(double mu, double mumax=-1);
|
---|
[3602] | 93 | virtual uint_8 PoissonSimple(double mu, double mumax=-1);
|
---|
| 94 | virtual uint_8 PoissonAhrens(double mu);
|
---|
| 95 |
|
---|
[3604] | 96 | //! Return a random number with exponential distribution
|
---|
| 97 | virtual r_8 Exponential();
|
---|
| 98 | inline r_8 Expo() { return Exponential(); }
|
---|
| 99 |
|
---|
[3602] | 100 | virtual r_8 ExpoSimple();
|
---|
| 101 | virtual r_8 ExpoAhrens();
|
---|
| 102 |
|
---|
| 103 | // --- Le tirage gaussien complexe (cf texte a la fin du .cc)
|
---|
| 104 | inline complex< r_8 > ComplexGaussRan(void)
|
---|
| 105 | {return complex< r_8 >(Gaussian(),Gaussian());}
|
---|
| 106 | inline complex< r_8 > ComplexGaussRan(double sig)
|
---|
| 107 | {return complex< r_8 >(sig*Gaussian(),sig*Gaussian());}
|
---|
| 108 | /*! \brief Returns the module of a random complex number generated by ComplexGaussRan */
|
---|
| 109 | inline double ModComplexGaussRan(double sig=1.)
|
---|
| 110 | {double r=-log(1.-Next()); return sig*sqrt(2.*r);}
|
---|
| 111 |
|
---|
[3604] | 112 | //! Return the pointer to the default global RandomGenerator object
|
---|
| 113 | static inline RandomGeneratorInterface* GetGlobalRandGenP()
|
---|
| 114 | { return gl_rndgen_p; }
|
---|
| 115 |
|
---|
| 116 | // Permet de definir l'instance global du generateur aleatoire
|
---|
| 117 | static void SetGlobalRandGenP(RandomGeneratorInterface* rgp);
|
---|
| 118 |
|
---|
[3602] | 119 | protected:
|
---|
| 120 | //! Return a random number in [0,1]
|
---|
| 121 | virtual r_8 Next();
|
---|
[3604] | 122 |
|
---|
| 123 | // Selection de type d'algo pour les aleatoires autres que plates
|
---|
| 124 | GaussianGenAlgo usegaussian_;
|
---|
| 125 | PoissonGenAlgo usepoisson_;
|
---|
| 126 | ExponentialGenAlgo useexpo_;
|
---|
| 127 |
|
---|
| 128 | // Instance global d'un generateur par defaut
|
---|
| 129 | static RandomGeneratorInterface* gl_rndgen_p;
|
---|
[3602] | 130 | };
|
---|
| 131 |
|
---|
| 132 | } /* namespace SOPHYA */
|
---|
| 133 |
|
---|
| 134 | #endif
|
---|