# NAG CL Interfaceg01lbc (pdf_​multi_​normal_​vector)

## 1Purpose

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

## 2Specification

 #include
 void g01lbc (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)
The function may be called by the names: g01lbc, nag_stat_pdf_multi_normal_vector or nag_multi_normal_pdf_vector.

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

None.

## 5Arguments

1: $\mathbf{ilog}$Nag_Boolean Input
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}$Integer Input
On entry: $k$, the number of points the PDF is to be evaluated at.
Constraint: ${\mathbf{k}}\ge 0$.
3: $\mathbf{n}$Integer Input
On entry: $n$, the number of dimensions.
Constraint: ${\mathbf{n}}\ge 2$.
4: $\mathbf{x}\left[\mathit{dim}\right]$const double Input
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}$Integer Input
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 double Input
On entry: $\mu$, the mean vector of the multivariate Normal distribution.
7: $\mathbf{iuld}$Nag_MatrixType Input
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 double Input
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}$Integer Input
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]$double Output
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 7 in the Introduction to the NAG Library CL Interface).

## 6Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface 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 7.5 in the Introduction to the NAG Library CL Interface 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 8 in the Introduction to the NAG Library CL Interface for further information.
NE_NOT_POS_SEM_DEF
On entry, $\Sigma$ is not positive semidefinite.

Not applicable.

## 8Parallelism and Performance

g01lbc is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
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)