g05rz sets up a reference vector and generates an array of pseudorandom numbers from a multivariate Normal distribution with mean vector and covariance matrix .
Syntax
C# |
---|
public static void g05rz( int mode, int n, int m, double[] xmu, double[,] c, double[] r, G05..::..G05State g05state, double[,] x, out int ifail ) |
Visual Basic |
---|
Public Shared Sub g05rz ( _ mode As Integer, _ n As Integer, _ m As Integer, _ xmu As Double(), _ c As Double(,), _ r As Double(), _ g05state As G05..::..G05State, _ x As Double(,), _ <OutAttribute> ByRef ifail As Integer _ ) |
Visual C++ |
---|
public: static void g05rz( int mode, int n, int m, array<double>^ xmu, array<double,2>^ c, array<double>^ r, G05..::..G05State^ g05state, array<double,2>^ x, [OutAttribute] int% ifail ) |
F# |
---|
static member g05rz : mode : int * n : int * m : int * xmu : float[] * c : float[,] * r : float[] * g05state : G05..::..G05State * x : float[,] * ifail : int byref -> unit |
Parameters
- mode
- Type: System..::..Int32On entry: a code for selecting the operation to be performed by the method.
- Set up reference vector only.
- Generate variates using reference vector set up in a prior call to g05rz.
- Set up reference vector and generate variates.
Constraint: , or .
- n
- Type: System..::..Int32On entry: , the number of random variates required.Constraint: .
- m
- Type: System..::..Int32On entry: , the number of dimensions of the distribution.Constraint: .
- xmu
- Type: array<System..::..Double>[]()[][]An array of size [m]On entry: , the vector of means of the distribution.
- c
- Type: array<System..::..Double,2>[,](,)[,][,]An array of size [dim1, m]Note: dim1 must satisfy the constraint:On entry: the covariance matrix of the distribution. Only the upper triangle need be set.Constraint: must be positive semidefinite to machine precision.
- r
- Type: array<System..::..Double>[]()[][]An array of size [lr]On entry: if , the reference vector as set up by g05rz in a previous call with or .On exit: if or , the reference vector that can be used in subsequent calls to g05rz with .
- g05state
- Type: NagLibrary..::..G05..::..G05StateAn Object of type G05.G05State.
- x
- Type: array<System..::..Double,2>[,](,)[,][,]An array of size [dim1, _tdx]Note: dim1 must satisfy the constraint:
- if or , ;
- if or , .
On exit: the array of pseudorandom multivariate Normal vectors generated by the method.Two possible storage orders are available. If or then holds the th dimension for the th variate. If or this ordering is reversed and holds the th dimension for the th variate.
- ifail
- Type: System..::..Int32%On exit: unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).
Description
When the covariance matrix is nonsingular (i.e., strictly positive definite), the distribution has probability density function
where is the number of dimensions, is the covariance matrix, is the vector of means and is the vector of positions.
Covariance matrices are symmetric and positive semidefinite. Given such a matrix , there exists a lower triangular matrix such that . is not unique, if is singular.
g05rz decomposes to find such an . It then stores , and in the reference vector which is used to generate a vector of independent standard Normal pseudorandom numbers. It then returns the vector , which has the required multivariate Normal distribution.
It should be noted that this method will work with a singular covariance matrix , provided is positive semidefinite, despite the fact that the above formula for the probability density function is not valid in that case. Wilkinson (1965) should be consulted if further information is required.
One of the initialization methods (G05KFF not in this release) (for a repeatable sequence if computed sequentially) or (G05KGF not in this release) (for a non-repeatable sequence) must be called prior to the first call to g05rz.
References
Knuth D E (1981) The Art of Computer Programming (Volume 2) (2nd Edition) Addison–Wesley
Wilkinson J H (1965) The Algebraic Eigenvalue Problem Oxford University Press, Oxford
Error Indicators and Warnings
Errors or warnings detected by the method:
Some error messages may refer to parameters that are dropped from this interface
(LDC, LDX) In these
cases, an error in another parameter has usually caused an incorrect value to be inferred.
-
On entry, .
Constraint: , or .
-
On entry, .
Constraint: .
-
On entry, .
Constraint: .
-
On entry, the covariance matrix is not positive semidefinite to machine precision.
-
On entry, and .
Constraint: .
-
On entry, lr is not large enough, : minimum length required .
-
On entry, state vector has been corrupted or not initialized.
-
On entry, and .
Constraint: .On entry, and .
Constraint: .
-
On entry, and .
Constraint: or .
-
On entry, and .
Constraint: or .
Accuracy
Not applicable.
Parallelism and Performance
None.
Further Comments
The time taken by g05rz is of order .
It is recommended that the diagonal elements of should not differ too widely in order of magnitude. This may be achieved by scaling the variables if necessary. The actual matrix decomposed is , where is a diagonal matrix with small positive diagonal elements. This ensures that, even when is singular, or nearly singular, the Cholesky factor corresponds to a positive definite covariance matrix that agrees with within machine precision.