umontreal.iro.lecuyer.randvarmulti
Class MultinormalPCAGen
- java.lang.Object
-
- umontreal.iro.lecuyer.randvarmulti.RandomMultivariateGen
-
- umontreal.iro.lecuyer.randvarmulti.MultinormalGen
-
- umontreal.iro.lecuyer.randvarmulti.MultinormalPCAGen
-
public class MultinormalPCAGen extends MultinormalGen
ExtendsMultinormalGenfor a multivariate normal distribution, generated via the method of principal components analysis (PCA) of the covariance matrix. The covariance matrix Σ is decomposed (by the constructor) as Σ = VΛVt where V is an orthogonal matrix and Λ is the diagonal matrix made up of the eigenvalues of Σ. Vt is the transpose matrix of V. The eigenvalues are ordered from the largest (λ1) to the smallest (λd). The random multinormal vector X is generated viaX = μ + AZ,where A = V()1/2, and Z is a d-dimensional vector of independent standard normal random variates. The decomposition method uses the SingularValueDecomposition class in colt.
-
-
Constructor Summary
Constructors Constructor and Description MultinormalPCAGen(NormalGen gen1, double[] mu, double[][] sigma)Equivalent toMultinormalPCAGen(gen1, mu, new DenseDoubleMatrix2D(sigma)).MultinormalPCAGen(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 static DoubleMatrix2DdecompPCA(double[][] sigma)Computes the decomposition sigma = Σ = VΛVt.static DoubleMatrix2DdecompPCA(DoubleMatrix2D sigma)Computes the decomposition sigma = Σ = VΛVt.double[]getLambda()Returns the eigenvalues of Σ in decreasing order.static double[]getLambda(DoubleMatrix2D sigma)Computes and returns the eigenvalues of sigma in decreasing order.DoubleMatrix2DgetPCADecompSigma()Returns the matrix A = V()1/2 of this object.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 PCA 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
-
MultinormalPCAGen
public MultinormalPCAGen(NormalGen gen1, double[] mu, double[][] sigma)
Equivalent toMultinormalPCAGen(gen1, mu, new DenseDoubleMatrix2D(sigma)).
-
MultinormalPCAGen
public MultinormalPCAGen(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 semi-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
-
decompPCA
public static DoubleMatrix2D decompPCA(double[][] sigma)
Computes the decomposition sigma = Σ = VΛVt. Returns A = V()1/2.
-
decompPCA
public static DoubleMatrix2D decompPCA(DoubleMatrix2D sigma)
Computes the decomposition sigma = Σ = VΛVt. Returns A = V()1/2.
-
getPCADecompSigma
public DoubleMatrix2D getPCADecompSigma()
Returns the matrix A = V()1/2 of this object.- Returns:
- the PCA square root of the covariance matrix
-
getLambda
public static double[] getLambda(DoubleMatrix2D sigma)
Computes and returns the eigenvalues of sigma in decreasing order.
-
getLambda
public double[] getLambda()
Returns the eigenvalues of Σ in decreasing order.
-
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, 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 PCA decomposition of Σ. The resulting vector is put into p. Note that this static method will be very slow for large dimensions, because it recomputes the singular value decomposition at every call. It is therefore recommended to use a MultinormalPCAGen 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 static void nextPoint(NormalGen gen1, double[] mu, double[][] sigma, double[] p)
Equivalent tonextPoint(gen1, mu, new DenseDoubleMatrix2D(sigma), p).
-
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