hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_mv_gaussian_mixture (g03ga)

Purpose

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

Syntax

[prob, niter, w, g, s, f, loglik, ifail] = g03ga(x, isx, nvar, ng, sopt, sds, tol, 'n', n, 'm', m, 'prob', prob, 'niter', niter, 'riter', riter)
[prob, niter, w, g, s, f, loglik, ifail] = nag_mv_gaussian_mixture(x, isx, nvar, ng, sopt, sds, tol, 'n', n, 'm', m, 'prob', prob, 'niter', niter, 'riter', riter)

Description

A Normal (Gaussian) mixture model is a weighted sum of kk group Normal densities given by,
k
p(xw,μ,Σ) = wjg(xμj,Σj), xp
j = 1
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.

References

Hartigan J A (1975) Clustering Algorithms Wiley

Parameters

Compulsory Input Parameters

1:     x(ldx,m) – double array
ldx, the first dimension of the array, must satisfy the constraint ldxnldxn.
x(i,j)xij must contain the value of the jjth variable for the iith object, for i = 1,2,,ni=1,2,,n and j = 1,2,,mj=1,2,,m.
2:     isx(m) – int64int32nag_int array
m, the dimension of the array, must satisfy the constraint m1m1.
If nvar = mnvar=m all available variables are included in the model and isx is not referenced; otherwise the jjth variable will be included in the analysis if isx(j) = 1isxj=1 and excluded if isx(j) = 0isxj=0, for j = 1,2,,mj=1,2,,m.
Constraints:
  • if nvarmnvarm, isx(j) = 1isxj=1 for nvar values of jj;
  • otherwise 00.
3:     nvar – int64int32nag_int scalar
pp, the number of variables included in the calculations.
Constraint: 1nvarm1nvarm.
4:     ng – int64int32nag_int scalar
kk, the number of groups in the mixture model.
Constraint: ng1ng1.
5:     sopt – int64int32nag_int scalar
Determines the (co)variance structure:
sopt = 1sopt=1
Groupwise covariance matrices.
sopt = 2sopt=2
Pooled covariance matrix.
sopt = 3sopt=3
Groupwise variances.
sopt = 4sopt=4
Pooled variances.
sopt = 5sopt=5
Overall variance.
Constraint: sopt = 1sopt=1, 22, 33, 44 or 55.
6:     sds – int64int32nag_int scalar
The second dimension of the (co)variance structure s.
Constraints:
  • if sopt = 1sopt=1 or 22, sds must be at least nvar;
  • if sopt = 3sopt=3, sds must be at least ng;
  • if sopt = 4sopt=4 or 55, sds must be at least 11.
7:     tol – double scalar
Iterations cease the first time an improvement in log-likelihood is less than tol. If tol0tol0 a value of 10310-3 is used.

Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The first dimension of the arrays x, prob. (An error is raised if these dimensions are not equal.)
nn, the number of objects. There must be more objects than parameters in the model.
Constraints:
2:     m – int64int32nag_int scalar
Default: The dimension of the array isx and the second dimension of the array x. (An error is raised if these dimensions are not equal.)
The total number of variables in array x.
Constraint: m1m1.
3:     prob(lprob,ng) – double array
If popt1popt1, prob(i,j)probij is the probability that the iith object belongs to the jjth group. (These probabilities are normalised internally.)
4:     niter – int64int32nag_int scalar
The maximum number of iterations.
Default: 1515
Constraint: niter1niter1.
5:     riter – int64int32nag_int scalar
If riter > 0riter>0, membership probabilities are rounded to 0.00.0 or 1.01.0 after the completion of every riter iterations.
Default: 55

Input Parameters Omitted from the MATLAB Interface

ldx popt lprob lds

Output Parameters

1:     prob(lprob,ng) – double array
lprobnlprobn.
prob(i,j)probij is the probability of membership of the iith object to the jjth group for the fitted model.
2:     niter – int64int32nag_int scalar
Default: 1515
The number of completed iterations.
3:     w(ng) – double array
wjwj, the mixing probability for the jjth group.
4:     g(nvar,ng) – double array
g(i,j)gij gives the estimated mean of the iith variable in the jjth group.
5:     s(lds,sds, : :) – double array
Note: the last dimension of the array s must be at least ngng if sopt = 1sopt=1, and at least 11 otherwise.
If sopt = 1sopt=1, s(i,j,k)sijk gives the (i,j)(i,j)th element of the kkth group.
If sopt = 2sopt=2, s(i,j,1)sij1 gives the (i,j)(i,j)th element of the pooled covariance.
If sopt = 3sopt=3, s(j,k,1)sjk1 gives the jjth variance in the kkth group.
If sopt = 4sopt=4, s(j,1,1)sj11 gives the jjth pooled variance.
If sopt = 5sopt=5, s(1,1,1)s111 gives the overall variance.
6:     f(n,ng) – double array
f(i,j)fij gives the pp-variate Normal (Gaussian) density of the iith object in the jjth group.
7:     loglik – double scalar
The log-likelihood for the fitted mixture model.
8:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:
  ifail = 1ifail=1
Constraint: n > pn>p, the number of parameters, i.e., too few objects have been supplied for the model.
  ifail = 2ifail=2
Constraint: m1m1.
  ifail = 4ifail=4
Constraint: ldxnldxn.
  ifail = 5ifail=5
Constraint: nvar1nvar1 and nvarmnvarm.
  ifail = 6ifail=6
On entry, nvarmnvarm and isx is invalid.
  ifail = 7ifail=7
Constraint: ng1ng1.
  ifail = 8ifail=8
On entry, popt1popt1 or 22.
  ifail = 9ifail=9
On entry, row kk of supplied prob does not sum to 11.
  ifail = 10ifail=10
Constraint: lprobnlprobn.
  ifail = 11ifail=11
Constraint: niter1niter1.
  ifail = 16ifail=16
On entry, sopt < 1sopt<1 or sopt > 5sopt>5.
  ifail = 18ifail=18
On entry was invalid.
  ifail = 19ifail=19
On entry was invalid.
  ifail = 44ifail=44
A covariance matrix is not positive definite, try a different initial allocation.
  ifail = 45ifail=45
An iteration cannot continue due to an empty group, try a different initial allocation.
  ifail = 999ifail=-999
Dynamic memory allocation failed.

Accuracy

Not applicable.

Further Comments

None.

Example

function nag_mv_gaussian_mixture_example
nvar  = int64(4);
sds   = int64(4);
sopt  = int64(2);
tol   = 0;
ng    = int64(2);

x = [2.7, 3.2, 4.5, 4.8;
     3.9, 3.8, 5.9, 6.2;
     4.8, 4.1, 6.8, 5.5;
     3.1, 3.5, 4.3, 4.6;
     3.4, 3.7, 5.1, 5.6;
     3.1, 3.4, 4.1, 4.7;
     4.6, 4.4, 6.6, 6.1;
     3.1, 3.3, 4.0, 4.9;
     3.8, 3.7, 4.7, 4.9;
     5.2, 4.9, 8.2, 6.9;
     3.9, 3.8, 5.2, 5.4;
     4.1, 4.0, 5.6, 5.6;
     5.7, 5.1, 7.0, 6.3;
     3.0, 3.2, 4.5, 5.0;
     2.9, 3.3, 4.5, 5.1;
     3.4, 3.3, 4.4, 5.0;
     4.0, 4.2, 5.2, 5.4;
     3.0, 3.0, 4.6, 5.0;
     4.0, 4.1, 5.9, 5.8;
     3.0, 3.2, 4.4, 5.1;
     3.6, 3.6, 5.3, 5.4;
     3.1, 3.2, 4.6, 5.0;
     3.2, 3.3, 5.4, 5.3;
     3.0, 3.4, 4.2, 4.7;
     3.8, 4.0, 6.9, 6.7];
prob = [1, 0;
        1, 0;
        1, 0;
        1, 0;
        1, 0;
        1, 0;
        1, 0;
        1, 0;
        1, 0;
        1, 0;
        1, 0;
        1, 0;
        0, 1;
        0, 1;
        0, 1;
        0, 1;
        0, 1;
        0, 1;
        0, 1;
        0, 1;
        0, 1;
        0, 1;
        0, 1;
        0, 1;
        0, 1];
isx = zeros(4, 1, 'int64');

[prob, niter, w, g, s, f, loglik, ifail] = ...
    nag_mv_gaussian_mixture(x, isx, nvar, ng, sopt, sds, tol, 'prob', prob)
 

prob =

    0.9502    0.0498
    0.0000    1.0000
    0.9996    0.0004
    0.9999    0.0001
    0.0390    0.9610
    0.9327    0.0673
    0.9888    0.0112
    0.0041    0.9959
    0.9725    0.0275
    0.9997    0.0003
    0.2172    0.7828
    0.7694    0.2306
    1.0000    0.0000
    0.0061    0.9939
    0.0442    0.9558
    0.0004    0.9996
    0.9999    0.0001
    0.0000    1.0000
    0.9738    0.0262
    0.0003    0.9997
    0.0695    0.9305
    0.0042    0.9958
    0.0308    0.9692
    0.9912    0.0088
    0.0004    0.9996


niter =

                   14


w =

    0.4798
    0.5202


g =

    4.0041    3.3350
    3.9949    3.4434
    5.5894    4.9870
    5.4432    5.3602


s =

    0.4539    0.2891    0.6075    0.3413
    0.2891    0.2048    0.4101    0.2490
    0.6075    0.4101    1.0648    0.6011
    0.3413    0.2490    0.6011    0.3759


f =

    0.2584    0.0119
    0.0000    0.1124
    0.0053    0.0000
    0.4246    0.0000
    0.0504    1.1544
    1.1260    0.0722
    2.0911    0.0212
    0.0058    1.3227
    1.1609    0.0294
    0.0898    0.0000
    0.3017    1.0106
    1.2930    0.3542
    0.0286    0.0000
    0.0208    3.1690
    0.0765    1.5231
    0.0003    0.8402
    0.5610    0.0000
    0.0000    0.6444
    2.1250    0.0510
    0.0009    2.7626
    0.1922    2.3971
    0.0125    2.8179
    0.0184    0.5357
    1.2409    0.0096
    0.0000    0.0487


loglik =

  -29.6831


ifail =

                    0


function g03ga_example
nvar  = int64(4);
sds   = int64(4);
sopt  = int64(2);
tol   = 0;
ng    = int64(2);

x = [2.7, 3.2, 4.5, 4.8;
     3.9, 3.8, 5.9, 6.2;
     4.8, 4.1, 6.8, 5.5;
     3.1, 3.5, 4.3, 4.6;
     3.4, 3.7, 5.1, 5.6;
     3.1, 3.4, 4.1, 4.7;
     4.6, 4.4, 6.6, 6.1;
     3.1, 3.3, 4.0, 4.9;
     3.8, 3.7, 4.7, 4.9;
     5.2, 4.9, 8.2, 6.9;
     3.9, 3.8, 5.2, 5.4;
     4.1, 4.0, 5.6, 5.6;
     5.7, 5.1, 7.0, 6.3;
     3.0, 3.2, 4.5, 5.0;
     2.9, 3.3, 4.5, 5.1;
     3.4, 3.3, 4.4, 5.0;
     4.0, 4.2, 5.2, 5.4;
     3.0, 3.0, 4.6, 5.0;
     4.0, 4.1, 5.9, 5.8;
     3.0, 3.2, 4.4, 5.1;
     3.6, 3.6, 5.3, 5.4;
     3.1, 3.2, 4.6, 5.0;
     3.2, 3.3, 5.4, 5.3;
     3.0, 3.4, 4.2, 4.7;
     3.8, 4.0, 6.9, 6.7];
prob = [1, 0;
        1, 0;
        1, 0;
        1, 0;
        1, 0;
        1, 0;
        1, 0;
        1, 0;
        1, 0;
        1, 0;
        1, 0;
        1, 0;
        0, 1;
        0, 1;
        0, 1;
        0, 1;
        0, 1;
        0, 1;
        0, 1;
        0, 1;
        0, 1;
        0, 1;
        0, 1;
        0, 1;
        0, 1];
isx = zeros(4, 1, 'int64');

[prob, niter, w, g, s, f, loglik, ifail] = ...
    g03ga(x, isx, nvar, ng, sopt, sds, tol, 'prob', prob)
 

prob =

    0.9502    0.0498
    0.0000    1.0000
    0.9996    0.0004
    0.9999    0.0001
    0.0390    0.9610
    0.9327    0.0673
    0.9888    0.0112
    0.0041    0.9959
    0.9725    0.0275
    0.9997    0.0003
    0.2172    0.7828
    0.7694    0.2306
    1.0000    0.0000
    0.0061    0.9939
    0.0442    0.9558
    0.0004    0.9996
    0.9999    0.0001
    0.0000    1.0000
    0.9738    0.0262
    0.0003    0.9997
    0.0695    0.9305
    0.0042    0.9958
    0.0308    0.9692
    0.9912    0.0088
    0.0004    0.9996


niter =

                   14


w =

    0.4798
    0.5202


g =

    4.0041    3.3350
    3.9949    3.4434
    5.5894    4.9870
    5.4432    5.3602


s =

    0.4539    0.2891    0.6075    0.3413
    0.2891    0.2048    0.4101    0.2490
    0.6075    0.4101    1.0648    0.6011
    0.3413    0.2490    0.6011    0.3759


f =

    0.2584    0.0119
    0.0000    0.1124
    0.0053    0.0000
    0.4246    0.0000
    0.0504    1.1544
    1.1260    0.0722
    2.0911    0.0212
    0.0058    1.3227
    1.1609    0.0294
    0.0898    0.0000
    0.3017    1.0106
    1.2930    0.3542
    0.0286    0.0000
    0.0208    3.1690
    0.0765    1.5231
    0.0003    0.8402
    0.5610    0.0000
    0.0000    0.6444
    2.1250    0.0510
    0.0009    2.7626
    0.1922    2.3971
    0.0125    2.8179
    0.0184    0.5357
    1.2409    0.0096
    0.0000    0.0487


loglik =

  -29.6831


ifail =

                    0



PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013