/** * 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()]; }
/** * Return true if the given matrix is symmetric positive definite--that is, * if it would make a valid covariance matrix. */ @SuppressWarnings({"BooleanMethodIsAlwaysInverted"}) public static boolean isPositiveDefinite(TetradMatrix matrix) { // DoubleMatrix2D _matrix = new DenseDoubleMatrix2D(matrix.toArray()); // System.out.println(MatrixUtils.toString(new CholeskyDecomposition(_matrix).getL().toArray())); // return new CholeskyDecomposition(_matrix).isSymmetricPositiveDefinite(); try { new RectangularCholeskyDecomposition(matrix.getRealMatrix()); } catch (NonPositiveDefiniteMatrixException e) { return false; } return true; }
/** * 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()]; }
/** * 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()]; }
/** * 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 = Cloner.clone(mean); final RectangularCholeskyDecomposition decomposition = new RectangularCholeskyDecomposition(covariance, small); root = decomposition.getRootMatrix(); this.generator = generator; normalized = new double[decomposition.getRank()]; }
/** * 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()]; }