G03GAF (PDF version)
G03 Chapter Contents
G03 Chapter Introduction
NAG Library Manual

NAG Library Routine Document

G03GAF

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.

 Contents

    1  Purpose
    7  Accuracy

1  Purpose

G03GAF performs a mixture of Normals (Gaussians) for a given (co)variance structure.

2  Specification

SUBROUTINE G03GAF ( N, M, X, LDX, ISX, NVAR, NG, POPT, PROB, LPROB, NITER, RITER, W, G, SOPT, S, LDS, SDS, F, TOL, LOGLIK, IFAIL)
INTEGER  N, M, LDX, ISX(M), NVAR, NG, POPT, LPROB, NITER, RITER, SOPT, LDS, SDS, IFAIL
REAL (KIND=nag_wp)  X(LDX,M), PROB(LPROB,NG), W(NG), G(NVAR,NG), S(LDS,SDS,*), F(N,NG), TOL, LOGLIK

3  Description

A Normal (Gaussian) mixture model is a weighted sum of k group Normal densities given by,
p xw,μ,Σ = j=1 k wj g xμj,Σj ,  xp  
where:
Optionally, the (co)variance structure may be pooled (common to all groups) or calculated for each group, and may be full or diagonal.

4  References

Hartigan J A (1975) Clustering Algorithms Wiley

5  Parameters

1:     N – INTEGERInput
On entry: n, the number of objects. There must be more objects than parameters in the model.
Constraints:
  • if SOPT=1, N>NG× NVAR×NVAR+NVAR;
  • if SOPT=2, N>NVAR× NG+NVAR ;
  • if SOPT=3, N>2×NG×NVAR ;
  • if SOPT=4, N>NVAR× NG+1 ;
  • if SOPT=5, N>NVAR×NG+1 .
2:     M – INTEGERInput
On entry: the total number of variables in array X.
Constraint: M1.
3:     XLDXM – REAL (KIND=nag_wp) arrayInput
On entry: Xij must contain the value of the jth variable for the ith object, for i=1,2,,n and j=1,2,,M.
4:     LDX – INTEGERInput
On entry: the first dimension of the array X as declared in the (sub)program from which G03GAF is called.
Constraint: LDXN.
5:     ISXM – INTEGER arrayInput
On entry: if NVAR=M all available variables are included in the model and ISX is not referenced; otherwise the jth variable will be included in the analysis if ISXj=1 and excluded if ISXj=0, for j=1,2,,M.
Constraint: if NVARM, ISXj=1 for NVAR values of j and ISXj=0 for the remaining M-NVAR values of j, for j=1,2,,M.
6:     NVAR – INTEGERInput
On entry: p, the number of variables included in the calculations.
Constraint: 1NVARM.
7:     NG – INTEGERInput
On entry: k, the number of groups in the mixture model.
Constraint: NG1.
8:     POPT – INTEGERInput
On entry: if POPT=1, the initial membership probabilities in PROB are set internally; otherwise these probabilities must be supplied.
9:     PROBLPROBNG – REAL (KIND=nag_wp) arrayInput/Output
On entry: if POPT1, PROBij is the probability that the ith object belongs to the jth group. (These probabilities are normalised internally.)
On exit: PROBij is the probability of membership of the ith object to the jth group for the fitted model.
10:   LPROB – INTEGERInput
On entry: the first dimension of the array PROB as declared in the (sub)program from which G03GAF is called.
Constraint: LPROBN.
11:   NITER – INTEGERInput/Output
On entry: the maximum number of iterations.
Suggested value: 15
On exit: the number of completed iterations.
Constraint: NITER1.
12:   RITER – INTEGERInput
On entry: if RITER>0, membership probabilities are rounded to 0.0 or 1.0 after the completion of every RITER iterations.
Suggested value: 5
13:   WNG – REAL (KIND=nag_wp) arrayOutput
On exit: wj, the mixing probability for the jth group.
14:   GNVARNG – REAL (KIND=nag_wp) arrayOutput
On exit: Gij gives the estimated mean of the ith variable in the jth group.
15:   SOPT – INTEGERInput
On entry: determines the (co)variance structure:
SOPT=1
Groupwise covariance matrices.
SOPT=2
Pooled covariance matrix.
SOPT=3
Groupwise variances.
SOPT=4
Pooled variances.
SOPT=5
Overall variance.
Constraint: SOPT=1, 2, 3, 4 or 5.
16:   SLDSSDS* – REAL (KIND=nag_wp) arrayOutput
Note: the last dimension of the array S must be at least NG if SOPT=1, and at least 1 otherwise.
On exit: if SOPT=1, Sijk gives the i,jth element of the kth group.
If SOPT=2, Sij1 gives the i,jth element of the pooled covariance.
If SOPT=3, Sjk1 gives the jth variance in the kth group.
If SOPT=4, Sj11 gives the jth pooled variance.
If SOPT=5, S111 gives the overall variance.
17:   LDS – INTEGERInput
On entry: the first dimension of the (co)variance structure S.
Constraints:
  • if SOPT=5, LDS=1;
  • otherwise LDS=NVAR.
18:   SDS – INTEGERInput
On entry: the second dimension of the (co)variance structure S.
Constraints:
  • if SOPT=1 or 2, SDS must be at least NVAR;
  • if SOPT=3, SDS must be at least NG;
  • if SOPT=4 or 5, SDS must be at least 1.
19:   FNNG – REAL (KIND=nag_wp) arrayOutput
On exit: Fij gives the p-variate Normal (Gaussian) density of the ith object in the jth group.
20:   TOL – REAL (KIND=nag_wp)Input
On entry: iterations cease the first time an improvement in log-likelihood is less than TOL. If TOL0 a value of 10-3 is used.
21:   LOGLIK – REAL (KIND=nag_wp)Output
On exit: the log-likelihood for the fitted mixture model.
22:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ 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​ 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 -1​ or ​1 is used it is essential to test the value of IFAIL on exit.
On exit: IFAIL=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6  Error Indicators and Warnings

If on entry IFAIL=0 or -1, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
IFAIL=1
On entry, N=value and p=value.
Constraint: N>p, the number of parameters, i.e., too few objects have been supplied for the model.
IFAIL=2
On entry, M=value.
Constraint: M1.
IFAIL=4
On entry, LDX=value and N=value.
Constraint: LDXN.
IFAIL=5
On entry, NVAR=value and M=value.
Constraint: 1NVARM.
IFAIL=6
On entry, NVARM and ISX is invalid.
IFAIL=7
On entry, NG=value.
Constraint: NG1.
IFAIL=8
On entry, POPT1 or 2.
IFAIL=9
On entry, row value of supplied PROB does not sum to 1.
IFAIL=10
On entry, LPROB=value and N=value.
Constraint: LPROBN.
IFAIL=11
On entry, NITER=value.
Constraint: NITER1.
IFAIL=16
On entry, SOPT<1 or SOPT>5.
IFAIL=18
On entry, LDS=value was invalid.
IFAIL=19
On entry, SDS=value was invalid.
IFAIL=44
A covariance matrix is not positive definite, try a different initial allocation.
IFAIL=45
An iteration cannot continue due to an empty group, try a different initial allocation.
IFAIL=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.8 in the Essential Introduction for further information.
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.
IFAIL=-999
Dynamic memory allocation failed.
See Section 3.6 in the Essential Introduction for further information.

7  Accuracy

Not applicable.

8  Parallelism and Performance

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

9  Further Comments

None.

10  Example

This example fits a Gaussian mixture model with pooled covariance structure to New Haven schools test data, see Table 5.1 (p. 118) in Hartigan (1975).

10.1  Program Text

Program Text (g03gafe.f90)

10.2  Program Data

Program Data (g03gafe.d)

10.3  Program Results

Program Results (g03gafe.r)


G03GAF (PDF version)
G03 Chapter Contents
G03 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2015