Nemo  2.4.0b
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
Uniform.h
Go to the documentation of this file.
1 
27 #ifndef __UNIFORM_H
28 #define __UNIFORM_H
29 #include <cmath>
30 #include <limits.h>
31 #include <assert.h>
32 #include <valarray>
33 #include "output.h"
34 #include <iostream>
35 #include "MPImanager.h"
36 
37 #ifdef HAS_SPRNG
38 // #define SIMPLE_SPRNG
39  #include <sprng_cpp.h>
40 #endif
41 
42 #ifdef HAS_GSL
43  #include <gsl/gsl_rng.h>
44  #include <gsl/gsl_randist.h>
45  #include <gsl/gsl_blas.h>
46  #include <gsl/gsl_math.h>
47  #include <gsl/gsl_vector.h>
48  #include <gsl/gsl_matrix.h>
49  #include <gsl/gsl_permutation.h>
50 #endif
51 
52 extern MPIenv *_myenv;
53 
55 class RAND {
56 private:
57 
58  RAND();
59 
60 public:
61 
62 #if defined(HAS_SPRNG)
63 
64  static Sprng *stream;
65 
66 #elif defined(HAS_GSL)
67 
68  static gsl_rng * r;
69 
70  static void init_gsl(const gsl_rng_type* T, unsigned long seed)
71  {
72  r = gsl_rng_alloc (T);
73  gsl_rng_set(r,seed);
74  }
75 
76 #else
77 
78  static long Seed1,Seed2;
79 
80 #endif
82  static void init (unsigned long seed) {
83 
84 #if defined(HAS_SPRNG)
85  // initializing the SPRNG stream with default param and LFG (0) generator
86 
87  stream = SelectType(4); //MLFG Modified Lagged Fibonacci
88 
89  stream->init_sprng( _myenv->workerRank(), _myenv->workerCount()+1, seed, SPRNG_DEFAULT );
90 
91 
92 #ifdef DEBUG_MPI
93  message("--- initialized the SPRNG random generator on rank %i\n", _myenv->workerRank());
94 
95  stream->print_sprng();
96 
97  message("--- process %i random number: %.14f\n", _myenv->workerRank(), stream->sprng());
98 #endif
99 
100 #elif defined(HAS_GSL)
101 
102  init_gsl( gsl_rng_mt19937, seed );
103 
104 #else
105 
106  Seed1 = seed;
107 
108 #endif
109  }
111  static void free()
112  {
113 
114 #if defined(HAS_SPRNG)
115  // do nothing with pointer?
116 #elif defined(HAS_GSL)
117  gsl_rng_free(r);
118 #endif
119 
120  }
121 
127  static inline double Uniform () {
128 
129 #ifdef HAS_SPRNG
130  return stream->sprng();
131 #elif defined(HAS_GSL)
132  return gsl_rng_uniform(r);
133 #else
134  register long z, w;
135 
136  do{
137  w = Seed1 / 53668;
138 
139  Seed1 = 40014 * (Seed1 - w * 53668) - w * 12211;
140 
141  if (Seed1 < 0) Seed1 += 2147483563;
142 
143  w = (Seed2 / 52774);
144 
145  Seed2 = 40692 * (Seed2 - w * 52774) - w * 3791;
146 
147  if (Seed2 < 0) Seed2 += 2147483399;
148 
149  z = Seed1 - Seed2;
150 
151  if (z < 1) z += 2147483562;
152 
153  }while (!((z * 4.656613e-10) < 1.0));
154 
155  return (z * 4.656613e-10);
156 #endif
157  }
159  static inline unsigned int Uniform (unsigned int max)
160  {
161  return (unsigned int)(Uniform() * max);
162  }
163 
165  static inline bool RandBool() {
166  //generate a random int (or long)
167 #ifdef HAS_SPRNG
168  static int intrand = stream->isprng();
169 #elif defined(HAS_GSL)
170  static unsigned long int intrand = gsl_rng_get(r);
171 #else
172  static int intrand = (int)(Uniform()*(double)std::numeric_limits<int>::max());
173 #endif
174  //read up to the first 16 bits
175  static unsigned int num = 0;
176  //redraw an number after that limit
177  if ( ++num > 16 ) {
178  num = 0;
179 
180 #ifdef HAS_SPRNG
181  intrand = stream->isprng();
182 #elif defined(HAS_GSL)
183  intrand = gsl_rng_get(r);
184 #else
185  intrand = (int)(Uniform()*(double)std::numeric_limits<int>::max());
186 #endif
187 
188  }
189  return (intrand & (1 << num) );
190 
191  }
192 
194  static inline unsigned long RandULong() {
195 #if defined(HAS_GSL) && !defined(HAS_SPRNG)
196  return gsl_rng_get(r);
197 #else
198  unsigned long rnd, limit = 0x10000000; //=2^28 this gives ~7% redraws
199  do{
200  rnd = (unsigned long)(Uniform()*ULONG_MAX);
201  }while(rnd < limit);
202 
203  return rnd;
204 #endif
205  }
207  static inline double gammln (double xx) {
208  double x,y,tmp,ser=1.000000000190015;
209  static double cof[6]={76.18009172947146,-86.50532032941677,
210  24.01409824083091,-1.231739572450155,
211  0.1208650973866179e-2,-0.5395239384953e-5};
212  int j;
213  y=x=xx;
214  tmp=x+5.5;
215  tmp -= (x+0.5)*log(tmp);
216  for (j = 0; j < 6; ++j) ser += cof[j]/++y;
217 
218  return -tmp+log(2.5066282746310005*ser/x);
219 
220  }
222  static inline double Poisson (double mean) {
223 
224 #if defined(HAS_GSL) && !defined(HAS_SPRNG)
225  return gsl_ran_poisson(r, mean);
226 #else
227  static double sq,alxm,g,oldm=(-1.0);
228  double em,t,y;
229 
230  if (mean < 12.0)
231  {
232  if (mean != oldm){
233  oldm=mean;
234  g=exp(-mean);
235  }
236  em = -1;
237  t=1.0;
238  do {
239  ++em;
240  t *= Uniform();
241  } while (t > g);
242  }else
243  {
244  if (mean != oldm)
245  {
246  oldm=mean;
247  sq=sqrt(2.0*mean);
248  alxm=log(mean);
249  g=mean*alxm-gammln(mean+1.0);
250  }
251  do {
252  do {
253  y=tan(M_PI*Uniform());
254  em=sq*y+mean;
255  } while (em < 0.0);
256  em=floor(em);
257  t=0.9*(1.0+y*y)*exp(em*alxm-gammln(em+1.0)-g);
258  } while (Uniform() > t);
259  }
260  return em;
261 #endif
262  }
263 
264  static inline double Gaussian(double sigma)
265  {
266 #if defined(HAS_GSL) && !defined(HAS_SPRNG)
267 
268  return gsl_ran_gaussian_ziggurat (r, sigma);
269 
270 #else
272 // double x, y, r2;
273 //
274 // do
275 // {
276 // /* choose x,y in uniform square (-1,-1) to (+1,+1) */
277 //
278 // x = -1 + 2 * Uniform ( );
279 // y = -1 + 2 * Uniform ( );
280 //
281 // /* see if it is in the unit circle */
282 // r2 = x * x + y * y;
283 // }
284 // while (r2 > 1.0 || r2 == 0);
285 //
286 // /* Box-Muller transform */
287 // return sigma * y * sqrt (-2.0 * log (r2) / r2);
288 
289  /*trying the ratio method from GSL*/
290  /* see code in gsl/randist/gauss.c */
291  double u, v, x, y, Q;
292  const double s = 0.449871; /* Constants from Leva */
293  const double t = -0.386595;
294  const double a = 0.19600;
295  const double b = 0.25472;
296  const double r1 = 0.27597;
297  const double r2 = 0.27846;
298 
299  do /* This loop is executed 1.369 times on average */
300  {
301  /* Generate a point P = (u, v) uniform in a rectangle enclosing
302  the K+M region v^2 <= - 4 u^2 log(u). */
303 
304  /* u in (0, 1] to avoid singularity at u = 0 */
305  u = 1 - RAND::Uniform();
306 
307  /* v is in the asymmetric interval [-0.5, 0.5). However v = -0.5
308  is rejected in the last part of the while clause. The
309  resulting normal deviate is strictly symmetric about 0
310  (provided that v is symmetric once v = -0.5 is excluded). */
311  v = RAND::Uniform() - 0.5;
312 
313  /* Constant 1.7156 > sqrt(8/e) (for accuracy); but not by too
314  much (for efficiency). */
315  v *= 1.7156;
316 
317  /* Compute Leva's quadratic form Q */
318  x = u - s;
319  y = fabs (v) - t;
320  Q = x * x + y * (a * y - b * x);
321 
322  /* Accept P if Q < r1 (Leva) */
323  /* Reject P if Q > r2 (Leva) */
324  /* Accept if v^2 <= -4 u^2 log(u) (K+M) */
325  /* This final test is executed 0.012 times on average. */
326  }
327  while (Q >= r1 && (Q > r2 || v * v > -4 * u * u * log (u)));
328 
329  return sigma * (v / u);
330 #endif
331  }
332 
333  static inline void BivariateGaussian(double sigma1,double sigma2, double rho, double *out1,double *out2) {
334 #if defined(HAS_GSL) && !defined(HAS_SPRNG)
335  gsl_ran_bivariate_gaussian(r,sigma1,sigma2,rho,out1,out2);
336 #else
337  //gsl code:
338  double u, v, r2, scale;
339  //double *x = out, *y = (++out);
340  do
341  {
342  /* choose x,y in uniform square (-1,-1) to (+1,+1) */
343 
344  u = -1 + 2 * Uniform ();
345  v = -1 + 2 * Uniform ();
346 
347  /* see if it is in the unit circle */
348  r2 = u * u + v * v;
349  }
350  while (r2 > 1.0 || r2 == 0);
351 
352  scale = sqrt (-2.0 * log (r2) / r2);
353 
354  *out1 = sigma1 * u * scale;
355  *out2 = sigma2 * (rho * u + sqrt(1 - rho*rho) * v) * scale;
356 
357 #endif
358  }
359 
360  static inline double LogNormal (double zeta, double sigma) {
361 #if defined(HAS_GSL) && !defined(HAS_SPRNG)
362  return gsl_ran_lognormal(r,zeta,sigma);
363 #else
364  //this is the GSL code:
365  double u, v, r2, normal, z;
366 
367  do
368  {
369  /* choose x,y in uniform square (-1,-1) to (+1,+1) */
370 
371  u = -1 + 2 * Uniform();
372  v = -1 + 2 * Uniform();
373 
374  /* see if it is in the unit circle */
375  r2 = u * u + v * v;
376  }
377  while (r2 > 1.0 || r2 == 0);
378 
379  normal = u * sqrt (-2.0 * log (r2) / r2);
380 
381  z = exp (sigma * normal + zeta);
382 
383  return z;
384 
385 #endif
386  }
387 
388  static inline double Gamma (double a, double b) {
389 #if defined(HAS_GSL) && !defined(HAS_SPRNG)
390  return gsl_ran_gamma(r, a, b);
391 #else
392  /*pasting GSL code in here*/
393 
394  /* assume a > 0 */
395 
396  if (a < 1)
397  {
398  double u = Uniform();//might give singularity at 0....
399  return Gamma(1.0 + a, b) * pow (u, 1.0 / a);
400  }
401 
402  {
403  double x, v, u;
404  double d = a - 1.0 / 3.0;
405  double c = (1.0 / 3.0) / sqrt (d);
406 
407  while (1)
408  {
409  do
410  {
411  x = Gaussian(1.0); //should use the Ziggurat method?
412  v = 1.0 + c * x;
413  }
414  while (v <= 0);
415 
416  v = v * v * v;
417  u = Uniform();//might give singularity at 0....
418 
419  if (u < 1 - 0.0331 * x * x * x * x)
420  break;
421 
422  if (log (u) < 0.5 * x * x + d * (1 - v + log (v)))
423  break;
424  }
425 
426  return b * d * v;
427  }
428 
429 #endif
430  }
431 
432  static inline double Bernoulli (double p)
433  {
434 #if defined(HAS_GSL) && !defined(HAS_SPRNG)
435  return gsl_ran_bernoulli(r, p);
436 #else
437  double u = RAND::Uniform() ;
438 
439  if (u < p)
440  {
441  return 1 ;
442  }
443  else
444  {
445  return 0 ;
446  }
447 #endif
448  }
449 
450  static inline double Exponential (double mu) {
451  return -mu * log(RAND::Uniform());
452  }
453 
454 #ifdef HAS_GSL
455  static inline void MultivariateGaussian(gsl_vector *eval, gsl_matrix *evec,
456  gsl_vector *workspace, gsl_vector *px)
457  {
458  size_t i;
459 
460  for (i=0; i<eval->size; i++)
461  gsl_vector_set (workspace, i,
462  Gaussian(gsl_vector_get (eval, i)));
463 
464  gsl_blas_dgemv (CblasNoTrans, 1.0,
465  evec, workspace, 0.0, px); /* px = evec * px */
466 
467  }
468 
469  static inline void MultivariateGaussianCholesky(gsl_vector *sigma, gsl_matrix *M, gsl_vector *px)
470  {//generate n i.i.d. random normal variates
471  for (size_t i = 0; i < sigma->size; i++)
472  gsl_vector_set (px, i, Gaussian(gsl_vector_get(sigma, i)));
473 
474  gsl_blas_dtrmv (CblasLower, CblasNoTrans, CblasNonUnit, M, px);
475  }
476 
477  static inline long double factoriel(unsigned int x) {
478  long double f = 1;
479  for(unsigned int i=1;i<=x;++i)
480  f *= i;
481  return f;
482  }
483 
484 // static inline double Binomial (double p,unsigned int k,long double N,
485 // const unsigned int n) {
486 // register long double bincoeff = N/(factoriel(k)*factoriel(n - k));
487 // return (bincoeff*pow(p,(int)k)*pow(1-p,(int)(n - k)));
488 // }
489 
490 #endif
491 
492  static inline double Binomial(double p, unsigned int n)
493  {
494  /*implements Knuth method*/
495  unsigned int i, a, b, k = 0;
496 
497  while (n > 10) /* This parameter is tunable */
498  {
499  double X;
500  a = 1 + (n / 2);
501  b = 1 + n - a;
502 
503  X = RAND::Beta((double) a, (double) b);
504 
505  if (X >= p)
506  {
507  n = a - 1;
508  p /= X;
509  }
510  else
511  {
512  k += a;
513  n = b - 1;
514  p = (p - X) / (1 - X);
515  }
516  }
517 
518  for (i = 0; i < n; i++)
519  {
520  double u = RAND::Uniform();
521  if (u < p)
522  k++;
523  }
524 
525  return k;
526 
527  }
528 
529  static inline double Beta (const double a, const double b)
530  {
531  /*from Knuth*/
532  double x1 = RAND::Gamma(a, 1.0);
533  double x2 = RAND::Gamma(b, 1.0);
534 
535  return x1 / (x1 + x2);
536  }
537 
538  static inline unsigned int Binomial2 (double p, unsigned int n){
539 
540 #if defined(HAS_GSL) && !defined(HAS_SPRNG)
541  return gsl_ran_binomial (r, p, n);
542 #else
543  return Binomial(p, n);
544 #endif
545  }
546 
547  static inline void Multinomial (size_t K, unsigned int N, const double p[], unsigned int n[])
548  {
549 #if defined(HAS_GSL) && !defined(HAS_SPRNG)
550  return gsl_ran_multinomial (r, K, N, p, n);
551 #else
552  // GSL code here:
553  size_t k;
554  double norm = 0.0;
555  double sum_p = 0.0;
556 
557  unsigned int sum_n = 0;
558 
559  /* p[k] may contain non-negative weights that do not sum to 1.0.
560  * Even a probability distribution will not exactly sum to 1.0
561  * due to rounding errors.
562  */
563 
564  for (k = 0; k < K; k++)
565  {
566  norm += p[k];
567  }
568 
569  for (k = 0; k < K; k++)
570  {
571  if (p[k] > 0.0)
572  {
573  n[k] = Binomial (p[k] / (norm - sum_p), N - sum_n); //MOD
574  }
575  else
576  {
577  n[k] = 0;
578  }
579 
580  sum_p += p[k];
581  sum_n += n[k];
582  }
583 
584 #endif
585  }
587  static inline void MultinomialOnNormalizedValarray (size_t K, unsigned int N, const std::valarray< double > &p,
588  unsigned int n[])
589  {
590  // GSL code here: FG 2020: modified for normalized arrays
591  size_t k;
592  double sum_p = 0.0;
593 
594  unsigned int sum_n = 0;
595 
596  for (k = 0; k < K; k++)
597  {
598  n[k] = RAND::Binomial (p[k] / (1.0 - sum_p), N - sum_n); //MOD FG
599  sum_p += p[k];
600  sum_n += n[k];
601  }
602  }
603 
605  static inline void MultinomialOnNormalizedValarray_expandedOut (size_t K, unsigned int N,
606  const std::valarray<double> &p,
607  unsigned int n[])
608  {
609  // GSL code here: FG 2020: modified for normalized arrays
610  size_t k;
611  double sum_p = 0.0;
612  unsigned int _n, sum_n = 0;
613  unsigned int i = 0, pos = 0;
614 
615  for (k = 0; k < K; k++) {
616  //draw number of events k with probability p[k]
617  _n = RAND::Binomial (p[k] / (1.0 - sum_p), N - sum_n);
618 
619  for(i = 0; i < _n; i++)
620  n[pos++] = k;
621 
622  sum_p += p[k];
623  sum_n += _n;
624  assert(pos <= N);
625  }
626  assert(sum_n == N);
627  }
628 
630  static inline void MultinomialOnNormalizedValarray_scrambleOut (size_t K, unsigned int N,
631  const std::valarray<double> &p,
632  unsigned int n[])
633  {
634  // GSL code here: FG 2020: modified for normalized arrays
635  size_t k;
636  double sum_p = 0.0;
637  unsigned int _n, sum_n = 0;
638  unsigned int i = 0, pos = 0;
639 
640  for (k = 0; k < K; k++) {
641  //draw number of events k with probability p[k]
642  _n = RAND::Binomial (p[k] / (1.0 - sum_p), N - sum_n);
643 
644  for(i = 0; i < _n; i++)
645  n[pos++] = k;
646 
647  sum_p += p[k];
648  sum_n += _n;
649  assert(pos <= N);
650  }
651  assert(sum_n == N);
652 
653  //scramble the output array
655 
656  }
657 
659  static inline void MultinomialOnNormalizedValarrayZipper_scrambleOut (size_t K, unsigned int N,
660  const std::valarray<double> &p,
661  unsigned int n[])
662  {
663  size_t k;
664  double sum = 0.0;
665  double rand;
666  unsigned int i = 0;
667 
668  for (k = 0; k < N; k++) {
669 
670  rand = std::min(0.99999995, RAND::Uniform()); // to avoid problems with rounding errors
671  i = 0;
672  sum = p[i];
673 
674  //zip through the proba array:
675  while( sum < rand ) {
676  i++;
677  sum += p[i];
678  }
679 
680  n[k] = i;
681 
682  }
683  //scramble the output array
685 
686  }
687 
692  static inline void ScrambleArrayUInt (const int length, unsigned int *array)
693  {
694  unsigned int size = length, pos, last = length - 1, num = length -1, el;
695 
696  // with stop after 2 elements are left
697  // this algo allows swapping an element with itself, which is fine
698  for (unsigned int i = 0; i < num; i++) {
699  pos = RAND::Uniform(size);
700  el = array[last];
701  array[last] = array[pos];
702  array[pos] = el;
703  size--; last--;
704  }
705 
706  assert(size == 1); //we stopped before swapping the last (first) element with itself
707  }
708 
716  static inline void Sample (const int from, const int to, const unsigned int num, int* result, bool replace)
717  {
718  assert(from < to);
719 
720  unsigned int seq_length = to - from; //don't include last (to)
721 
722  assert(num <= seq_length);
723 
724  // we build a sequence of indexes to choose from
725  int *seq = new int [seq_length];
726 
727  seq[0] = from;
728 
729  for(unsigned int i = 1; seq[i-1] < to && i < seq_length; ++i)
730  seq[i] = seq[i-1] + 1;
731 
732  if(!replace) { //without replacement
733 
734  unsigned int size = seq_length, pos, last = seq_length - 1;
735 
736  for (unsigned int i = 0; i < num; i++) {
737  pos = RAND::Uniform(size);
738  result[i] = seq[pos];
739  seq[pos] = seq[last];
740  // seq[last] = result[i]; useless operation
741  size--; last--;
742  }
743 
744  } else { //with replacement
745  for (unsigned int i = 0; i < num; i++)
746  result[i] = seq[ RAND::Uniform(seq_length) ];
747  }
748 
749  delete [] seq;
750  }
751 
752  static inline void SampleSeq(int from, int to, int by, unsigned int num, int* result, bool replace = false)
753  {
754  assert(from < to && by < to && by > 0);
755 
756  unsigned int seq_length = (int)((to - from) / by); //don't include last (to)
757 
758  assert(num <= seq_length);
759 
760  int *seq = new int [seq_length];
761 
762  seq[0] = from;
763 
764  for(unsigned int i = 1; seq[i-1] + by < to && i < seq_length; ++i) seq[i] = seq[i-1] + by;
765 
766  if(!replace) { //without replacement
767 
768  unsigned int size = seq_length, pos, last = seq_length - 1;
769 
770  for (unsigned int i = 0; i < num; i++) {
771  pos = RAND::Uniform(size);
772  result[i] = seq[pos];
773  seq[pos] = seq[last];
774  // seq[last] = result[i]; useless operation
775  size--; last--;
776  }
777 
778  } else { //with replacement
779  for (unsigned int i = 0; i < num; i++) result[i] = seq[ RAND::Uniform(seq_length) ];
780  }
781 
782  delete [] seq;
783  }
784 
785  static inline void SampleSeqWithReciprocal(int from, int to, int by, unsigned int num1, int* result1, unsigned int num2, int* result2)
786  {
787  assert(from < to && by < to && by > 0);
788 
789  unsigned int seq_length = (int)((to - from) / by); //don't include last (to)
790 
791  assert(num1 + num2 == seq_length);
792 
793  int *seq = new int [seq_length];
794 
795  seq[0] = from;
796 
797  for(unsigned int i = 1; seq[i-1] + by < to && i < seq_length; ++i) seq[i] = seq[i-1] + by;
798 
799  unsigned int size = seq_length, pos, last = seq_length - 1;
800 
801  for (unsigned int i = 0; i < num1; i++) {
802  pos = RAND::Uniform(size);
803  result1[i] = seq[pos];
804  seq[pos] = seq[last];
805  seq[last] = result1[i];
806  size--; last--;
807  }
808 
809  for (unsigned int i = 0; i < num2 && i < size; i++)
810  result2[i] = seq[i];
811 
812  delete [] seq;
813  }
814 
816  static inline size_t Discrete (const gsl_ran_discrete_t *g)
817  {
818 #if defined(HAS_GSL) && !defined(HAS_SPRNG)
819  return gsl_ran_discrete(r, g);
820 #else
821  /* GSL code here, modified to call our Uniform() */
822  size_t c=0;
823  double u,f;
824  u = Uniform();
825 
826 #if KNUTH_CONVENTION
827  c = (u*(g->K));
828 #else
829  u *= g->K;
830  c = u;
831  u -= c;
832 #endif
833 
834  f = (g->F)[c];
835  /* fprintf(stderr,"c,f,u: %d %.4f %f\n",c,f,u); */
836  if (f == 1.0) return c;
837 
838  if (u < f) {
839  return c;
840  }
841  else {
842  return (g->A)[c];
843  }
844 
845 #endif
846  }
847 
848 };
849 
850 #endif
MPIenv * _myenv
Definition: MPImanager.cc:36
MPI environment setup.
Definition: MPImanager.h:122
int workerCount() const
Definition: MPImanager.h:129
int workerRank() const
Definition: MPImanager.h:130
Random number generation class, uses various types of random generators depending on the implementati...
Definition: Uniform.h:55
static double Exponential(double mu)
Definition: Uniform.h:450
static double Bernoulli(double p)
Definition: Uniform.h:432
static void SampleSeqWithReciprocal(int from, int to, int by, unsigned int num1, int *result1, unsigned int num2, int *result2)
Definition: Uniform.h:785
static double gammln(double xx)
From the Numerical Recieps.
Definition: Uniform.h:207
static void MultinomialOnNormalizedValarray(size_t K, unsigned int N, const std::valarray< double > &p, unsigned int n[])
Multinomial draw assuming the probabilities sum to 1.0 and are all > 0.
Definition: Uniform.h:587
static void Multinomial(size_t K, unsigned int N, const double p[], unsigned int n[])
Definition: Uniform.h:547
static void BivariateGaussian(double sigma1, double sigma2, double rho, double *out1, double *out2)
Definition: Uniform.h:333
static void MultinomialOnNormalizedValarrayZipper_scrambleOut(size_t K, unsigned int N, const std::valarray< double > &p, unsigned int n[])
Multinomial draw assuming the probabilities sum to 1.0 and are all > 0, the output is an array of siz...
Definition: Uniform.h:659
static void MultinomialOnNormalizedValarray_expandedOut(size_t K, unsigned int N, const std::valarray< double > &p, unsigned int n[])
Multinomial draw assuming the probabilities sum to 1.0 and are all > 0, the output is an array of siz...
Definition: Uniform.h:605
static double Binomial(double p, unsigned int n)
Definition: Uniform.h:492
static void free()
Memory de-allocation.
Definition: Uniform.h:111
static long Seed1
Definition: Uniform.h:78
static void ScrambleArrayUInt(const int length, unsigned int *array)
Randomize the elements within an array.
Definition: Uniform.h:692
static double Poisson(double mean)
From the Numerical Recieps.
Definition: Uniform.h:222
static unsigned int Binomial2(double p, unsigned int n)
Definition: Uniform.h:538
static size_t Discrete(const gsl_ran_discrete_t *g)
Calling the GSL ran_discrete function.
Definition: Uniform.h:816
static unsigned long RandULong()
Return a random unsigned long, from uniform distribution.
Definition: Uniform.h:194
static void MultinomialOnNormalizedValarray_scrambleOut(size_t K, unsigned int N, const std::valarray< double > &p, unsigned int n[])
Multinomial draw assuming the probabilities sum to 1.0 and are all > 0, the output is an array of siz...
Definition: Uniform.h:630
static unsigned int Uniform(unsigned int max)
Returns a uniformly distributed random number from [0.0, max[.
Definition: Uniform.h:159
static void init(unsigned long seed)
Initialize the random generator's seed.
Definition: Uniform.h:82
static long Seed2
Definition: Uniform.h:78
static void Sample(const int from, const int to, const unsigned int num, int *result, bool replace)
Creates a sample of integers within range [from, to), with or without replacement.
Definition: Uniform.h:716
static double Beta(const double a, const double b)
Definition: Uniform.h:529
static double Gaussian(double sigma)
Definition: Uniform.h:264
static double Uniform()
Generates a random number from [0.0, 1.0[ uniformly distributed.
Definition: Uniform.h:127
static void SampleSeq(int from, int to, int by, unsigned int num, int *result, bool replace=false)
Definition: Uniform.h:752
static bool RandBool()
Returns a random boolean.
Definition: Uniform.h:165
static double LogNormal(double zeta, double sigma)
Definition: Uniform.h:360
static double Gamma(double a, double b)
Definition: Uniform.h:388
void message(const char *message,...)
Definition: output.cc:40

Generated for Nemo v2.4.0b by  doxygen 1.9.1 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR