org.jscience.measure.random
Class CorrelatedRandomVectorGenerator

java.lang.Object
  extended by org.jscience.measure.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.Lt where C is the covariance matrix and L is a lower-triangular matrix, we compute C = B.Bt where B is a rectangular matrix having more rows than columns. The number of columns of B is 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
CorrelatedRandomVectorGenerator(double[] mean, DoubleSymmetricMatrix covariance, RandomGenerator generator)
          Simple constructor.
CorrelatedRandomVectorGenerator(DoubleSymmetricMatrix covariance, RandomGenerator generator)
          Simple constructor.
 
Method Summary
 RandomGenerator getGenerator()
          Get the underlying normalized components generator.
 int getRank()
          Get the rank of the covariance matrix.
 Matrix getRootMatrix()
          Get the root of the covariance matrix.
 double[] nextVector()
          Generate a correlated random vector.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CorrelatedRandomVectorGenerator

public CorrelatedRandomVectorGenerator(double[] mean,
                                       DoubleSymmetricMatrix covariance,
                                       RandomGenerator generator)
                                throws NotPositiveDefiniteMatrixException
Simple constructor.

Build a correlated random vector generator from its mean vector and covariance matrix.

Parameters:
mean - expected mean values for all components
covariance - covariance matrix
generator - underlying generator for uncorrelated normalized components
Throws:
java.lang.IllegalArgumentException - if there is a dimension mismatch between the mean vector and the covariance matrix
NotPositiveDefiniteMatrixException - if the covariance matrix is not strictly positive definite

CorrelatedRandomVectorGenerator

public CorrelatedRandomVectorGenerator(DoubleSymmetricMatrix covariance,
                                       RandomGenerator generator)
                                throws NotPositiveDefiniteMatrixException
Simple constructor.

Build a null mean random correlated vector generator from its covariance matrix.

Parameters:
covariance - covariance matrix
generator - 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 matrix B such that B.Bt is equal to the covariance matrix

Returns:
root of the square matrix

getGenerator

public RandomGenerator 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:
nextVector in interface RandomVectorGenerator
Returns:
a random vector as an array of double. The generator will reuse the same array for each call, in order to save the allocation time, so the user should keep a copy by himself if he needs so.