Changeset 3604 in Sophya for trunk/SophyaLib/BaseTools/randinterf.h
- Timestamp:
- Apr 29, 2009, 12:14:04 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/BaseTools/randinterf.h
r3602 r3604 15 15 namespace SOPHYA { 16 16 17 //! Definition of the interface for Random number generator classes 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 18 39 class RandomGeneratorInterface : public AnyDataObj { 19 40 public: … … 21 42 virtual ~RandomGeneratorInterface(); 22 43 23 void UseGaussian(uint_2 type=0); 24 void UsePoisson(uint_2 type=0); 25 void UseExpo(uint_2 type=0); 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; } 26 53 27 void GenerateSeedVector(int nseed,vector<uint_2>& seed,int lp=0); 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_; } 64 65 virtual void GenerateSeedVector(int nseed,vector<uint_2>& seed,int lp=0); 28 66 29 67 // --- Le tirage sur une distribution plate … … 35 73 // --- Le tirage sur une distribution gaussienne 36 74 /*! \brief Return a random number following a gaussian distribution (sigma=1, mean=0)*/ 37 inline r_8 Gaussian() 38 { 39 if(usegaussian_==0) return GaussianBoxMuller(); 40 if(usegaussian_==1) return GaussianSNorm(); 41 if(usegaussian_==2) return GaussianPolarBoxMuller(); 42 if(usegaussian_==3) return GaussianRatioUnif(); 43 if(usegaussian_==4) return GaussianLevaRatioUnif(); 44 return GaussianBoxMuller(); 45 } 75 virtual r_8 Gaussian(); 76 46 77 virtual r_8 GaussianBoxMuller(); 47 78 virtual r_8 GaussianSNorm(); … … 59 90 // --- Le tirage sur une distribution de poisson 60 91 /*! \brief Return a random number following a poisson distribution with mean mu */ 61 inline uint_8 Poisson(double mu, double mumax) 62 { 63 if(usepoisson_==0) return PoissonSimple(mu,mumax); 64 if(usepoisson_==1) return PoissonAhrens(mu); 65 return PoissonSimple(mu,mumax); 66 } 92 virtual uint_8 Poisson(double mu, double mumax=-1); 67 93 virtual uint_8 PoissonSimple(double mu, double mumax=-1); 68 94 virtual uint_8 PoissonAhrens(double mu); 69 95 70 // --- Le tirage sur une distribution exponentielle 71 inline r_8 Expo() 72 { 73 if(useexpo_==0) return ExpoSimple(); 74 if(useexpo_==1) return ExpoAhrens(); 75 return ExpoSimple(); 76 } 96 //! Return a random number with exponential distribution 97 virtual r_8 Exponential(); 98 inline r_8 Expo() { return Exponential(); } 99 77 100 virtual r_8 ExpoSimple(); 78 101 virtual r_8 ExpoAhrens(); … … 87 110 {double r=-log(1.-Next()); return sig*sqrt(2.*r);} 88 111 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 89 119 protected: 90 120 //! Return a random number in [0,1] 91 121 virtual r_8 Next(); 92 uint_2 usegaussian_, usepoisson_, useexpo_; 93 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; 94 130 }; 95 131
Note:
See TracChangeset
for help on using the changeset viewer.