nag_mv_gaussian_mixture (g03gac) (PDF version)
g03 Chapter Contents
g03 Chapter Introduction
NAG Library Manual

NAG Library Function Document

nag_mv_gaussian_mixture (g03gac)

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

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

2  Specification

#include <nag.h>
#include <nagg03.h>
void  nag_mv_gaussian_mixture (Integer n, Integer m, const double x[], Integer pdx, const Integer isx[], Integer nvar, Integer ng, Nag_Boolean popt, double prob[], Integer tdprob, Integer *niter, Integer riter, double w[], double g[], Nag_VarCovar sopt, double s[], double f[], double tol, double *loglik, NagError *fail)

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
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  Arguments

1:     nIntegerInput
On entry: n, the number of objects. There must be more objects than parameters in the model.
  • if sopt=Nag_GroupCovar, n>ng× nvar×nvar+nvar;
  • if sopt=Nag_PooledCovar, n>nvar× ng+nvar ;
  • if sopt=Nag_GroupVar, n>2×ng×nvar ;
  • if sopt=Nag_PooledVar, n>nvar× ng+1 ;
  • if sopt=Nag_OverallVar, n>nvar×ng+1 .
2:     mIntegerInput
On entry: the total number of variables in array x.
Constraint: m1.
3:     x[n×pdx]const doubleInput
On entry: x[i-1×pdx+j-1] must contain the value of the jth variable for the ith object, for i=1,2,,n and j=1,2,,m.
4:     pdxIntegerInput
On entry: the stride separating matrix column elements in the array x.
Constraint: pdxm.
5:     isx[m]const IntegerInput
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 isx[j-1]=1 and excluded if isx[j-1]=0, for j=1,2,,m.
Constraint: if nvarm, isx[j-1]=1 for nvar values of j and isx[j-1]=0 for the remaining m-nvar values of j, for j=1,2,,m.
6:     nvarIntegerInput
On entry: p, the number of variables included in the calculations.
Constraint: 1nvarm.
7:     ngIntegerInput
On entry: k, the number of groups in the mixture model.
Constraint: ng1.
8:     poptNag_BooleanInput
On entry: if popt=Nag_TRUE, the initial membership probabilities in prob are set internally; otherwise these probabilities must be supplied.
9:     prob[n×tdprob]doubleInput/Output
On entry: if poptNag_TRUE, prob[i-1×tdprob+j-1] is the probability that the ith object belongs to the jth group. (These probabilities are normalised internally.)
On exit: prob[i-1×tdprob+j-1] is the probability of membership of the ith object to the jth group for the fitted model.
10:   tdprobIntegerInput
On entry: the stride separating matrix column elements in the array prob.
Constraint: tdprobng.
11:   niterInteger *Input/Output
On entry: the maximum number of iterations.
Suggested value: 15
On exit: the number of completed iterations.
Constraint: niter1.
12:   riterIntegerInput
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:   w[ng]doubleOutput
On exit: wj, the mixing probability for the jth group.
14:   g[nvar×ng]doubleOutput
On exit: g[i-1×ng+j-1] gives the estimated mean of the ith variable in the jth group.
15:   soptNag_VarCovarInput
On entry: determines the (co)variance structure:
Groupwise covariance matrices.
Pooled covariance matrix.
Groupwise variances.
Pooled variances.
Overall variance.
Constraint: sopt=Nag_GroupCovar, Nag_PooledCovar, Nag_GroupVar, Nag_PooledVar or Nag_OverallVar.
16:   s[dim]doubleOutput
Note: the dimension, dim, of the array s must be at least a×b×c.
Where Si,j,k appears in this document, it refers to the array element s[k-1×a×b+j-1×a+i-1].
On exit: if sopt=Nag_GroupCovar, Si,j,k gives the i,jth element of the kth group, with a=b=nvar and c=ng.
If sopt=Nag_PooledCovar, Si,j,1 gives the i,jth element of the pooled covariance, with a=b=nvar and c=1.
If sopt=Nag_GroupVar, Sj,k,1 gives the jth variance in the kth group, with a=nvar, b=ng and c=1.
If sopt=Nag_PooledVar, Sj,1,1 gives the jth pooled variance., with a=nvar and b=c=1
If sopt=Nag_OverallVar, S1,1,1 gives the overall variance, with a=b=c=1.
17:   f[n×ng]doubleOutput
On exit: f[i-1×ng+j-1] gives the p-variate Normal (Gaussian) density of the ith object in the jth group.
18:   toldoubleInput
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.
19:   loglikdouble *Output
On exit: the log-likelihood for the fitted mixture model.
20:   failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

6  Error Indicators and Warnings

Dynamic memory allocation failed.
On entry, pdx=value and n=value.
Constraint: pdxn.
On entry, tdprob=value and n=value.
Constraint: tdprobn.
On entry, argument value had an illegal value.
An iteration cannot continue due to an empty group, try a different initial allocation.
On entry, m=value.
Constraint: m1.
On entry, ng=value.
Constraint: ng1.
On entry, niter=value.
Constraint: niter1.
On entry, nvar=value and m=value.
Constraint: 1nvarm.
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.
A covariance matrix is not positive definite, try a different initial allocation.
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.
On entry, row value of supplied prob does not sum to 1.
On entry, nvarm and isx is invalid.

7  Accuracy

Not applicable.

8  Parallelism and Performance

Not applicable.

9  Further Comments


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

10.2  Program Data

Program Data (g03gace.d)

10.3  Program Results

Program Results (g03gace.r)

nag_mv_gaussian_mixture (g03gac) (PDF version)
g03 Chapter Contents
g03 Chapter Introduction
NAG Library Manual

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