34 #include <itpp/itexports.h> 140 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; }
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;
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)) {
597 mean = std::complex<double>(m_re, m_im);
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 bin sample()
Get a sample.
cvec operator()(int n)
Get a sample vector.
void sample_vector(int size, vec &out)
Get a Normal distributed (0,1) vector.
bmat operator()(int h, int w)
Get a sample matrix.
unsigned int GlobalRNG_get_local_seed()
Get new seed to initialize thread-local generators.
double random_01_lclosed()
Return a uniformly distributed [0,1) value.
const double m_2pi
Constant 2*Pi.
double sample()
Returns a single sample.
vec randray(int size, double sigma=1.0)
Generates a random Rayleigh vector.
cmat operator()(int h, int w)
Get a sample matrix.
double randu(void)
Generates a random uniform (0,1) number.
int randi(int low, int high)
Generates a random integer in the interval [low,high].
Normal distributionNormal (Gaussian) random variables, using a simplified Ziggurat method...
void GlobalRNG_set_state(const ivec &state)
Resume the global seed provider state saved in memory.
std::complex< double > operator()()
Get one sample.
uint32_t random_int()
Return a uniformly distributed [0, UINT_MAX) value.
Normal_RNG Gauss_RNG
Gauss_RNG is the same as Normal Source.
vec randexp(int size, double lambda=1.0)
Generates a random complex Gaussian vector.
void setup(double lambda)
Set lambda.
double randn(void)
Generates a random Gaussian (0,1) variable.
Normal_RNG(double meanval, double variance)
Constructor. Set mean and variance.
vec operator()(int n)
Get a sample vector.
double operator()()
Get one sample.
Normal_RNG()
Constructor. Set mean and variance.
double genrand_open_open()
Generate uniform (0, 1) double pseudorandom number.
Gamma distributionGenerate samples from Gamma(alpha,beta) density, according to the following equatio...
Filtered normal distribution.
double genrand_open_close()
Generate uniform (0, 1] double pseudorandom number.
void get_setup(std::complex< double > &mean, double &variance)
Get mean and variance.
void get_setup(double &sigma, double &v)
Get parameters.
double get_setup() const
return the probability
double operator()()
Get one sample.
double sample()
Get a Normal distributed (0,1) sample.
Random_Generator()
Default constructor.
#define it_assert(t, s)
Abort if t is not true.
void sample_matrix(int rows, int cols, cmat &out)
Get a Complex Normal (0,1) distributed matrix.
std::complex< double > sample()
Get a Complex Normal (0,1) distributed sample.
void GlobalRNG_reset(unsigned int seed)
Set the internal seed of the Global Seed Provider.
void setup(std::complex< double > mean, double variance)
Set mean and variance.
AR1_Normal_RNG AR1_Gauss_RNG
AR1_Gauss_RNG is the same as AR1_Normal_RNG.
C++ implementation of dSFMT random number generator.
double operator()()
Get one sample.
double mean(const vec &v)
The mean value.
vec sin(const vec &x)
Sine function.
vec log(const vec &x)
The natural logarithm of the elements.
double variance(const cvec &v)
The variance of the elements in the vector. Normalized with N-1 to be unbiased.
Complex_Normal_RNG & operator=(const Complex_Normal_RNG &)
Dummy assignment operator - MSVC++ warning C4512.
T min(const Vec< T > &in)
Minimum value of vector.
Complex_Normal_RNG(std::complex< double > mean, double variance)
Constructor. Set mean and variance.
Bernoulli_RNG(double prob)
Binary source with probability prob for a 1.
double operator()()
Get one sample.
double get_setup()
Get sigma.
uint32_t genrand_uint32()
Generate uniform [0, UINT_MAX) integer pseudorandom number.
void RNG_randomize()
Set a random seed for all Random Number Generators in the current thread.
T max(const Vec< T > &v)
Maximum value of vector.
C++ implementation of dSFMT random number generator.
void lc_mark_initialized()
Function to mark thread-local context as initialized.
void RNG_reset(unsigned int seed)
Set the seed for all Random Number Generators in the current thread.
double operator()()
Get one sample.
Base class for random (stochastic) sources.
vec pow(const double x, const vec &y)
Calculates x to the power of y (x^y)
int size(const Vec< T > &v)
Length of vector.
double operator()()
Get one sample.
Complex_Normal_RNG()
Default constructor.
mat operator()(int h, int w)
Get a sample matrix.
Definitions of operators for vectors and matricies of different types.
bin randb(void)
Generates a random bit (equally likely 0s and 1s)
int floor_i(double x)
The nearest smaller integer.
Exponential distribution.
void RNG_set_state(const ivec &state)
Resume Random Number generation in the current thread with previously stored context.
void setup(double a, double b)
Set alpha and beta.
bool lc_is_initialized()
Function to check if thread-local context is initialized.
bin operator()()
Get one sample.
void GlobalRNG_get_state(ivec &state)
Save current full state of global seed provider in memory.
ActiveDSFMT::Context & lc_get()
Function to access thread-local context for random numbers generation.
double operator()()
Get one sample.
void sample_vector(int size, cvec &out)
Get a Complex Normal (0,1) distributed vector.
void sample_vector(int size, bvec &out)
Get a sample vector.
void GlobalRNG_randomize()
Set a random seed for the Global Seed Provider seed.
Binary arithmetic (boolean) class.
void RNG_get_state(ivec &state)
Save Random Number generation context used in the current thread.
void sample_matrix(int rows, int cols, bmat &out)
Get a sample matrix.
double genrand_close_open()
Generate uniform [0, 1) double pseudorandom number.
Gamma_RNG(double a=1.0, double b=1.0)
Constructor, which sets alpha (a) and beta (b)
vec sqrt(const vec &x)
Square root of the elements.
void setup(double sigma, double v)
Set sigma, and v (if v = 0, Rice -> Rayleigh).
void setup(double meanval, double variance)
Set mean, and variance.
void sample_matrix(int rows, int cols, mat &out)
Get a Normal distributed (0,1) matrix.
bvec operator()(int n)
Get a sample vector.
void get_setup(double &lambda, double &beta)
Get lambda and beta.
double random_01_rclosed()
Return a uniformly distributed (0,1] value.
void setup(double sigma)
Set sigma.
double genrand_close1_open2()
Generate uniform [1, 2) double pseudorandom number.
vec cos(const vec &x)
Cosine function.
double random_01()
Return a uniformly distributed (0,1) value.
Bernoulli_RNG()
Binary source with probability prob for a 1.
double operator()()
Get a single random sample.
vec randrice(int size, double sigma=1.0, double s=1.0)
Generates a random Rice vector (See J.G. Poakis, "Digital Communications, 3rd ed." p...
Mat< bin > bmat
bin matrix
std::complex< double > randn_c(void)
Generates a random complex Gaussian (0,1) variable.
void setup(double prob)
set the probability