Nom

randvar — A class to manage a random variable.

SYNOPSIS

tokenmatrix = randvar_tokens () 
nb = randvar_size () 
rv = randvar_new ( name , a , b ) 
rv = randvar_new ( name , a ) 
rv = randvar_new ( name ) 
randvar_destroy ( rv ) 
value = randvar_getvalue ( rv ) 
value = randvar_getvalue ( rv , rv2 , value2 ) 
randvar_getlog ( rv ) 

Description

This class manages a random variable.

The randvar_new function allows to create a new random variable. The randvar_destroy function allows to destroy an existing random variable. The type of random variable is chosen at the creation of the random variable to the randvar_new function. Several random variable types are available, including Normal and Uniform variables (see below for a complete list). Once a random variable is created, the randvar_getvalue function allows to generate random numbers from the associated distribution function.

The randvar_new function returns a token which is a unique identifier for the new random variable. Indeed, when a new random variable is created, a counter is updated which corresponds to the returned token. This way, each token is unique and can correspond only to one single random variable.

The functions randvar_tokens and randvar_size allow to manage the random variables which have already been created. The function randvar_size returns the number of random variables, while the randvar_tokens function returns the list of current random variables.

Functions

The following functions are available.

tokenmatrix = setrandvar_tokens ()

Returns a 1x(n) matrix containing the tokens of current sets, where n is the number of sets.

n = randvar_size ()

Returns the number of random variables

rv = randvar_new ( name )

Returns a new random variable rv which corresponds to the distribution function given by name, with default parameters.

The following is the list of possible values for the name input argument.

  • "Normale"
  • "Uniforme"
  • "Exponentielle"
  • "LogNormale"
  • "LogUniforme"

rv = randvar_new ( name , a )

Returns a new random variable rv with first parameter a.

Each type of random variable is associated with a specific distribution function, which depends on given parameters. If the randvar_new function does not receive these parameters, default values are used. While some distribution function require 1 parameter, some other distribution functions require two parameters. This implies that, if the parameters are given to the randvar_new function, the type of distribution function must be consistent with the number of given parameters. For example, the Exponential distribution can only be associated with 0 (i.e. default) parameter or 1 parameter (and not 2 parameter). Another example is the Normal distribution function, which can only be associated with 0 (i.e. default) parameter or 2 parameters (and not 1 parameter). Please read the User Manual to get more information on the distribution functions used in the randvar class.

rv = randvar_new ( name , a , b )

Returns a new random variable rv with first parameter a and second parameter b.

randvar_destroy ( rv )

Destroys the current random variable.

randvar getlog ( rv )

Prints a log for the current random variable.

value = randvar getvalue ( rv )

Returns a random value from the distribution function of the current random variable.

value = randvar getvalue ( rv , rv2 , value2 )

Rreturns a random value from the distribution function of the random variable rv by transformation of value2 from the distribution function of random variable rv2.

Example

In the following example, we call the randvar_new function in order to create a Normal random variable with mean 1.0 and standard deviation 0.5. Then, we perform a loop so that we get 1000 values from this random variable. In order to check that these values are associated with a Normal distribution function, we compute the mean and variance and check that this corresponds to the expected results. Finally, the random variable is destroyed with the randvar_destroy function.

nisp_initseed ( 0 );
mu = 1.0;
sigma = 0.5;
rv = randvar_new("Normale" , mu , sigma);
nbshots = 1000;
values = zeros(nbshots);
for i=1:nbshots
  values(i) = randvar_getvalue(rv);
end
mymean = mean (values);
myvariance = variance (values);
randvar_destroy(rv);

TODO

  • other distribution functions

Bibliography

TODO

Authors

Jean-Marc Martinez, 2009, CEA

Michael Baudin, 2009, Digiteo