34#include <itpp/itexports.h>
141ITPP_EXPORT
void RNG_reset(
unsigned int seed);
274 "must be between 0 and 1");
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;
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(); }
391 for(
int i = 0;
i < rows * cols;
i++)
out(
i) = sample();
396 double lo_bound, hi_bound;
421 double sample() {
return (-std::log(RNG.genrand_open_close()) / l); }
423 Random_Generator RNG;
458 sample_vector(n,
temp);
466 sample_matrix(
h, w,
temp);
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; }
537 double _s, _s2, _d, _scale;
538 double _q0, _b, _si, _c;
562 double u = RNG.genrand_open_open();
563 double l = sqrt_12var;
565 l *= std::log(2.0 * u);
567 l *= -std::log(2.0 * (1 - u));
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);
634 for(
int i = 0;
i < rows * cols;
i++)
out(
i) = sample();
644 const double norm_factor;
674 r1 =
m_2pi * RNG.genrand_open_close();
675 r2 = std::sqrt(factr * std::log(RNG.genrand_open_close()));
676 mem += r2 * std::cos(r1);
679 mem += r2 * std::sin(r1);
684 double mem, r, factr,
mean, var, r1, r2;
686 Random_Generator RNG;
711 void setup(
double lambda,
double beta);
722 return (std::pow(-std::log(RNG.genrand_open_close()), 1.0 / b) / l);
726 Random_Generator RNG;
739 void setup(
double sigma) { sig = sigma; }
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; }
780 double s1 = nRNG.sample() + s;
781 double s2 = nRNG.sample();
783 return (sig * std::sqrt(
s1 *
s1 +
s2 *
s2));
Filtered normal distribution.
double operator()()
Get a single random sample.
int size() const
Returns the number of data elements in the array object.
T & operator()(int i)
Get the i element.
void set_size(int n, bool copy=false)
Resizing an Array<T>.
double get_setup() const
return the probability
bmat operator()(int h, int w)
Get a sample matrix.
Bernoulli_RNG()
Binary source with probability prob for a 1.
bin sample()
Get a sample.
void setup(double prob)
set the probability
void sample_vector(int size, bvec &out)
Get a sample vector.
bvec operator()(int n)
Get a sample vector.
void sample_matrix(int rows, int cols, bmat &out)
Get a sample matrix.
bin operator()()
Get one sample.
Bernoulli_RNG(double prob)
Binary source with probability prob for a 1.
void get_setup(std::complex< double > &mean, double &variance)
Get mean and variance.
std::complex< double > sample()
Get a Complex Normal (0,1) distributed sample.
Complex_Normal_RNG(std::complex< double > mean, double variance)
Constructor. Set mean and variance.
std::complex< double > operator()()
Get one sample.
Complex_Normal_RNG & operator=(const Complex_Normal_RNG &)
Dummy assignment operator - MSVC++ warning C4512.
void setup(std::complex< double > mean, double variance)
Set mean and variance.
void sample_vector(int size, cvec &out)
Get a Complex Normal (0,1) distributed vector.
cmat operator()(int h, int w)
Get a sample matrix.
void sample_matrix(int rows, int cols, cmat &out)
Get a Complex Normal (0,1) distributed matrix.
cvec operator()(int n)
Get a sample vector.
Complex_Normal_RNG()
Default constructor.
Exponential distribution.
double operator()()
Get one sample.
double get_setup() const
get lambda
void setup(double lambda)
Set lambda.
double operator()()
Get one sample.
void setup(double a, double b)
Set alpha and beta.
Gamma_RNG(double a=1.0, double b=1.0)
Constructor, which sets alpha (a) and beta (b)
double operator()()
Get one sample.
double sample()
Returns a single sample.
void sample_vector(int size, vec &out)
Get a Normal distributed (0,1) vector.
mat operator()(int h, int w)
Get a sample matrix.
void sample_matrix(int rows, int cols, mat &out)
Get a Normal distributed (0,1) matrix.
vec operator()(int n)
Get a sample vector.
double operator()()
Get one sample.
void setup(double meanval, double variance)
Set mean, and variance.
Normal_RNG()
Constructor. Set mean and variance.
Normal_RNG(double meanval, double variance)
Constructor. Set mean and variance.
Base class for random (stochastic) sources.
double genrand_open_open()
Generate uniform (0, 1) double pseudorandom number.
double genrand_close_open()
Generate uniform [0, 1) double pseudorandom number.
double random_01_lclosed()
Return a uniformly distributed [0,1) value.
uint32_t genrand_uint32()
Generate uniform [0, UINT_MAX) integer pseudorandom number.
double genrand_close1_open2()
Generate uniform [1, 2) double pseudorandom number.
double random_01()
Return a uniformly distributed (0,1) value.
uint32_t random_int()
Return a uniformly distributed [0, UINT_MAX) value.
Random_Generator()
Default constructor.
double genrand_open_close()
Generate uniform (0, 1] double pseudorandom number.
double random_01_rclosed()
Return a uniformly distributed (0,1] value.
double get_setup()
Get sigma.
double operator()()
Get one sample.
void setup(double sigma)
Set sigma.
double operator()()
Get one sample.
void get_setup(double &sigma, double &v)
Get parameters.
void setup(double sigma, double v)
Set sigma, and v (if v = 0, Rice -> Rayleigh).
double operator()()
Get one sample.
void get_setup(double &lambda, double &beta)
Get lambda and beta.
Binary arithmetic (boolean) class.
C++ implementation of dSFMT random number generator.
#define it_assert(t, s)
Abort if t is not true.
int size(const Vec< T > &v)
Length of vector.
T min(const Vec< T > &in)
Minimum value of vector.
T max(const Vec< T > &v)
Maximum value of vector.
vec sqrt(const vec &x)
Square root of the elements.
void RNG_randomize()
Set a random seed for all Random Number Generators in the current thread.
void lc_mark_initialized()
Function to mark thread-local context as initialized.
void GlobalRNG_get_state(ivec &state)
Save current full state of global seed provider in memory.
Normal_RNG Gauss_RNG
Gauss_RNG is the same as Normal Source.
void RNG_set_state(const ivec &state)
Resume Random Number generation in the current thread with previously stored context.
double randu(void)
Generates a random uniform (0,1) number.
vec randexp(int size, double lambda=1.0)
Generates a random complex Gaussian vector.
unsigned int GlobalRNG_get_local_seed()
Get new seed to initialize thread-local generators.
vec randray(int size, double sigma=1.0)
Generates a random Rayleigh vector.
std::complex< double > randn_c(void)
Generates a random complex Gaussian (0,1) variable.
void RNG_reset()
Reset the seed to the previously set value for all Random Number Generators in the current thread.
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....
bin randb(void)
Generates a random bit (equally likely 0s and 1s)
bool lc_is_initialized()
Function to check if thread-local context is initialized.
int randi(int low, int high)
Generates a random integer in the interval [low,high].
void GlobalRNG_reset()
Reset the internal seed of the Global Seed Provider to the previously set value.
double randn(void)
Generates a random Gaussian (0,1) variable.
void RNG_get_state(ivec &state)
Save Random Number generation context used in the current thread.
void GlobalRNG_randomize()
Set a random seed for the Global Seed Provider seed.
AR1_Normal_RNG AR1_Gauss_RNG
AR1_Gauss_RNG is the same as AR1_Normal_RNG.
void GlobalRNG_set_state(const ivec &state)
Resume the global seed provider state saved in memory.
double variance(const cvec &v)
The variance of the elements in the vector. Normalized with N-1 to be unbiased.
double mean(const vec &v)
The mean value.
Mat< bin > bmat
bin matrix
const double m_2pi
Constant 2*Pi.
int floor_i(double x)
The nearest smaller integer.
Definitions of operators for vectors and matricies of different types.
C++ implementation of dSFMT random number generator.