34 #include <itpp/itexports.h>
141 ITPP_EXPORT
void RNG_reset(
unsigned int seed);
273 it_assert(prob >= 0.0 && prob <= 1.0,
"The Bernoulli source probability "
274 "must be between 0 and 1");
282 bvec
operator()(
int n) { bvec temp(n); sample_vector(n, temp);
return temp; }
286 bin sample() {
return RNG.genrand_close_open() < p ?
bin(1) : bin(0); }
289 out.set_size(size,
false);
290 for(
int i = 0; i <
size; i++) out(i) = sample();
294 out.set_size(rows, cols,
false);
295 for(
int i = 0; i < rows * cols; i++) out(i) = sample();
328 void setup(
int min,
int max);
330 void get_setup(
int &min,
int &max)
const;
334 ivec operator()(
int n);
336 imat operator()(
int h,
int w);
339 return floor_i(RNG.genrand_close_open() * (hi - lo + 1)) + lo;
360 void setup(
double min,
double max);
362 void get_setup(
double &min,
double &max)
const;
364 double operator()() {
return (sample() * (hi_bound - lo_bound) + lo_bound); }
368 sample_vector(n, temp);
369 temp *= hi_bound - lo_bound;
376 sample_matrix(h, w, temp);
377 temp *= hi_bound - lo_bound;
382 double sample() {
return RNG.genrand_close_open(); }
385 out.set_size(size,
false);
386 for(
int i = 0; i <
size; i++) out(i) = sample();
390 out.set_size(rows, cols,
false);
391 for(
int i = 0; i < rows * cols; i++) out(i) = sample();
396 double lo_bound, hi_bound;
411 void setup(
double lambda) { l = lambda; }
413 double get_setup()
const;
417 vec operator()(
int n);
419 mat operator()(
int h,
int w);
421 double sample() {
return (-
std::log(RNG.genrand_open_close()) / l); }
423 Random_Generator RNG;
445 mean(meanval), sigma(std::
sqrt(variance)) {}
452 void get_setup(
double &meanval,
double &
variance)
const;
458 sample_vector(n, temp);
466 sample_matrix(h, w, temp);
476 out.set_size(size,
false);
477 for(
int i = 0; i <
size; i++) out(i) = sample();
482 out.set_size(rows, cols,
false);
483 for(
int i = 0; i < rows * cols; i++) out(i) = sample();
487 static const double ytab[128];
488 static const unsigned int ktab[128];
489 static const double wtab[128];
490 static const double PARAM_R;
514 Gamma_RNG(
double a = 1.0,
double b = 1.0): alpha(a), beta(b) {init_state();}
516 void setup(
double a,
double b) { alpha = a; beta = b; }
520 vec operator()(
int n);
522 mat operator()(
int r,
int c);
537 double _s, _s2, _d, _scale;
538 double _q0, _b, _si, _c;
551 void setup(
double meanval,
double variance);
553 void get_setup(
double &meanval,
double &variance)
const;
557 vec operator()(
int n);
559 mat operator()(
int h,
int w);
562 double u = RNG.genrand_open_open();
563 double l = sqrt_12var;
571 double mean, var, sqrt_12var;
584 norm_factor(1.0 / std::
sqrt(2.0)) {
585 setup(mean, variance);
597 mean = std::complex<double>(m_re, m_im);
598 variance = sigma * sigma;
601 std::complex<double>
operator()() {
return sigma * sample() + std::complex<double>(m_re, m_im); }
605 sample_vector(n, temp);
607 temp += std::complex<double>(m_re, m_im);
613 sample_matrix(h, w, temp);
615 temp += std::complex<double>(m_re, m_im);
620 double a = nRNG.sample() * norm_factor;
621 double b = nRNG.sample() * norm_factor;
622 return std::complex<double>(a, b);
627 out.set_size(size,
false);
628 for(
int i = 0; i <
size; i++) out(i) = sample();
633 out.set_size(rows, cols,
false);
634 for(
int i = 0; i < rows * cols; i++) out(i) = sample();
644 const double norm_factor;
659 void setup(
double meanval,
double variance,
double rho);
661 void get_setup(
double &meanval,
double &variance,
double &rho)
const;
667 vec operator()(
int n);
669 mat operator()(
int h,
int w);
674 r1 =
m_2pi * RNG.genrand_open_close();
684 double mem, r, factr,
mean, var, r1, r2;
686 Random_Generator RNG;
709 Weibull_RNG(
double lambda = 1.0,
double beta = 1.0);
711 void setup(
double lambda,
double beta);
713 void get_setup(
double &lambda,
double &beta) { lambda = l; beta = b; }
717 vec operator()(
int n);
719 mat operator()(
int h,
int w);
726 Random_Generator RNG;
739 void setup(
double sigma) { sig = sigma; }
745 vec operator()(
int n);
747 mat operator()(
int h,
int w);
750 double s1 = nRNG.sample();
751 double s2 = nRNG.sample();
753 return (sig *
std::sqrt(s1 * s1 + s2 * s2));
767 Rice_RNG(
double sigma = 1.0,
double v = 1.0);
769 void setup(
double sigma,
double v) { sig = sigma; s = v; }
771 void get_setup(
double &sigma,
double &v) { sigma = sig; v = s; }
775 vec operator()(
int n);
777 mat operator()(
int h,
int w);
780 double s1 = nRNG.sample() + s;
781 double s2 = nRNG.sample();
783 return (sig *
std::sqrt(s1 * s1 + s2 * s2));
812 inline mat
randu(
int rows,
int cols) { mat temp;
randu(rows, cols, temp);
return temp; }
839 inline mat
randn(
int rows,
int cols) { mat temp;
randn(rows, cols, temp);
return temp; }
853 inline cmat
randn_c(
int rows,
int cols) { cmat temp;
randn_c(rows, cols, temp);
return temp; }
859 #endif // #ifndef RANDOM_H