Random

Random — Wrapper for GSL random number generators and distribution functions

Synopsis

guint32             oscats_rnd_uniform_int              ();
gint                oscats_rnd_uniform_int_range        (gint min,
                                                         gint max);
gdouble             oscats_rnd_uniform                  ();
gdouble             oscats_rnd_uniform_range            (gdouble min,
                                                         gdouble max);
gdouble             oscats_rnd_normal                   (gdouble sd);
void                oscats_rnd_binorm                   (gdouble sdx,
                                                         gdouble sdy,
                                                         gdouble rho,
                                                         gdouble *X,
                                                         gdouble *Y);
void                oscats_rnd_multinorm_prep           (const GGslMatrix *sigma,
                                                         GGslMatrix *sigma_half);
void                oscats_rnd_multinorm                (const GGslVector *mu,
                                                         const GGslMatrix *sigma_half,
                                                         GGslVector *x);
gdouble             oscats_rnd_exp                      (gdouble mu);
gdouble             oscats_rnd_gamma                    (gdouble a,
                                                         gdouble b);
gdouble             oscats_rnd_beta                     (gdouble a,
                                                         gdouble b);
void                oscats_rnd_dirichlet                (const GGslVector *alpha,
                                                         GGslVector *x);
guint               oscats_rnd_poisson                  (gdouble mu);
guint               oscats_rnd_binomial                 (guint n,
                                                         gdouble p);
void                oscats_rnd_multinomial              (guint n,
                                                         const GGslVector *p,
                                                         GArray *x);
guint               oscats_rnd_hypergeometric           (guint n1,
                                                         guint n2,
                                                         guint N);
gdouble             oscats_rnd_normal_p                 (gdouble x,
                                                         gdouble sd);
gdouble             oscats_rnd_chisq_p                  (gdouble x,
                                                         gdouble nu);
gdouble             oscats_rnd_F_p                      (gdouble x,
                                                         gdouble nu1,
                                                         gdouble nu2);
gdouble             oscats_rnd_t_p                      (gdouble x,
                                                         gdouble nu);
void                oscats_rnd_sample                   (const GPtrArray *population,
                                                         guint num,
                                                         GPtrArray *sample,
                                                         gboolean replace);

Description

Details

oscats_rnd_uniform_int ()

guint32             oscats_rnd_uniform_int              ();

Returns :

a uniformly random integer on [0, 2^32)

oscats_rnd_uniform_int_range ()

gint                oscats_rnd_uniform_int_range        (gint min,
                                                         gint max);

min :

the minimum

max :

the maximum

Returns :

a uniformly random integer on [min, max]

oscats_rnd_uniform ()

gdouble             oscats_rnd_uniform                  ();

Returns :

a uniformly random number on [0,1).

oscats_rnd_uniform_range ()

gdouble             oscats_rnd_uniform_range            (gdouble min,
                                                         gdouble max);

min :

minimum

max :

maximum

Returns :

a uniformly random number on [min,max).

oscats_rnd_normal ()

gdouble             oscats_rnd_normal                   (gdouble sd);

The mean-zero normal distribution has pdf f_norm(x|sd) = exp(-x^2 / (2 sd^2)) / (sqrt(2 pi) sd).

Must have: sd > 0.

sd :

standard deviation

Returns :

a Normally distributed random number

oscats_rnd_binorm ()

void                oscats_rnd_binorm                   (gdouble sdx,
                                                         gdouble sdy,
                                                         gdouble rho,
                                                         gdouble *X,
                                                         gdouble *Y);

The mean-zero bivariate normal distribution has pdf f_binorm(x,y|sdx,sdy) = exp(-(x^2/sdx^2 + y^2/sdy^2 - 2 rho x y / (sdx sdy)) / 2(1-rho^2)) / (2 pi sdx sdy). Note that cov(X,Y) = rho * sdx * sdy.

Must have: sdx > 0, sdy > 0, -1 <= rho <= 1.

sdx :

standard deviation for first variable

sdy :

standard deviation for second variable

rho :

correlation coefficient

X :

pointer to return first variable

Y :

pointer to return second variable

oscats_rnd_multinorm_prep ()

void                oscats_rnd_multinorm_prep           (const GGslMatrix *sigma,
                                                         GGslMatrix *sigma_half);

Prepares a lower-triangular matrix A such that AA'=Sigma for multivariate-normal random-number generation. This is achieved by Cholesky decomposition.

Must have: sigma symmetric and positive definite, sigma and sigma_half with same size > 2.

sigma :

covariance matrix for multivariate normal distribution

sigma_half :

return matrix

oscats_rnd_multinorm ()

void                oscats_rnd_multinorm                (const GGslVector *mu,
                                                         const GGslMatrix *sigma_half,
                                                         GGslVector *x);

A random vector x of length n is multivariate normal if x = mu + A z, where AA' = Sigma is the covariance matrix of the random vector, and z is a vector of indepenedent standard normal random variables.

Must have: sigma_half lower-triangular with same size as mu and x.

mu :

mean

sigma_half :

half of covariance matrix

x :

return for random vector

oscats_rnd_exp ()

gdouble             oscats_rnd_exp                      (gdouble mu);


oscats_rnd_gamma ()

gdouble             oscats_rnd_gamma                    (gdouble a,
                                                         gdouble b);


oscats_rnd_beta ()

gdouble             oscats_rnd_beta                     (gdouble a,
                                                         gdouble b);


oscats_rnd_dirichlet ()

void                oscats_rnd_dirichlet                (const GGslVector *alpha,
                                                         GGslVector *x);


oscats_rnd_poisson ()

guint               oscats_rnd_poisson                  (gdouble mu);


oscats_rnd_binomial ()

guint               oscats_rnd_binomial                 (guint n,
                                                         gdouble p);


oscats_rnd_multinomial ()

void                oscats_rnd_multinomial              (guint n,
                                                         const GGslVector *p,
                                                         GArray *x);


oscats_rnd_hypergeometric ()

guint               oscats_rnd_hypergeometric           (guint n1,
                                                         guint n2,
                                                         guint N);


oscats_rnd_normal_p ()

gdouble             oscats_rnd_normal_p                 (gdouble x,
                                                         gdouble sd);

Computes the upper tail of the Normal cdf: p_norm(x|sd) = int_{-\infty}^x f_norm(t|sd) dt.

Must have: sd > 0.

x :

sampled value

sd :

standard deviation

Returns :

the upper-tail p-value

oscats_rnd_chisq_p ()

gdouble             oscats_rnd_chisq_p                  (gdouble x,
                                                         gdouble nu);

If y_1, ..., y_nu are standard normally distributed random numbers, then sum_1^nu y_i^2 is distributed Chi^2 with nu degrees of freedom. Computes the upper tail of the Chi^2 cdf with nu degrees of freedom: p_chisq(x|nu) = int_{-\infty}^x (t/2)^(nu^2-1) exp(-t/2) / 2 Gamma(nu/2) dt.

Must have: x >= 0.

x :

sampled value

nu :

degrees of freedom

Returns :

the upper-tail p-value

oscats_rnd_F_p ()

gdouble             oscats_rnd_F_p                      (gdouble x,
                                                         gdouble nu1,
                                                         gdouble nu2);

If y_1 is distributed Chi^2 with nu_1 degrees of freedom, and y_2 is distributed Chi^2 with nu_2 degrees of freedom, w = (y_1/nu_1) / (y_2/nu_2) is distributed F(nu_1, nu_2). Computes the upper tail of the F cdf with nu1 and nu2 degrees of freedom.

Must have: x >= 0.

x :

sampled value

nu1 :

degrees of freedom for numerator

nu2 :

degrees of freedom for denominator

Returns :

the upper-tail p-value

oscats_rnd_t_p ()

gdouble             oscats_rnd_t_p                      (gdouble x,
                                                         gdouble nu);

If y_1 is distributed standard normal, and y_2 is distributed Chi^2 with nu degrees of freedom, w = y_1 / (y_2/nu) is distributed t(nu). Computes the upper tail of the t cdf with nu degrees of freedom.

x :

sampled value

nu :

degrees of freedom

Returns :

the upper-tail p-value

oscats_rnd_sample ()

void                oscats_rnd_sample                   (const GPtrArray *population,
                                                         guint num,
                                                         GPtrArray *sample,
                                                         gboolean replace);

Pointers are not ref'd when added to sample. Moreover, sample should not have a GDestroyNotify.

population :

objects from which to sample

num :

number of objects to sample

sample :

return vector of sampled objects

replace :

sample with replacement?