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:     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:     K – INTEGERInput
On entry: $k$, the number of points the PDF is to be evaluated at.
Constraint: ${\mathbf{K}}\ge 0$.
3:     N – INTEGERInput
On entry: $n$, the number of dimensions.
Constraint: ${\mathbf{N}}\ge 2$.
4:     X(LDX,$*$) – 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:     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:     XMU(N) – REAL (KIND=nag_wp) arrayInput
On entry: $\mu$, the mean vector of the multivariate Normal distribution.
7:     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:     SIG(LDSIG,$*$) – 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:     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:   PDF(${\mathbf{K}}$) – 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:   RANK – INTEGEROutput
On exit: $r$, rank of $\Sigma$.
12:   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}}$.

Not applicable.

None.

## 9  Example

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

### 9.1  Program Text

Program Text (g01lbfe.f90)

### 9.2  Program Data

Program Data (g01lbfe.d)

### 9.3  Program Results

Program Results (g01lbfe.r)