Changeset 718 for trunk/yat/random
 Timestamp:
 Dec 26, 2006, 10:56:26 AM (16 years ago)
 Location:
 trunk/yat/random
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

trunk/yat/random/random.cc
r706 r718 34 34 RNG* RNG::instance_ = NULL; 35 35 36 37 36 RNG::RNG(void) 38 37 { … … 50 49 51 50 51 u_long RNG::max(void) const 52 { 53 return gsl_rng_max(rng_); 54 } 55 56 57 u_long RNG::min(void) const 58 { 59 return gsl_rng_min(rng_); 60 } 61 62 63 std::string RNG::name(void) const 64 { 65 return gsl_rng_name(rng_); 66 } 67 68 69 const gsl_rng* RNG::rng(void) const 70 { 71 return rng_; 72 } 73 74 75 void RNG::seed(u_long s) const 76 { 77 gsl_rng_set(rng_,s); 78 } 79 80 52 81 u_long RNG::seed_from_devurandom(void) 53 82 { … … 72 101 } 73 102 103 //  RNG_state  74 104 75 105 RNG_state::RNG_state(const RNG* rng) … … 85 115 } 86 116 117 const gsl_rng* RNG_state::rng(void) const 118 { 119 return rng_; 120 } 121 87 122 //  Discrete distribtuions  88 123 … … 95 130 Discrete::~Discrete(void) 96 131 { 132 } 133 134 135 void Discrete::seed(u_long s) const 136 { 137 rng_>seed(s); 97 138 } 98 139 … … 116 157 117 158 159 u_long DiscreteGeneral::operator()(void) const 160 { 161 return gsl_ran_discrete(rng_>rng(), gen_); 162 } 163 164 165 DiscreteUniform::DiscreteUniform(void) 166 : range_(rng_>max()) 167 { 168 } 169 170 DiscreteUniform::DiscreteUniform(const u_long n) 171 : range_(n) 172 { 173 if (range_>rng_>max()) 174 range_=rng_>max(); 175 } 176 177 178 u_long DiscreteUniform::operator()(void) const 179 { 180 return gsl_rng_uniform_int(rng_>rng(), range_); 181 } 182 183 184 u_long DiscreteUniform::operator()(const u_long n) const 185 { 186 return gsl_rng_uniform_int(rng_>rng(), n); 187 } 188 189 118 190 Poisson::Poisson(const double m) 119 191 : m_(m) … … 121 193 } 122 194 195 u_long Poisson::operator()(void) const 196 { 197 return gsl_ran_poisson(rng_>rng(), m_); 198 } 199 200 201 u_long Poisson::operator()(const double m) const 202 { 203 return gsl_ran_poisson(rng_>rng(), m); 204 } 205 123 206 //  Continuous distribtuions  124 207 … … 134 217 135 218 219 void Continuous::seed(u_long s) const 220 { 221 rng_>seed(s); 222 } 223 224 136 225 ContinuousGeneral::ContinuousGeneral(const statistics::Histogram& hist) 137 226 : discrete_(DiscreteGeneral(hist)), hist_(hist) … … 140 229 141 230 231 double ContinuousGeneral::operator()(void) const 232 { 233 return hist_.observation_value(discrete_())+(u_()0.5)*hist_.spacing(); 234 } 235 236 double ContinuousUniform::operator()(void) const 237 { 238 return gsl_rng_uniform(rng_>rng()); 239 } 240 241 142 242 Exponential::Exponential(const double m) 143 243 : m_(m) … … 146 246 147 247 248 double Exponential::operator()(void) const 249 { 250 return gsl_ran_exponential(rng_>rng(), m_); 251 } 252 253 254 double Exponential::operator()(const double m) const 255 { 256 return gsl_ran_exponential(rng_>rng(), m); 257 } 258 259 148 260 Gaussian::Gaussian(const double s, const double m) 149 261 : m_(m), s_(s) … … 151 263 } 152 264 265 266 double Gaussian::operator()(void) const 267 { 268 return gsl_ran_gaussian(rng_>rng(), s_)+m_; 269 } 270 271 272 double Gaussian::operator()(const double s) const 273 { 274 return gsl_ran_gaussian(rng_>rng(), s); 275 } 276 277 278 double Gaussian::operator()(const double s, const double m) const 279 { 280 return gsl_ran_gaussian(rng_>rng(), s)+m; 281 } 282 153 283 }}} // of namespace random, yat, and theplu 
trunk/yat/random/random.h
r706 r718 98 98 /// generator can return. 99 99 /// 100 inline u_long max(void) const { return gsl_rng_max(rng_); }100 u_long max(void) const; 101 101 102 102 /// … … 104 104 /// generator can return. 105 105 /// 106 inline u_long min(void) const { return gsl_rng_min(rng_); }106 u_long min(void) const; 107 107 108 108 /// 109 109 /// @brief Returns the name of the random number generator 110 110 /// 111 inline std::string name(void) const { return gsl_rng_name(rng_); }111 std::string name(void) const; 112 112 113 113 /// 114 114 /// @return const pointer to underlying GSL random generator. 115 115 /// 116 inline const gsl_rng* rng(void) const { return rng_; }116 const gsl_rng* rng(void) const; 117 117 118 118 /// … … 125 125 /// @see seed_from_devurandom 126 126 /// 127 inline void seed(u_long s) const { gsl_rng_set(rng_,s); }127 void seed(u_long s) const; 128 128 129 129 /// … … 168 168 /// @return const pointer to underlying GSL random generator. 169 169 /// 170 inline const gsl_rng* rng(void) const { return rng_; } 171 170 const gsl_rng* rng(void) const; 172 171 173 172 private: … … 209 208 /// @see seed_from_devurandom, RNG::seed_from_devurandom, RNG::seed 210 209 /// 211 inline void seed(u_long s) const { rng_>seed(s); }210 void seed(u_long s) const; 212 211 213 212 /// … … 256 255 /// @return A random number. 257 256 /// 258 inline u_long 259 operator()(void) const { return gsl_ran_discrete(rng_>rng(), gen_); } 257 u_long operator()(void) const; 260 258 261 259 private: … … 281 279 /// @brief Default constructor. 282 280 /// 283 DiscreteUniform(void) : range_(rng_>max()) {}281 DiscreteUniform(void); 284 282 285 283 /// … … 296 294 /// functionality will not return). 297 295 /// 298 DiscreteUniform(const u_long n) : range_(n) 299 { if ( range_>rng_>max() ) range_=rng_>max(); } 296 DiscreteUniform(const u_long n); 300 297 301 298 /// … … 304 301 /// likely. n is set in constructor. 305 302 /// 306 inline u_long 307 operator()(void) const { return gsl_rng_uniform_int(rng_>rng(), range_); } 303 u_long operator()(void) const; 308 304 309 305 /// … … 312 308 /// likely. 313 309 /// 314 inline u_long operator()(const u_long n) const 315 { return gsl_rng_uniform_int(rng_>rng(), n); } 310 u_long operator()(const u_long n) const; 316 311 317 312 private: … … 347 342 /// @return A Poisson distributed number. 348 343 /// 349 inline u_long 350 operator()(void) const { return gsl_ran_poisson(rng_>rng(), m_); } 351 352 /// 353 /// @return A Poisson distributed number with expectation value \a 354 /// m 344 u_long operator()(void) const; 345 346 /// 347 /// @return A Poisson distributed number with expectation value 348 /// \a m 355 349 /// 356 350 /// @note this operator ignores parameters set in Constructor 357 351 /// 358 inline u_long 359 operator()(const double m) const { return gsl_ran_poisson(rng_>rng(), m); } 352 u_long operator()(const double m) const; 360 353 361 354 private: … … 393 386 /// @see seed_from_devurandom, RNG::seed_from_devurandom, RNG::seed 394 387 /// 395 inline void seed(u_long s) const { rng_>seed(s); }388 void seed(u_long s) const; 396 389 397 390 /// … … 414 407 }; 415 408 409 // ContinuousUniform is declared before ContinuousGeneral to avoid 410 // forward declaration 416 411 /// 417 412 /// @brief Uniform distribution … … 427 422 { 428 423 public: 429 inline double operator()(void) const { return gsl_rng_uniform(rng_>rng());}424 double operator()(void) const; 430 425 }; 431 426 … … 451 446 /// @return A random number. 452 447 /// 453 inline double operator()(void) const 454 { return hist_.observation_value(discrete_())+(u_()0.5)*hist_.spacing(); } 448 double operator()(void) const; 455 449 456 450 private: … … 476 470 /// @param m is the expectation value of the distribution. 477 471 /// 478 inlineExponential(const double m=1);472 Exponential(const double m=1); 479 473 480 474 /// 481 475 /// @return A random number from exponential distribution. 482 476 /// 483 inline double 484 operator()(void) const { return gsl_ran_exponential(rng_>rng(), m_); } 477 double operator()(void) const; 485 478 486 479 /// … … 490 483 /// @note This operator ignores parameters given in constructor. 491 484 /// 492 inline double operator()(const double m) const 493 { return gsl_ran_exponential(rng_>rng(), m); } 485 double operator()(const double m) const; 494 486 495 487 private: … … 524 516 /// @return A random Gaussian number 525 517 /// 526 inline double 527 operator()(void) const { return gsl_ran_gaussian(rng_>rng(), s_)+m_; } 518 double operator()(void) const; 528 519 529 520 /// … … 533 524 /// @note this operator ignores parameters given in Constructor 534 525 /// 535 inline double 536 operator()(const double s) const { return gsl_ran_gaussian(rng_>rng(), s); } 526 double operator()(const double s) const; 537 527 538 528 /// … … 542 532 /// @note this operator ignores parameters given in Constructor 543 533 /// 544 inline double operator()(const double s, const double m) const 545 { return gsl_ran_gaussian(rng_>rng(), s)+m; } 534 double operator()(const double s, const double m) const; 546 535 547 536 private:
Note: See TracChangeset
for help on using the changeset viewer.