g01 Chapter Contents
g01 Chapter Introduction
NAG Library Manual

# NAG Library Function Documentnag_multi_normal_pdf_vector (g01lbc)

## 1  Purpose

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.

## 2  Specification

 #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)

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

None.

## 5  Arguments

1:     ilogNag_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:     kIntegerInput
On entry: $k$, the number of points the PDF is to be evaluated at.
Constraint: ${\mathbf{k}}\ge 0$.
3:     nIntegerInput
On entry: $n$, the number of dimensions.
Constraint: ${\mathbf{n}}\ge 2$.
4:     x[$\mathit{dim}$]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:     pdxIntegerInput
On entry: the stride separating matrix row elements in the array x.
Constraint: ${\mathbf{pdx}}\ge {\mathbf{n}}$.
6:     xmu[n]const doubleInput
On entry: $\mu$, the mean vector of the multivariate Normal distribution.
7:     iuldNag_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:     sig[$\mathit{dim}$]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:     pdsigIntegerInput
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:   pdf[${\mathbf{k}}$]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:   rankInteger *Output
On exit: $r$, rank of $\Sigma$.
12:   failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

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.
NE_MAT_NOT_POS_DEF
On entry, $\Sigma$ is not positive definite and eigenvalue decomposition failed.
NE_NOT_POS_SEM_DEF
On entry, $\Sigma$ is not positive semidefinite.

Not applicable.

## 8  Parallelism 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.

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 (g01lbce.c)

### 10.2  Program Data

Program Data (g01lbce.d)

### 10.3  Program Results

Program Results (g01lbce.r)