# NAG C Library Function Document

## 1Purpose

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

## 2Specification

 #include #include
 void nag_multi_normal_pdf_vector (Nag_Boolean ilog, Integer k, Integer n, const double x[], Integer pdx, const double xmu[], Nag_MatrixType iuld, const double sig[], Integer pdsig, double pdf[], Integer *rank, NagError *fail)

## 3Description

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.
nag_multi_normal_pdf_vector (g01lbc) evaluates the PDF at $k$ points with a single call.

None.

## 5Arguments

1:    $\mathbf{ilog}$Nag_BooleanInput
On entry: the value of ilog determines whether the logarithmic value is returned in PDF.
${\mathbf{ilog}}=\mathrm{Nag_FALSE}$
$f\left(X:\mu ,\Sigma \right)$, the probability density function is returned.
${\mathbf{ilog}}=\mathrm{Nag_TRUE}$
$\mathrm{log}\left(f\left(X:\mu ,\Sigma \right)\right)$, the logarithm of the probability density function is returned.
2:    $\mathbf{k}$IntegerInput
On entry: $k$, the number of points the PDF is to be evaluated at.
Constraint: ${\mathbf{k}}\ge 0$.
3:    $\mathbf{n}$IntegerInput
On entry: $n$, the number of dimensions.
Constraint: ${\mathbf{n}}\ge 2$.
4:    $\mathbf{x}\left[\mathit{dim}\right]$const doubleInput
Note: the dimension, dim, of the array x must be at least ${\mathbf{pdx}}×{\mathbf{k}}$.
Where ${\mathbf{X}}\left(i,j\right)$ appears in this document, it refers to the array element ${\mathbf{x}}\left[\left(j-1\right)×{\mathbf{pdx}}+i-1\right]$.
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:    $\mathbf{pdx}$IntegerInput
On entry: the stride separating matrix row elements in the array x.
Constraint: ${\mathbf{pdx}}\ge {\mathbf{n}}$.
6:    $\mathbf{xmu}\left[{\mathbf{n}}\right]$const doubleInput
On entry: $\mu$, the mean vector of the multivariate Normal distribution.
7:    $\mathbf{iuld}$Nag_MatrixTypeInput
On entry: indicates the form of $\Sigma$ and how it is stored in sig.
${\mathbf{iuld}}=\mathrm{Nag_LowerMatrix}$
sig holds the lower triangular portion of $\Sigma$.
${\mathbf{iuld}}=\mathrm{Nag_UpperMatrix}$
sig holds the upper triangular portion of $\Sigma$.
${\mathbf{iuld}}=\mathrm{Nag_DiagonalMatrix}$
$\Sigma$ is a diagonal matrix and sig only holds the diagonal elements.
${\mathbf{iuld}}=\mathrm{Nag_LowerFactored}$
sig holds the lower Cholesky decomposition, $L$ such that $L{L}^{\mathrm{T}}=\Sigma$.
${\mathbf{iuld}}=\mathrm{Nag_UpperFactored}$
sig holds the upper Cholesky decomposition, $U$ such that ${U}^{\mathrm{T}}U=\Sigma$.
Constraint: ${\mathbf{iuld}}=\mathrm{Nag_LowerMatrix}$, $\mathrm{Nag_UpperMatrix}$, $\mathrm{Nag_DiagonalMatrix}$, $\mathrm{Nag_LowerFactored}$ or $\mathrm{Nag_UpperFactored}$.
8:    $\mathbf{sig}\left[\mathit{dim}\right]$const doubleInput
Note: the dimension, dim, of the array sig must be at least ${\mathbf{pdsig}}×{\mathbf{n}}$.
Where ${\mathbf{SIG}}\left(i,j\right)$ appears in this document, it refers to the array element ${\mathbf{sig}}\left[\left(j-1\right)×{\mathbf{pdsig}}+i-1\right]$.
On entry: information defining the variance-covariance matrix, $\Sigma$.
${\mathbf{iuld}}=\mathrm{Nag_LowerMatrix}$ or $\mathrm{Nag_UpperMatrix}$
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}}=\mathrm{Nag_DiagonalMatrix}$
$\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}}=\mathrm{Nag_LowerFactored}$ or $\mathrm{Nag_UpperFactored}$
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:    $\mathbf{pdsig}$IntegerInput
On entry: the stride separating matrix row elements in the array sig.
Constraints:
• if ${\mathbf{iuld}}=\mathrm{Nag_DiagonalMatrix}$, ${\mathbf{pdsig}}\ge 1$;
• otherwise ${\mathbf{pdsig}}\ge {\mathbf{n}}$.
10:  $\mathbf{pdf}\left[{\mathbf{k}}\right]$doubleOutput
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:  $\mathbf{rank}$Integer *Output
On exit: $r$, rank of $\Sigma$.
12:  $\mathbf{fail}$NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

## 6Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
NE_ARRAY_SIZE
On entry, ${\mathbf{pdsig}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{iuld}}=\mathrm{Nag_DiagonalMatrix}$, ${\mathbf{pdsig}}\ge 1$.
On entry, ${\mathbf{pdsig}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{iuld}}\ne \mathrm{Nag_DiagonalMatrix}$, ${\mathbf{pdsig}}\ge {\mathbf{n}}$.
On entry, ${\mathbf{pdx}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdx}}\ge {\mathbf{n}}$.
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_DIAG_ELEMENTS
On entry, at least one diagonal element of $\Sigma$ is less than or equal to $0$.
NE_INT
On entry, ${\mathbf{k}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{k}}\ge 0$.
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge 2$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 2.7.6 in How to Use the NAG Library and its Documentation for further information.
NE_MAT_NOT_POS_DEF
On entry, $\Sigma$ is not positive definite and eigenvalue decomposition failed.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.
NE_NOT_POS_SEM_DEF
On entry, $\Sigma$ is not positive semidefinite.

Not applicable.

## 8Parallelism and Performance

nag_multi_normal_pdf_vector (g01lbc) is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
nag_multi_normal_pdf_vector (g01lbc) 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 function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

None.

## 10Example

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

### 10.1Program Text

Program Text (g01lbce.c)

### 10.2Program Data

Program Data (g01lbce.d)

### 10.3Program Results

Program Results (g01lbce.r)