Top |
NcmRNGNcmRNG — Encapsulated GNU Scientific Library (GSL) random number generator with support for multhreading. |
This object encapsulates the GNU Scientific Library (GSL) pseudo random number generator (PRNG). Its main purpose is to add support for saving and loading state and multhreading. For more information about the GSL routines see both links: random number generation and random number distributions.
NcmRNGDiscrete * ncm_rng_discrete_new (const gdouble *weights
,const guint n
);
Creates a new NcmRNGDiscrete. This object is used to generate random numbers from a discrete distribution for the given set of weights.
NcmRNGDiscrete *
ncm_rng_discrete_copy (NcmRNGDiscrete *rng
);
Creates a copy of rng_discrete
.
void
ncm_rng_discrete_free (NcmRNGDiscrete *rng
);
Frees the memory allocated by rng
.
NcmRNG *
ncm_rng_new (const gchar *algo
);
Creates a new NcmRNG using the algorithm algo
.
See the list of algorithms here.
If algo
is NULL the default algorithm and seed are used.
See this link for more details.
NcmRNG * ncm_rng_seeded_new (const gchar *algo
,gulong seed
);
Creates a new NcmRNG using the algorithm algo
.
See the list of algorithms here.
If algo
is NULL the default algorithm is used.
See this link for more details.
void
ncm_rng_clear (NcmRNG **rng
);
Decreases the reference count of *rng
by one and sets *rng
to NULL.
gchar *
ncm_rng_get_state (NcmRNG *rng
);
Gets the state of the algorithm in Base64. It can be a very large string depending on the underlining state.
void ncm_rng_set_algo (NcmRNG *rng
,const gchar *algo
);
Sets the PRNG algorithm.
void ncm_rng_set_state (NcmRNG *rng
,const gchar *state
);
Sets the PRNG algorithm state.
gboolean ncm_rng_check_seed (NcmRNG *rng
,gulong seed
);
Check if the seed was already used by any NcmRNG.
gulong
ncm_rng_get_seed (NcmRNG *rng
);
This functions returns the seed used to initialize the PRNG.
void ncm_rng_set_random_seed (NcmRNG *rng
,gboolean allow_colisions
);
Sets the algorithm seed using a PRNG seeded by /dev/urandom (Unix/Linux)
or current time, when the first is not available (see
).
If g_rand_new()
allow_colisions
is FALSE this function will set the first unused seed generated.
NcmRNG *
ncm_rng_pool_get (const gchar *name
);
Gets the NcmRNG named name
from the pool.
If it doesn't exists, it creates one, add it to the pool and returns it.
gulong
ncm_rng_gen_ulong (NcmRNG *rng
);
This function returns a random unsigned integer from the uniform distribution.
gulong ncm_rng_uniform_int_gen (NcmRNG *rng
,gulong n
);
This function returns a random number drawn from the
uniform distribution between zero and n
.
gdouble
ncm_rng_uniform01_gen (NcmRNG *rng
);
This function returns a random number drawn from the uniform distribution between zero and one $[0,1)$.
gdouble
ncm_rng_uniform01_pos_gen (NcmRNG *rng
);
This function returns a random number drawn from the uniform distribution between zero and one $(0,1)$.
gdouble ncm_rng_uniform_gen (NcmRNG *rng
,const gdouble xl
,const gdouble xu
);
This functions returns a random number drawn from the
uniform distribution between the values xl
and xu
.
gdouble ncm_rng_gaussian_gen (NcmRNG *rng
,const gdouble mu
,const gdouble sigma
);
This function returns a random number drawn from the
Gaussian distribution,
with mean mu
and standard deviation sigma
.
gdouble
ncm_rng_ugaussian_gen (NcmRNG *rng
);
This function returns a random number drwan from the
Gaussian distribution,
with mean zero and standard deviation one.
Equivalent as above but with mean
= 0 and sigma
= 1.
gdouble ncm_rng_gaussian_tail_gen (NcmRNG *rng
,const gdouble a
,const gdouble sigma
);
This function returns a random number drawn from the upper tail of the
Gaussian distribution with standard deviation sigma
.
The value returned is larger than the lower limit a
, which must be positive.
gdouble ncm_rng_exponential_gen (NcmRNG *rng
,const gdouble mu
);
This function returns a random number drawn from the
exponential distribution
with scale parameter (mean) mu
.
gdouble ncm_rng_laplace_gen (NcmRNG *rng
,const gdouble a
);
This function returns a random number drawn from the
Laplace distribution
with width a
.
gdouble ncm_rng_exppow_gen (NcmRNG *rng
,const gdouble a
,const gdouble b
);
This function returns a random number drawn from the
exponential power distribution
with scale parameter a
and exponent b
.
gdouble ncm_rng_beta_gen (NcmRNG *rng
,const gdouble a
,const gdouble b
);
This function returns a random number drawn from the
beta distribution
with shape parameters a
and b
. The shape parameters must be positive.
gdouble ncm_rng_gamma_gen (NcmRNG *rng
,const gdouble a
,const gdouble b
);
This function returns a random number drawn from the
gamma distribution
with shape parameter a
and scale parameter b
.
gdouble ncm_rng_chisq_gen (NcmRNG *rng
,const gdouble nu
);
This function returns a random number drawn from the Chi-square Distribution, with $\nu$ degrees of freedom.
gdouble ncm_rng_poisson_gen (NcmRNG *rng
,const gdouble mu
);
This function returns a random number drawn from the Poisson distribution,
with frequency mu
.
gdouble ncm_rng_rayleigh_gen (NcmRNG *rng
,const gdouble sigma
);
This function returns a random number drawn from the
Rayleigh distribution
with scale parameter sigma
.
gsize ncm_rng_discrete_gen (NcmRNG *rng
,NcmRNGDiscrete *rng_discrete
);
This function returns a random number drawn from the discrete distribution. The
weights must created using ncm_rng_discrete_new()
.
void ncm_rng_sample (NcmRNG *rng
,void *dest
,size_t k
,void *src
,size_t n
,size_t size
);
This function fills the array dest
with k
elements from the array src
.
The elements are chosen randomly using the algorithm (sample with replecement) in
gsl_ran_sample()
.
rng |
a NcmRNG |
|
dest |
an array of |
|
k |
number of elements in |
|
src |
an array of |
|
n |
number of elements in |
|
size |
size of each element in |
void ncm_rng_choose (NcmRNG *rng
,void *dest
,size_t k
,void *src
,size_t n
,size_t size
);
This function fills the array dest
with k
elements from the array src
.
The elements are chosen randomly using the algorithm (choose with replecement) in
gsl_ran_choose()
.
rng |
a NcmRNG |
|
dest |
an array of |
|
k |
number of elements in |
|
src |
an array of |
|
n |
number of elements in |
|
size |
size of each element in |
void ncm_rng_multinomial (NcmRNG *rng
,gsize K
,guint N
,const gdouble *p
,guint *n
);
This function fills the array n
with K
elements using a multinomial distribution
defined by the array p
.
rng |
a NcmRNG |
|
K |
number of possible outcomes |
|
N |
number of trials |
|
p |
array of probabilities. |
[array length=K][element-type gdouble] |
n |
array of counts. |
[array length=K][element-type guint] |
void ncm_rng_bivariate_gaussian_gen (NcmRNG *rng
,const gdouble sigma_x
,const gdouble sigma_y
,const gdouble rho
,gdouble *x
,gdouble *y
);
This function returns a random number drawn from the
Bivariate Gaussian distribution,
with standard deviations sigma_x
and sigma_y
and correlation coefficient rho
.
The correlation coefficient must be in the range $-1 \leq \rho \leq 1$.
rng |
a NcmRNG |
|
sigma_x |
standard deviation |
|
sigma_y |
standard deviation |
|
rho |
correlation coefficient |
|
x |
random number from the Bivariate Gaussian distribution. |
[out] |
y |
random number from the Bivariate Gaussian distribution. |
[out] |
“algorithm”
property “algorithm” char *
The name of the pseudo random number algorithm to be used from GNU Scientific Library (GSL). A list of the available algorithms can be find here.
Owner: NcmRNG
Flags: Read / Write / Construct
Default value: "mt19937"
“seed”
property “seed” gulong
Pseudo random number algorithm seed.
Owner: NcmRNG
Flags: Read / Write