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

 1 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
Note: See TracChangeset
for help on using the changeset viewer.