/** * Builds a correlated random vector generator from its mean * vector and covariance matrix. * * @param mean Expected mean values for all components. * @param covariance Covariance matrix. * @param small Diagonal elements threshold under which column are * considered to be dependent on previous ones and are discarded * @param generator underlying generator for uncorrelated normalized * components. * @throws org.apache.commons.math3.linear.NonPositiveDefiniteMatrixException * if the covariance matrix is not strictly positive definite. * @throws DimensionMismatchException if the mean and covariance * arrays dimensions do not match. */ public CorrelatedRandomVectorGenerator(double[] mean, RealMatrix covariance, double small, NormalizedRandomGenerator generator) { int order = covariance.getRowDimension(); if (mean.length != order) { throw new DimensionMismatchException(mean.length, order); } this.mean = mean.clone(); final RectangularCholeskyDecomposition decomposition = new RectangularCholeskyDecomposition(covariance, small); root = decomposition.getRootMatrix(); this.generator = generator; normalized = new double[decomposition.getRank()]; }
/** * Builds a null mean random correlated vector generator from its * covariance matrix. * * @param covariance Covariance matrix. * @param small Diagonal elements threshold under which column are * considered to be dependent on previous ones and are discarded. * @param generator Underlying generator for uncorrelated normalized * components. * @throws org.apache.commons.math3.linear.NonPositiveDefiniteMatrixException * if the covariance matrix is not strictly positive definite. */ public CorrelatedRandomVectorGenerator(RealMatrix covariance, double small, NormalizedRandomGenerator generator) { int order = covariance.getRowDimension(); mean = new double[order]; for (int i = 0; i < order; ++i) { mean[i] = 0; } final RectangularCholeskyDecomposition decomposition = new RectangularCholeskyDecomposition(covariance, small); root = decomposition.getRootMatrix(); this.generator = generator; normalized = new double[decomposition.getRank()]; }