Nom

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

Static Functions

      tokenmatrix = setrandvar_tokens ()
      nb = setrandvar_size ()
    

Creation/Destruction

      srv = setrandvar_new ( )
      srv = setrandvar_new ( n )
      srv = setrandvar_new ( file )
      setrandvar_destroy ( srv )
    

Methods: Configuration

      setrandvar_addrandvar ( srv , rv )
      np = setrandvar_getsize ( srv )
      nx = setrandvar_getdimension ( srv )
    

Methods: Samples

      setrandvar_setsample ( srv , name , np )
      setrandvar_setsample ( srv , k , i , value )
      setrandvar_setsample ( srv , k , value )
      setrandvar_setsample ( srv , value )
      sampling = setrandvar_getsample ( srv , k , i )
      sampling = setrandvar_getsample ( srv , k )
      sampling = setrandvar_getsample ( srv )
      setrandvar_buildsample ( srv , srv2 )
      setrandvar_buildsample ( srv , name , np )
      setrandvar_buildsample ( srv , name , np , ne )
    

Methods: Miscellaneous

      setrandvar_save ( srv , file )
      setrandvar_getlog ( srv )
      setrandvar_freememory ( srv )
    

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 matrix of current tokens.

Static Functions

tokenmatrix = randvar_tokens ()

Returns a 1-by-n matrix of floating point integers representing the current setrandvar tokens, where n is the number of tokens.

n = setrandvar_size ()

Returns a 1-by-1 matrix containing the current number of setrandvar tokens currently in use, where n is the number of tokens.

Creation/Destruction

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.

Methods: Configuration

setrandvar_addrandvar ( srv , rv )

Add the random variable "rv" to the set.

np = setrandvar_getsize ( srv )

Returns the number of experiments of the set random variable

nx = setrandvar_getdimension ( srv )

Returns the number of input random variables.

Methods: Samples

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.

sampling = 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.

sampling = 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.

sampling = setrandvar_getsample ( srv )

Returns the sampling matrix with size np-by-nx, where np is the number of experiments and nx is the number of input random variables.

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 , ntry )

Builds a sampling with sampling method name = "LhsMaxMin" of size np, selected from ntry "Lhs" samples. This function attempts to optimize the sample by maximizing the minium distance between design points.

Methods: Miscellaneous

setrandvar_save ( srv , file )

Save the set into the file.

setrandvar_getlog ( srv )

Prints out a log of the set of random variables.

setrandvar_freememory ( srv )

Free the memory of the current 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).

      nisp_initseed(0);
      rvu1 = randvar_new("Normale",1,3);
      rvu2 = randvar_new("Uniforme",2,3);
      //
      srvu = setrandvar_new();
      setrandvar_addrandvar ( srvu, rvu1);
      setrandvar_addrandvar ( srvu, rvu2);
      //
      np = 5000;
      setrandvar_buildsample(srvu, "MonteCarlo",np);
      sampling = setrandvar_getsample(srvu);
      // Check sampling of random variable #1
      mean(sampling(1:np,1))
      // Check sampling of random variable #2
      mean(sampling(1:np,2))
      //
      scf();
      histplot(50,sampling(:,1));
      xtitle("Empirical histogram of X1");
      scf();
      histplot(50,sampling(:,2));
      xtitle("Empirical histogram of X2");
      //
      // Clean-up
      setrandvar_destroy(srvu);
      randvar_destroy(rvu1);
      randvar_destroy(rvu2);
    

Example: LhsMaxMin design

In the following example, we create a LhsMaxMin sampling.

      srv = setrandvar_new(2);
      np = 1000;
      ntry = 10;
      setrandvar_buildsample ( srv , "LhsMaxMin" , np , ntry );
      sampling = setrandvar_getsample ( srv );
      scf();
      plot(sampling(:,1),sampling(:,2),"bo");
      xtitle("LHS Max Min Design","X1,"X2");
      setrandvar_destroy ( srv )
    

Example: Lhs design

In the following example, we create a Lhs sampling for 10 points in dimension 2. The Lhs design which is provided in this module is not classical: as we can see, the points are in the center of each cell.

      srv = setrandvar_new(2);
      np = 10;
      setrandvar_buildsample ( srv , "Lhs" , np );
      sampling = setrandvar_getsample ( srv );
      scf();
      plot(sampling(:,1),sampling(:,2),"bo");
      xtitle("LHS Design","X1","X2");
      // Add the cuts
      cut = linspace ( 0 , 1 , np + 1 );
      for i = 1 : np + 1
      plot( [cut(i) cut(i)] , [0 1] , "-" )
      end
      for i = 1 : np + 1
      plot( [0 1] , [cut(i) cut(i)] , "-" )
      end
      setrandvar_destroy ( srv )
    

Bibliography

TODO

Authors

Copyright (C) 2008-2011 - CEA - Jean-Marc Martinez

Copyright (C) 2008-2011 - INRIA - Michael Baudin