<< randvar NISP polychaos >>

NISP >> NISP > setrandvar

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=setrandvar_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)

Set the type of the sampling to name and set the number of simulations to np. The value of name must be one of the available samplings in setrandvar_buildsample.

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.

The "SmolyakGauss", "SmolyakTrapeze", "SmolyakFejer", "SmolyakClenshawCurtis" samplings are sparse grids. The idea of the algorithm is to use a Smolyak construction of a multivariate quadrature formula on the basis of one-dimensional quadrature formulas in a tensor product setting.

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

  • "MonteCarlo"

    In that case, np is the number of experiments. This sampling is a simple random sampling.

  • "Lhs"

    In that case, np is the number of experiments. This sampling is a Centered Latin Hypercube Sampling, which is well suited for numerical integration. This is different from the classical Lating Hypercube Sampling, which can be produced with nisp_buildlhs.

  • "QmcSobol"

    In that case, np is the number of experiments. This sampling is a Quasi-Monte-Carlo sampling based on the Sobol sequence.

  • "Quadrature"

    This sampling is a multi-dimensional tensor product quadrature of 1-dimensional quadrature formulas defined on the unit interval [0,1]. In that case, the number of experiments is (np+1)^nx, where nx is the number of input arguments.

    The random variables must be normalized.

  • "Petras"

    This sampling is an sparse tensor product quadrature based on the Smolyak algorithm by Knut Petras.

    In that case, np is the maximum degree of the chaos polynomial that we can compute. The value of np must be lower or equal to 40. The random variables must be normalized.

  • "SmolyakGauss"

    This sampling computes a multi-dimensional sparse grid based on a Gauss one-dimensional formula.

  • "SmolyakTrapeze"

    This sampling computes a multi-dimensional sparse grid based on a Trapezoidal one-dimensional formula.

  • "SmolyakFejer"

    This sampling computes a multi-dimensional sparse grid based on a Fejer one-dimensional formula.

  • "SmolyakClenshawCurtis"

    This sampling computes a multi-dimensional sparse grid based on a Clenshaw-Curtis one-dimensional formula. This one-dimensional formula uses absissas based on the roots of Chebyshev polynomials.

setrandvar_buildsample(srv,"LhsMaxMin",np,ntry)

Builds a sampling with LhsMaxMin sampling with np simulations. The sampling requires to generate ntry intermediate centered "Lhs" samplings. The sampling which maximizes the minium distance between design points is kept, and the others are ignored.

Methods: Miscellaneous

setrandvar_save(srv,file)

Save the set into the file.

The file can be used to create a new setrandvar variable, with the srv2=setrandvar_new(file) calling sequence. This can be useful in order to build a sample in a first session, save the sample on the disk and use it in another session.

The file is made of two parts: the header and the body.

In the header, the first character of each line is "#". This header describes the body of the file, i.e. the type of sampling (e.g. "Petras"), the number of simulations np, the number of variables nx, the maximum degree of the quadrature (if this can be applied), the type of each distribution (e.g. "Normale") and its parameters (e.g. the actual mean and standard deviation).

The body of the file is a np-by-(nx+1) matrix of doubles, where np is the number of simulations and nx is the number of variables. Each row of the body of the file corresponds to a sample. The columns 1, 2, ..., nx of the body of the file contains the value of the variables and the column nx+1 contains the weight of the sample in the integration. For quadrature designs (e.g. Petras), the weights are non equal, and are all equal to 1/np for other designs (e.g. Monte-Carlo, LHS).

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 a centered Lhs (which is different from the 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)

Example: Save a design

In the following example, we create a Petras sampling for 751 samples in dimension 3.

nx = 3;
srvx=setrandvar_new( nx);
degre = 9;
setrandvar_buildsample(srvx,"Petras",degre);
filename=fullfile(TMPDIR,"PetrasDesign.txt");
setrandvar_save(srvx,filename);
path = nisp_getpath();
editor(filename);
setrandvar_destroy(srvx);

Bibliography

Asymptotically minimal Smolyak cubature, Knut Petras, 2000

Fast Calculation of Coefficients in the Smolyak Algorithm, Knut Petras, Numerical Algorithms, Volume 26, Number 2 (2001), 93-109

Paul Bratley, Bennett Fox, Algorithm 659: Implementing Sobol's Quasirandom Sequence Generator, ACM Transactions on Mathematical Software, Volume 14, Number 1, March 1988, pages 88-100.

Bennett Fox, Algorithm 647: Implementation and Relative Efficiency of Quasirandom Sequence Generators, ACM Transactions on Mathematical Software, Volume 12, Number 4, December 1986, pages 362-376.

gss: General Smoothing Splines. Chong Gu, R Package, 2012. A comprehensive package for structural multivariate function estimation using smoothing splines.

Authors

Copyright (C) 2012 - Michael Baudin

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

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


Report an issue
<< randvar NISP polychaos >>