Nom

setrandvar — A class to manage a set of random variables.

SYNOPSIS

    tokenmatrix = setrandvar_tokens ()
    nb = setrandvar_size ()
    srv = setrandvar_new ( )
    srv = setrandvar_new ( n )
    srv = setrandvar_new ( file )
    setrandvar_destroy ( srv )
    setrandvar_setsample ( srv , name , np )
    setrandvar_setsample ( srv , k , i , value )
    setrandvar_setsample ( srv , k , value )
    setrandvar_setsample ( srv , value )
    setrandvar_save ( srv , file )
    np = setrandvar_getsize ( srv )
    sample = setrandvar_getsample ( srv , k , i )
    sample = setrandvar_getsample ( srv , k )
    sample = setrandvar_getsample ( srv )
    setrandvar_getlog ( srv )
    nx = setrandvar_getdimension ( srv )
    setrandvar_freememory ( srv )
    setrandvar_buildsample ( srv , srv2 )
    setrandvar_buildsample ( srv , name , np )
    setrandvar_buildsample ( srv , name , np , ne )
    setrandvar_addrandvar ( srv , rv )
    

Description

The setrandvar_new function allows to create a new set of random variables. The setrandvar_destroy function allows to destroy an existing set of random variables.

The setrandvar_new function returns a token which is a unique identifier for the new set of random variables. Indeed, when a new set 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 set.

The functions setrandvar_tokens and setrandvar_size allow to manage the sets which have already been created. The function setrandvar_size returns the number of sets, while the setrandvar_tokens function returns the list of current sets.

Functions

The following functions are available.

tokenmatrix = randvar_tokens ()

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

n = setrandvar_size ()

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

srv = setrandvar_new ( )

Creates a new set of random variables.

srv = setrandvar_new ( n )

Creates a new set of n uniformly distributed random variables.

srv = setrandvar_new ( file )

Creates a new set of random variables from an existing file.

setrandvar_destroy ( srv )

Destroys the current object.

setrandvar_setsample ( srv , name , np )

Initialize the number of simulation to np and stores the name of the sampling.

setrandvar_setsample ( srv , k , i , value )

Set the value of the the sample input #i with 1≤ i≤ nx where nx is the number of input random variables of the sample #k with 1≤ k≤ np, where np is the number of simulations.

setrandvar_setsample ( srv , k , value )

Set the sample #k with 1≤ k≤ np, where np is the number of simulations and value is a matrix with size 1 x (nx) where nx is the number of input random variables.

setrandvar_setsample ( srv , value )

Set the experiment matrix, where value is a matrix with size (np) x (nx), where np is the number of experiments and nx is the number of input random variables.

setrandvar_save ( srv , file )

Save the set into the file.

np = setrandvar_getsize ( srv )

Returns the number of experiments of the set random variable

sample = setrandvar_getsample ( srv , k , i )

returns the sample input #i=1,...nx where nx is the number of random variables of the sample #k, where 1≤ k≤ np, where np is the number of experiments.

sample = setrandvar_getsample ( srv , k )

Returns the sample #k as a matrix with size 1 x (nx), where 1≤ k≤ np, np is the number of experiments and nx is the number of input random variables.

sample = setrandvar_getsample ( srv )

Returns the sampling matrix with size (np) x (nx), where np is the number of experiments and nx is the number of input random variables.

setrandvar_getlog ( srv )

Prints out a log of the set of random variables.

nx = setrandvar_getdimension ( srv )

Returns the number of input random variables.

setrandvar_freememory ( srv )

Free the memory of the current set.

setrandvar_buildsample ( srv , srv2 )

Build a sampling from the other set srv2. Uses density transformation methods to produce the sampling for srv, given the sampling of srv2.

setrandvar_buildsample ( srv , name , np )

Build a sampling with sampling method "name" and np experiments. (TODO : clarify the difference between np as experiments and np as degree)

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

  • "MonteCarlo"

    In that case, np is the number of experiments.

  • "Lhs"

    In that case, np is the number of experiments.

  • "QmcSobol"

    In that case, np is the number of experiments.

  • "Quadrature"

    The random variables must be normalized.

  • "Petras"

    In that case, np is the degree of the polynomial which must be lower or equal to 40. The random variables must be normalized.

  • "SmolyakGauss"
  • "SmolyakTrapeze"
  • "SmolyakFejer"
  • "SmolyakClenshawCurtis"
setrandvar_buildsample ( srv , name , np , ne )

Build a sampling with sampling method "name" and np experiments, with selected ne samples.

setrandvar_addrandvar ( srv , rv )

Add the random variable "rv" to the set.

Example

In the following example, we build a Monte-Carlo design of experiments, with 2 input random variables. The first variable is associated with a Normal distribution function and the second variable is associated with a Uniform distribution function. The simulation is based on 1000 experiments.

The function nisp_initseed is used to set the value of the seed to zero, so that the results can be reproduced. The setrandvar_new function is used to create a new set of random variables. Then we create two new random variables with the randvar_new function. These two variables are added to the set with the setrandvar_addrandvar function. The setrandvar_buildsample allows to build the design of experiments, which can be retrieved as matrix with the setrandvar_getsample function. The sampling matrix has np=1000 rows and 2 columns (one for each input variable).

// Test setrandvar_buildsample with ( name , np ) and with MonteCarlo
nisp_initseed ( 0 );
srv = setrandvar_new ( );
rv1 = randvar_new("Normale",1.0,0.5);
rv2 = randvar_new("Uniforme",1.0,2.5);
setrandvar_addrandvar ( srv , rv1 );
setrandvar_addrandvar ( srv , rv2 );
np = 1000;
name = "MonteCarlo";
setrandvar_buildsample ( srv , name , np );
sampling = setrandvar_getsample ( srv );
// Check sampling of random variable #1
mean(sampling(1:np,1))
// Check sampling of random variable #2
mean(sampling(1:np,2))
setrandvar_destroy(srv);
randvar_destroy(rv1);
randvar_destroy(rv2);

Bibliography

TODO

Authors

Jean-Marc Martinez, 2009, CEA

Michael Baudin, 2009, Digiteo