Class CorrelatedRandomVectorGenerator
- java.lang.Object
-
- org.spaceroots.mantissa.random.CorrelatedRandomVectorGenerator
-
- All Implemented Interfaces:
- java.io.Serializable, RandomVectorGenerator
public class CorrelatedRandomVectorGenerator extends java.lang.Object implements java.io.Serializable, RandomVectorGenerator
This class allows to generate random vectors with correlated components.Random vectors with correlated components are built by combining the uncorrelated components of another random vector in such a way the resulting correlations are the ones specified by a positive definite covariance matrix.
Sometimes, the covariance matrix for a given simulation is not strictly positive definite. This means that the correlations are not all independant from each other. In this case, however, the non strictly positive elements found during the Cholesky decomposition of the covariance matrix should not be negative either, they should be null. This implies that rather than computing
C = L.LtwhereCis the covariance matrix andLis a lower-triangular matrix, we computeC = B.BtwhereBis a rectangular matrix having more rows than columns. The number of columns ofBis the rank of the covariance matrix, and it is the dimension of the uncorrelated random vector that is needed to compute the component of the correlated vector. This class does handle this situation automatically.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description CorrelatedRandomVectorGenerator(double[] mean, SymetricalMatrix covariance, NormalizedRandomGenerator generator)Simple constructor.CorrelatedRandomVectorGenerator(SymetricalMatrix covariance, NormalizedRandomGenerator generator)Simple constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description NormalizedRandomGeneratorgetGenerator()Get the underlying normalized components generator.intgetRank()Get the rank of the covariance matrix.MatrixgetRootMatrix()Get the root of the covariance matrix.double[]nextVector()Generate a correlated random vector.
-
-
-
Constructor Detail
-
CorrelatedRandomVectorGenerator
public CorrelatedRandomVectorGenerator(double[] mean, SymetricalMatrix covariance, NormalizedRandomGenerator generator) throws NotPositiveDefiniteMatrixExceptionSimple constructor.Build a correlated random vector generator from its mean vector and covariance matrix.
- Parameters:
mean- expected mean values for all componentscovariance- covariance matrixgenerator- underlying generator for uncorrelated normalized components- Throws:
java.lang.IllegalArgumentException- if there is a dimension mismatch between the mean vector and the covariance matrixNotPositiveDefiniteMatrixException- if the covariance matrix is not strictly positive definite
-
CorrelatedRandomVectorGenerator
public CorrelatedRandomVectorGenerator(SymetricalMatrix covariance, NormalizedRandomGenerator generator) throws NotPositiveDefiniteMatrixException
Simple constructor.Build a null mean random correlated vector generator from its covariance matrix.
- Parameters:
covariance- covariance matrixgenerator- underlying generator for uncorrelated normalized components- Throws:
NotPositiveDefiniteMatrixException- if the covariance matrix is not strictly positive definite
-
-
Method Detail
-
getRootMatrix
public Matrix getRootMatrix()
Get the root of the covariance matrix. The root is the matrixBsuch thatB.Btis equal to the covariance matrix- Returns:
- root of the square matrix
-
getGenerator
public NormalizedRandomGenerator getGenerator()
Get the underlying normalized components generator.- Returns:
- underlying uncorrelated components generator
-
getRank
public int getRank()
Get the rank of the covariance matrix. The rank is the number of independant rows in the covariance matrix, it is also the number of columns of the rectangular matrix of the factorization.- Returns:
- rank of the square matrix.
-
nextVector
public double[] nextVector()
Generate a correlated random vector.- Specified by:
nextVectorin interfaceRandomVectorGenerator- Returns:
- a random vector as an array of double. The returned array is created at each call, the caller can do what it wants with it.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG