56 std::vector<float>
mu;
102 Ranq1(
unsigned long long j) :
v(4101842887655102017LL) {
115 return v * 2685821657736338717LL;
123 return 5.42101086242752217E-20 *
int64();
131 return (
float)
doub();
139 return (
unsigned int)
int64();
168 for(
int k = 0; k < 55; k++) {
183 if(
dd < 0 )
dd += 1.0;
193 return (
float)
doub();
214 inline float dev(
double mu,
double sigma) {
220 v = 1.7156 * (
fl() - 0.5 );
222 y = abs(v) + 0.386595;
223 q = x * x + y * ( 0.19600 * y - 0.25472 * x );
224 }
while ( q > 0.27597 && ( q > 0.27846 || v * v > -4.0 * log(u) * u * u ) );
226 return mu + sigma * v / u;
238 inline float dev(
double mu,
double sigma,
float max) {
243 result =
dev(mu, sigma);
244 }
while ( result > max );
258 inline float dev(
double mu,
double sigma,
float min,
float max) {
263 result =
dev(mu, sigma);
264 }
while ( result > max || result < min );
288 inline float dev(
double mu,
double sigma) {
295 v = 1.7156 * (
fl() - 0.5 );
297 y = abs(v) + 0.386595;
298 q = x * x + y * ( 0.19600 * y - 0.25472 * x );
299 }
while ( q > 0.27597 && ( q > 0.27846 || v * v > -4.0 * log(u) * u * u ) );
301 return exp(mu + sigma * v / u);
313 inline float dev(
double mu,
double sigma,
float max) {
318 result =
dev(mu, sigma);
319 }
while ( result > max );
333 inline float dev(
double mu,
double sigma,
float min,
float max) {
338 result =
dev(mu, sigma);
339 }
while ( result > max || result < min );
361 inline float dev(std::vector<float> mu, std::vector<float> sigma, std::vector<float> p) {
371 while( prop_cum < a_p ) {
373 prop_cum = prop_cum + p[comp];
379 v = 1.7156 * (
fl() - 0.5 );
381 y = abs(v) + 0.386595;
382 q = x * x + y * ( 0.19600 * y - 0.25472 * x );
383 }
while ( q > 0.27597 && ( q > 0.27846 || v * v > -4.0 * log(u) * u * u ) );
385 return (mu[comp] + sigma[comp] * v / u);
398 inline float dev( std::vector<float> mu, std::vector<float> sigma, std::vector<float> p,
float max) {
403 result =
dev(mu, sigma, p);
404 std::cout <<
"TEST MIXTURE NORM " << result << std::endl;
405 }
while ( result > max );
420 inline float dev( std::vector<float> mu, std::vector<float> sigma, std::vector<float> p,
float min,
float max) {
425 result =
dev(mu, sigma, p);
427 }
while ( result > max || result < min );
448 inline float dev(std::vector<float> mu, std::vector<float> sigma, std::vector<float> p) {
458 while( prop_cum < a_p ) {
460 prop_cum = prop_cum + p[comp];
466 v = 1.7156 * (
fl() - 0.5 );
468 y = abs(v) + 0.386595;
469 q = x * x + y * ( 0.19600 * y - 0.25472 * x );
470 }
while ( q > 0.27597 && ( q > 0.27846 || v * v > -4.0 * log(u) * u * u ) );
472 return exp(mu[comp] + sigma[comp] * v / u);
485 inline float dev( std::vector<float> mu, std::vector<float> sigma, std::vector<float> p,
float max) {
490 result =
dev(mu, sigma, p);
491 }
while ( result > max );
506 inline float dev( std::vector<float> mu, std::vector<float> sigma, std::vector<float> p,
float min,
float max) {
511 result =
dev(mu, sigma, p);
512 }
while ( result > max || result < min );
536 prop_cum = distrib.
p[comp];
537 while( prop_cum < a_p ) {
539 prop_cum = prop_cum + distrib.
p[comp];
551 }
while (result.
x1 > distrib.
max[0] || result.
x2 > distrib.
max[1] );
560 template <
typename T>
589 std::cerr <<
"No instance already created!" << std::endl;
609 template <
typename T>
649 if( freq.size() < 1 )
throw std::logic_error(
"draw_discrete: empty vector!" );
661 for( i = 0; i < N; i++ ) {
669 cumfreq[i]=cumfreq[i]/icum;
675 cumfreq[i]=(i+1.0)/(N+1.0);
687 for ( i = 0; i < N; i++ ) {
688 if ( (low <= draw) && (draw <= cumfreq[i]) ) {
694 std::cerr <<
"Could not find a class identifier!" << std::endl;
708 template <
typename T>
int draw_discrete( std::vector<T> freq,
int lo_bound,
int up_bound ) {
710 int N = ( up_bound - lo_bound ) + 1;
721 for( i = lo_bound; i <= up_bound; i++ ) {
729 for(i = 0; i < N; i++ ) {
730 cumfreq[i]=cumfreq[i]/icum;
735 std::cout <<
"Error: trivial distribution" << std::endl;
736 for( i = 0; i < N; i++ ) {
737 cumfreq[i]=(i+1)/(N+1);
749 for ( i = 0; i < N; i++ ) {
750 if ( (low <= draw) && (draw <= cumfreq[i]) ) {
756 std::cerr <<
"Could not find a class identifier!" << std::endl;
772 float norm_rand(
float mu,
float sigma );
783 float norm_rand(
float mu,
float sigma,
float max );
792 float log_rand(
float mu,
float sigma );
802 float log_rand(
float mu,
float sigma,
float max );
Simplest and fastest random number generator recommended by Numerical Recipes.
Definition: Random.hpp:94
float dev(std::vector< float > mu, std::vector< float > sigma, std::vector< float > p, float max)
Returns a draw from the mixture distribution.
Definition: Random.hpp:398
RandomGenerators(unsigned long long i)
Constructor, initialize every random number generators.
Definition: Random.hpp:634
float x2
second component
Definition: Random.hpp:28
float dev(std::vector< float > mu, std::vector< float > sigma, std::vector< float > p, float min, float max)
Returns a draw from the mixture distribution.
Definition: Random.hpp:420
Definition: Random.hpp:83
float dev(std::vector< float > mu, std::vector< float > sigma, std::vector< float > p, float max)
Returns a draw from the mixture distribution.
Definition: Random.hpp:485
draw_2d(float aX1, float aX2)
Constructor.
Definition: Random.hpp:31
double doub()
Returns random double-precision floating point value in [0,1].
Definition: Random.hpp:178
SingletonRnd class for the RandomGenerators class.
Definition: Random.hpp:561
LogNormaldev lognorm_dev
log-normal random draws
Definition: Random.hpp:625
static T * getInstance()
Return the instance of SingletonRnd if already generated.
Definition: Random.hpp:587
double doub()
Generates a double.
Definition: Random.hpp:122
Ranq1 unif
uniform random draws
Definition: Random.hpp:622
draw_2d dev(dist_param_mixture_2d distrib)
Returns 2 draws from a bounded mixture distribution.
Definition: Random.hpp:527
SingletonRnd()
Constructor.
Definition: Random.hpp:566
float mu[2]
mean of the distribution
Definition: Random.hpp:71
Ranfib fast_unif
fast uniform random draws
Definition: Random.hpp:623
static void makeInstance(unsigned long long i)
Create a singleton instance of a T object.
Definition: Random.hpp:577
MixtureLogNormal2D(unsigned long long i)
Constructor.
Definition: Random.hpp:524
Normaldev norm_dev
normal random draws
Definition: Random.hpp:624
float sigma[3]
covariance matrix or its choleski decomposition
Definition: Random.hpp:72
int inext
part of the generator state
Definition: Random.hpp:154
int draw_discrete(std::vector< T > freq)
Randomly draws a class identifier within an empirical density function.
Definition: Random.hpp:647
float min[2]
vector of lower bounds
Definition: Random.hpp:86
MixtureLogNormal mixt_lognorm_dev
mixture of univariate log-normal random draws
Definition: Random.hpp:627
float max
upper bound of the distribution
Definition: Random.hpp:45
float dev(double mu, double sigma)
Returns a normal random draw with mean mu and standart deviation sigma.
Definition: Random.hpp:214
Ranfib(unsigned long j)
Constructor.
Definition: Random.hpp:161
float dev(double mu, double sigma, float max)
Returns a upper bounded normal random draw.
Definition: Random.hpp:238
float x1
first component
Definition: Random.hpp:27
MixtureLogNormal2D mixt_lognorm_dev_2d
mixture of bivariate log-normal random draws
Definition: Random.hpp:628
float dev(double mu, double sigma)
Returns a Log-normal random draw.
Definition: Random.hpp:288
float dev(std::vector< float > mu, std::vector< float > sigma, std::vector< float > p, float min, float max)
Returns a draw from the mixture distribution.
Definition: Random.hpp:506
unsigned int int32()
Generates an unsigned 32 bits integer.
Definition: Random.hpp:138
float mu
mean of the distribution
Definition: Random.hpp:43
Fast and good random number generator (see Numerical Recipes).
Definition: Random.hpp:150
float fl()
Generates a float.
Definition: Random.hpp:130
float norm_rand(float mu, float sigma)
Random number generator following a normal distribution (DEPRECIATED)
Definition: Random.cpp:14
float dev(double mu, double sigma, float min, float max)
Returns a bounded Log-normal random draw.
Definition: Random.hpp:333
float max
upper bound of the distribution
Definition: Random.hpp:59
Fast Random number generator for log-normal distribution (Numerical Recipes).
Definition: Random.hpp:273
MixtureLogNormal(unsigned long long i)
Constructor.
Definition: Random.hpp:438
Definition: Random.hpp:55
Fast Random number generator for normal distribution (Numerical Recipes).
Definition: Random.hpp:199
unsigned long long v
state of the random number generator
Definition: Random.hpp:96
Fast Random number generator for mixture of bivariate log-normal distribution (Numerical Recipes)...
Definition: Random.hpp:521
double dd
part of the generator state
Definition: Random.hpp:153
float fl()
Returns random simple-precision floating point value in [0,1].
Definition: Random.hpp:192
Definition: Random.hpp:70
std::vector< float > p
mixing proportions of each components
Definition: Random.hpp:85
Random generators.
Definition: Random.hpp:616
static T * _singleton
unique instance of the RandomGenerators class
Definition: Random.hpp:604
MixtureNormal mixt_norm_dev
mixture of univariate normal random draws
Definition: Random.hpp:626
LogNormaldev(unsigned long long i)
Constructor.
Definition: Random.hpp:279
std::vector< float > p
proportions of each components
Definition: Random.hpp:58
float dev(std::vector< float > mu, std::vector< float > sigma, std::vector< float > p)
Returns a draw from the mixture distribution.
Definition: Random.hpp:448
unsigned long long int64()
Generates an unsigned 64 bits integer.
Definition: Random.hpp:111
Definition: Random.hpp:25
virtual ~RandomGenerators()
Destructor.
Definition: Random.hpp:638
std::vector< dist_param_2d > components
vector storing the mixture's components
Definition: Random.hpp:84
~SingletonRnd()
Destructor.
Definition: Random.hpp:569
std::vector< float > sigma
vector storing the standard error of each component
Definition: Random.hpp:57
int inextp
part of the generator state
Definition: Random.hpp:155
float dev(double mu, double sigma, float max)
Returns a bounded Log-normal random draw.
Definition: Random.hpp:313
float dev(double mu, double sigma, float min, float max)
Returns a bounded normal random draw.
Definition: Random.hpp:258
Normaldev(unsigned long long i)
Constructor.
Definition: Random.hpp:205
std::vector< float > mu
vector storing the mean of each component
Definition: Random.hpp:56
float sigma
standard error of the distribution
Definition: Random.hpp:44
float log_rand(float mu, float sigma)
Random number generator following a log-normal distribution (DEPRECIATED)
Definition: Random.cpp:43
Fast Random number generator for mixture of log-normal distribution (Numerical Recipes).
Definition: Random.hpp:435
Fast Random number generator for mixture of normal distribution (Numerical Recipes).
Definition: Random.hpp:348
Ranq1(unsigned long long j)
Constructor j is the seed.
Definition: Random.hpp:102
static void kill()
Killing the instance and freeing memory.
Definition: Random.hpp:595
Definition: Random.hpp:42
double dtab[55]
part of the generator state
Definition: Random.hpp:152
float max[2]
vector of upper bounds
Definition: Random.hpp:87
MixtureNormal(unsigned long long i)
Constructor.
Definition: Random.hpp:351
float dev(std::vector< float > mu, std::vector< float > sigma, std::vector< float > p)
Returns a draw from the mixture distribution.
Definition: Random.hpp:361
float min
lower bound of the distribution
Definition: Random.hpp:60