Top |
Libgretl uses the Mersenne Twister as its underlying engine for uniform random values, but offers added value in the form of generators for several distributions commonly used in econometrics.
Note that before using the libgretl PRNG you must call
either libgretl_init()
or the specific initialization
function shown below, gretl_rand_init()
. And once you're
finished with it, you may call gretl_rand_free()
or the
global libgretl function libgretl_cleanup()
.
void
gretl_rand_init (void
);
Initialize gretl's PRNG, using the system time as seed. Default version, as opposed to DCMT.
void
gretl_rand_free (void
);
Free the gretl_rand structure (may be called at program exit).
void gretl_dcmt_init (int n
,int self
,unsigned int seed
);
Initialize DCMT, if needed.
void
gretl_rand_set_seed (unsigned int seed
);
Set a specific (and hence reproducible) seed for gretl's PRNG.
But if the value 0 is given for seed
, set the seed using
the system time (which is the default when libgretl is
initialized).
int gretl_rand_int_minmax (int *a
,int n
,int min
,int max
);
Fill array a
of length n
with pseudo-random drawings
from the uniform distribution on [min
, max
], using the
Mersenne Twister.
int gretl_alt_rand_int_minmax (int *a
,int n
,int min
,int max
);
Fill array a
of length n
with pseudo-random drawings
from the uniform distribution on [min
, max
], using a
Mersenne Twister which is independent of the main one
employed by libgretl.
void gretl_rand_uniform (double *a
,int t1
,int t2
);
Fill the selected range of array a
with pseudo-random drawings
from the uniform distribution on [0-1), using the Mersenne
Twister.
int gretl_rand_uniform_minmax (double *a
,int t1
,int t2
,double min
,double max
);
Fill the selected subset of array a
with pseudo-random drawings
from the uniform distribution on min
to max
, using the Mersenne
Twister.
int gretl_rand_uniform_int_minmax (double *a
,int t1
,int t2
,int min
,int max
,gretlopt opt
);
Fill the selected subset of array a
with pseudo-random drawings
from the uniform distribution on [min
, max
], using the
Mersenne Twister.
void gretl_rand_normal (double *a
,int t1
,int t2
);
Fill the selected range of array a
with pseudo-random drawings
from the standard normal distribution, using the Mersenne Twister
for uniform input and the Ziggurat method for converting to the
normal distribution.
int gretl_rand_normal_full (double *a
,int t1
,int t2
,double mean
,double sd
);
Fill the selected range of array a
with pseudo-random drawings
from the normal distribution with the given mean and standard
deviation, using the Mersenne Twister for uniform input and
the Ziggurat method for converting to the normal distribution.
int gretl_rand_chisq (double *a
,int t1
,int t2
,int v
);
Fill the selected range of array a
with pseudo-random drawings
from the Chi-squared distribution with v
degrees of freedom,
using the gamma r.v. generator.
int gretl_rand_student (double *a
,int t1
,int t2
,double v
);
Fill the selected range of array a
with pseudo-random drawings
from the Student t distribution with v
degrees of freedom,
using the Mersenne Twister for uniform input and the ziggurat
method for converting to the normal distribution.
int gretl_rand_F (double *a
,int t1
,int t2
,int v1
,int v2
);
Fill the selected range of array a
with pseudo-random drawings
from the F distribution with v1
and v2
degrees of freedom,
using the Mersenne Twister for uniform input and the Ziggurat
method for converting to the normal distribution.
int gretl_rand_binomial (double *a
,int t1
,int t2
,int n
,double p
);
Fill the selected range of array a
with pseudo-random drawings
from the binomial distribution with parameters n
and p
.
int gretl_rand_poisson (double *a
,int t1
,int t2
,const double *m
,int vec
);
Fill the selected range of array a
with pseudo-random drawings
from the Poisson distribution with a mean determined by
m
, which can either be a pointer to a scalar, or an array
of length greater than or equal to t2
+ 1.
int gretl_rand_exponential (double *a
,int t1
,int t2
,double mu
);
Fill the selected range of array a
with pseudo-random drawings
from the exponential distribution with scale mu
.
int gretl_rand_weibull (double *a
,int t1
,int t2
,double shape
,double scale
);
Fill the selected range of array a
with pseudo-random drawings
from the Weibull distribution with shape k
and scale lambda
.
int gretl_rand_logistic (double *a
,int t1
,int t2
,double loc
,double scale
);
Fill the selected range of array a
with pseudo-random drawings
from the logistic distribution with location loc
and scale scale
.
int gretl_rand_gamma (double *a
,int t1
,int t2
,double shape
,double scale
);
Fill the selected range of array a
with pseudo-random drawings
from the specified gamma distribution.
int gretl_rand_GED (double *a
,int t1
,int t2
,double nu
);
Fill the selected range of array a
with pseudo-random drawings
from the GED distribution with shape nu
. We exploit the fact that
if x ~ GED(n), then |x/k|^n is a Gamma rv.
int gretl_rand_laplace (double *a
,int t1
,int t2
,double mu
,double b
);
Fill the selected range of array a
with pseudo-random drawings
from the Laplace distribution with mean mu
and scale b
.
int gretl_rand_beta (double *x
,int t1
,int t2
,double s1
,double s2
);
Fill the selected range of array a
with pseudo-random drawings
from the beta distribution with shape parameters s1
and s2
.
The code here is adapted from http://www.netlib.org/random/random.f90
which implements the method of R.C.H. Cheng, "Generating beta
variates with nonintegral shape parameters", Communications of the
ACM, 21(4), April 1978.
int gretl_rand_beta_binomial (double *x
,int t1
,int t2
,int n
,double s1
,double s2
);
Fill the selected range of array x
with pseudo-random drawings
from the binomial distribution with n
trials and success
probability distributed according to the beta distribution with
shape parameters s1
and s2
.
gretl_matrix * gretl_rand_dirichlet (const gretl_vector *a
,int n
,int *err
);
gretl_matrix * halton_matrix (int m
,int r
,int offset
,int *err
);
gretl_matrix * inverse_wishart_matrix (const gretl_matrix *S
,int v
,int *err
);
Computes a draw from the Inverse Wishart distribution
with v
degrees of freedom, using the method of Odell and
Feiveson, "A numerical procedure to generate a sample
covariance matrix", JASA 61, pp. 199203, 1966.
gretl_matrix * inverse_wishart_sequence (const gretl_matrix *S
,int v
,int replics
,int *err
);