G01 Chapter Contents
G01 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentG01LBF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

G01LBF returns a number of values of the probability density function (PDF), or its logarithm, for the multivariate Normal (Gaussian) distribution.

## 2  Specification

 SUBROUTINE G01LBF ( ILOG, K, N, X, LDX, XMU, IULD, SIG, LDSIG, PDF, RANK, IFAIL)
 INTEGER ILOG, K, N, LDX, IULD, LDSIG, RANK, IFAIL REAL (KIND=nag_wp) X(LDX,*), XMU(N), SIG(LDSIG,*), PDF(K)

## 3  Description

The probability density function, $f\left(X:\mu ,\Sigma \right)$ of an $n$-dimensional multivariate Normal distribution with mean vector $\mu$ and $n$ by $n$ variance-covariance matrix $\Sigma$, is given by
 $fX:μ,Σ = 2⁢π n ⁢ Σ -1/2 ⁢ exp -12 ⁢ X-μT ⁢ Σ-1 ⁢ X-μ .$
If the variance-covariance matrix, $\Sigma$, is not of full rank then the probability density function, is calculated as
 $fX:μ,Σ = 2⁢π r ⁢ pdet Σ -1/2 ⁢ exp -12 ⁢ X-μT ⁢ Σ- ⁢ X-μ$
where $\text{pdet}\left(\Sigma \right)$ is the pseudo-determinant, ${\Sigma }^{-}$ a generalized inverse of $\Sigma$ and $r$ its rank.
G01LBF evaluates the PDF at $k$ points with a single call.

None.

## 5  Parameters

1:     $\mathrm{ILOG}$ – INTEGERInput
On entry: the value of ILOG determines whether the logarithmic value is returned in PDF.
${\mathbf{ILOG}}=0$
$f\left(X:\mu ,\Sigma \right)$, the probability density function is returned.
${\mathbf{ILOG}}=1$
$\mathrm{log}\left(f\left(X:\mu ,\Sigma \right)\right)$, the logarithm of the probability density function is returned.
Constraint: ${\mathbf{ILOG}}=0$ or $1$.
2:     $\mathrm{K}$ – INTEGERInput
On entry: $k$, the number of points the PDF is to be evaluated at.
Constraint: ${\mathbf{K}}\ge 0$.
3:     $\mathrm{N}$ – INTEGERInput
On entry: $n$, the number of dimensions.
Constraint: ${\mathbf{N}}\ge 2$.
4:     $\mathrm{X}\left({\mathbf{LDX}},*\right)$ – REAL (KIND=nag_wp) arrayInput
Note: the second dimension of the array X must be at least ${\mathbf{K}}$.
On entry: $X$, the matrix of $k$ points at which to evaluate the probability density function, with the $i$th dimension for the $j$th point held in ${\mathbf{X}}\left(i,j\right)$.
5:     $\mathrm{LDX}$ – INTEGERInput
On entry: the first dimension of the array X as declared in the (sub)program from which G01LBF is called.
Constraint: ${\mathbf{LDX}}\ge {\mathbf{N}}$.
6:     $\mathrm{XMU}\left({\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayInput
On entry: $\mu$, the mean vector of the multivariate Normal distribution.
7:     $\mathrm{IULD}$ – INTEGERInput
On entry: indicates the form of $\Sigma$ and how it is stored in SIG.
${\mathbf{IULD}}=1$
SIG holds the lower triangular portion of $\Sigma$.
${\mathbf{IULD}}=2$
SIG holds the upper triangular portion of $\Sigma$.
${\mathbf{IULD}}=3$
$\Sigma$ is a diagonal matrix and SIG only holds the diagonal elements.
${\mathbf{IULD}}=4$
SIG holds the lower Cholesky decomposition, $L$ such that $L{L}^{\mathrm{T}}=\Sigma$.
${\mathbf{IULD}}=5$
SIG holds the upper Cholesky decomposition, $U$ such that ${U}^{\mathrm{T}}U=\Sigma$.
Constraint: ${\mathbf{IULD}}=1$, $2$, $3$, $4$ or $5$.
8:     $\mathrm{SIG}\left({\mathbf{LDSIG}},*\right)$ – REAL (KIND=nag_wp) arrayInput
Note: the second dimension of the array SIG must be at least ${\mathbf{N}}$.
On entry: information defining the variance-covariance matrix, $\Sigma$.
${\mathbf{IULD}}=1$ or $2$
SIG must hold the lower or upper portion of $\Sigma$, with ${\Sigma }_{ij}$ held in ${\mathbf{SIG}}\left(i,j\right)$. The supplied variance-covariance matrix must be positive semidefinite.
${\mathbf{IULD}}=3$
$\Sigma$ is a diagonal matrix and the $i$th diagonal element, ${\Sigma }_{ii}$, must be held in ${\mathbf{SIG}}\left(1,i\right)$
${\mathbf{IULD}}=4$ or $5$
SIG must hold $L$ or $U$, the lower or upper Cholesky decomposition of $\Sigma$, with ${L}_{ij}$ or ${U}_{ij}$ held in ${\mathbf{SIG}}\left(i,j\right)$, depending on the value of IULD. No check is made that $L{L}^{\mathrm{T}}$ or ${U}^{\mathrm{T}}U$ is a valid variance-covariance matrix. The diagonal elements of the supplied $L$ or $U$ must be greater than zero
9:     $\mathrm{LDSIG}$ – INTEGERInput
On entry: the first dimension of the array SIG as declared in the (sub)program from which G01LBF is called.
Constraints:
• if ${\mathbf{IULD}}=3$, ${\mathbf{LDSIG}}\ge 1$;
• otherwise ${\mathbf{LDSIG}}\ge {\mathbf{N}}$.
10:   $\mathrm{PDF}\left({\mathbf{K}}\right)$ – REAL (KIND=nag_wp) arrayOutput
On exit: $f\left(X:\mu ,\Sigma \right)$ or $\mathrm{log}\left(f\left(X:\mu ,\Sigma \right)\right)$ depending on the value of ILOG.
11:   $\mathrm{RANK}$ – INTEGEROutput
On exit: $r$, rank of $\Sigma$.
12:   $\mathrm{IFAIL}$ – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{1}}$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}=11$
On entry, ${\mathbf{ILOG}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ILOG}}=0$ or $1$.
${\mathbf{IFAIL}}=21$
On entry, ${\mathbf{K}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{K}}\ge 0$.
${\mathbf{IFAIL}}=31$
On entry, ${\mathbf{N}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{N}}\ge 2$.
${\mathbf{IFAIL}}=51$
On entry, ${\mathbf{LDX}}=〈\mathit{\text{value}}〉$ and ${\mathbf{N}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{LDX}}\ge {\mathbf{N}}$.
${\mathbf{IFAIL}}=71$
On entry, ${\mathbf{IULD}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{IULD}}=1$, $2$, $3$, $4$ or $5$.
${\mathbf{IFAIL}}=81$
On entry, $\Sigma$ is not positive semidefinite.
${\mathbf{IFAIL}}=82$
On entry, at least one diagonal element of $\Sigma$ is less than or equal to $0$.
${\mathbf{IFAIL}}=83$
On entry, $\Sigma$ is not positive definite and eigenvalue decomposition failed.
${\mathbf{IFAIL}}=91$
On entry, ${\mathbf{LDSIG}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{IULD}}=3$, ${\mathbf{LDSIG}}\ge 1$.
${\mathbf{IFAIL}}=92$
On entry, ${\mathbf{LDSIG}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{IULD}}\ne 3$, ${\mathbf{LDSIG}}\ge {\mathbf{N}}$.
${\mathbf{IFAIL}}=-99$
See Section 3.8 in the Essential Introduction for further information.
${\mathbf{IFAIL}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.7 in the Essential Introduction for further information.
${\mathbf{IFAIL}}=-999$
Dynamic memory allocation failed.
See Section 3.6 in the Essential Introduction for further information.

Not applicable.

## 8  Parallelism and Performance

G01LBF is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
G01LBF makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

None.

## 10  Example

This example prints the value of the multivariate Normal PDF at a number of different points.

### 10.1  Program Text

Program Text (g01lbfe.f90)

### 10.2  Program Data

Program Data (g01lbfe.d)

### 10.3  Program Results

Program Results (g01lbfe.r)