umontreal.iro.lecuyer.randvarmulti
Class MultinormalCholeskyGen
- java.lang.Object
-
- umontreal.iro.lecuyer.randvarmulti.RandomMultivariateGen
-
- umontreal.iro.lecuyer.randvarmulti.MultinormalGen
-
- umontreal.iro.lecuyer.randvarmulti.MultinormalCholeskyGen
-
public class MultinormalCholeskyGen extends MultinormalGen
ExtendsMultinormalGenfor a multivariate normal distribution, generated via a Cholesky decomposition of the covariance matrix. The covariance matrix Σ is decomposed (by the constructor) as Σ = AAt where A is a lower-triangular matrix (this is the Cholesky decomposition), and X is generated viaX = μ + AZ,where Z is a d-dimensional vector of independent standard normal random variates, and At is the transpose of A. The covariance matrix Σ must be positive-definite, otherwise the Cholesky decomposition will fail. The decomposition method uses the CholeskyDecomposition class in colt.
-
-
Constructor Summary
Constructors Constructor and Description MultinormalCholeskyGen(NormalGen gen1, double[] mu, double[][] sigma)Equivalent toMultinormalCholeskyGen(gen1, mu, new DenseDoubleMatrix2D(sigma)).MultinormalCholeskyGen(NormalGen gen1, double[] mu, DoubleMatrix2D sigma)Constructs a multinormal generator with mean vector mu and covariance matrix sigma.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description DoubleMatrix2DgetCholeskyDecompSigma()Returns the lower-triangular matrix A in the Cholesky decomposition of Σ.voidnextPoint(double[] p)Generates a point from this multinormal distribution.static voidnextPoint(NormalGen gen1, double[] mu, double[][] sigma, double[] p)Equivalent tonextPoint(gen1, mu, new DenseDoubleMatrix2D(sigma), p).static voidnextPoint(NormalGen gen1, double[] mu, DoubleMatrix2D sigma, double[] p)Generates a d-dimensional vector from the multinormal distribution with mean vector mu and covariance matrix sigma, using the one-dimensional normal generator gen1 to generate the coordinates of Z, and using the Cholesky decomposition of Σ.voidsetSigma(DoubleMatrix2D sigma)Sets the covariance matrix Σ of this multinormal generator to sigma (and recomputes A).-
Methods inherited from class umontreal.iro.lecuyer.randvarmulti.MultinormalGen
getMu, getMu, getSigma, setMu, setMu
-
Methods inherited from class umontreal.iro.lecuyer.randvarmulti.RandomMultivariateGen
getDimension, getStream, nextArrayOfPoints, setStream
-
-
-
-
Constructor Detail
-
MultinormalCholeskyGen
public MultinormalCholeskyGen(NormalGen gen1, double[] mu, double[][] sigma)
Equivalent toMultinormalCholeskyGen(gen1, mu, new DenseDoubleMatrix2D(sigma)).- Parameters:
gen1- the one-dimensional generatormu- the mean vector.sigma- the covariance matrix.- Throws:
java.lang.NullPointerException- if any argument is null.java.lang.IllegalArgumentException- if the length of the mean vector is incompatible with the dimensions of the covariance matrix.
-
MultinormalCholeskyGen
public MultinormalCholeskyGen(NormalGen gen1, double[] mu, DoubleMatrix2D sigma)
Constructs a multinormal generator with mean vector mu and covariance matrix sigma. The mean vector must have the same length as the dimensions of the covariance matrix, which must be symmetric and positive-definite. If any of the above conditions is violated, an exception is thrown. The vector Z is generated by calling d times the generator gen1, which must be a standard normal 1-dimensional generator.- Parameters:
gen1- the one-dimensional generatormu- the mean vector.sigma- the covariance matrix.- Throws:
java.lang.NullPointerException- if any argument is null.java.lang.IllegalArgumentException- if the length of the mean vector is incompatible with the dimensions of the covariance matrix.
-
-
Method Detail
-
getCholeskyDecompSigma
public DoubleMatrix2D getCholeskyDecompSigma()
Returns the lower-triangular matrix A in the Cholesky decomposition of Σ.- Returns:
- the Cholesky decomposition of the covariance matrix.
-
setSigma
public void setSigma(DoubleMatrix2D sigma)
Sets the covariance matrix Σ of this multinormal generator to sigma (and recomputes A).- Parameters:
sigma- the new covariance matrix.- Throws:
java.lang.IllegalArgumentException- if sigma has incorrect dimensions.
-
nextPoint
public static void nextPoint(NormalGen gen1, double[] mu, double[][] sigma, double[] p)
Equivalent tonextPoint(gen1, mu, new DenseDoubleMatrix2D(sigma), p).
-
nextPoint
public static void nextPoint(NormalGen gen1, double[] mu, DoubleMatrix2D sigma, double[] p)
Generates a d-dimensional vector from the multinormal distribution with mean vector mu and covariance matrix sigma, using the one-dimensional normal generator gen1 to generate the coordinates of Z, and using the Cholesky decomposition of Σ. The resulting vector is put into p. Note that this static method will be very slow for large dimensions, since it computes the Cholesky decomposition at every call. It is therefore recommended to use a MultinormalCholeskyGen object instead, if the method is to be called more than once.- Parameters:
p- the array to be filled with the generated point.- Throws:
java.lang.IllegalArgumentException- if the one-dimensional normal generator uses a normal distribution with μ not equal to 0, or σ not equal to 1.java.lang.IllegalArgumentException- if the length of the mean vector is different from the dimensions of the covariance matrix, or if the covariance matrix is not symmetric and positive-definite.java.lang.NullPointerException- if any argument is null.
-
nextPoint
public void nextPoint(double[] p)
Generates a point from this multinormal distribution. This is much faster than the static method as it computes the singular value decomposition matrix only once in the constructor.- Overrides:
nextPointin classMultinormalGen- Parameters:
p- the array to be filled with the generated point
-
-
DMelt 3.0 © DataMelt by jWork.ORG