NAG FL Interface
g03gbf (gaussian_​mixture_​ld)

Settings help

FL Name Style:


FL Specification Language:


1 Purpose

g03gbf performs a mixture of Normals (Gaussians) for a given (co)variance structure allowing for submatrix arguments.

2 Specification

Fortran Interface
Subroutine g03gbf ( n, m, x, ldx, isx, nvar, ng, popt, prob, lprob, niter, riter, w, g, ldg, sopt, s, lds, sds, f, ldf, tol, loglik, ifail)
Integer, Intent (In) :: n, m, ldx, isx(m), nvar, ng, popt, lprob, riter, ldg, sopt, lds, sds, ldf
Integer, Intent (Inout) :: niter, ifail
Real (Kind=nag_wp), Intent (In) :: x(ldx,*), tol
Real (Kind=nag_wp), Intent (Inout) :: prob(lprob,*), g(ldg,*), s(lds,sds,*), f(ldf,*)
Real (Kind=nag_wp), Intent (Out) :: w(ng), loglik
C Header Interface
#include <nag.h>
void  g03gbf_ (const Integer *n, const Integer *m, const double x[], const Integer *ldx, const Integer isx[], const Integer *nvar, const Integer *ng, const Integer *popt, double prob[], const Integer *lprob, Integer *niter, const Integer *riter, double w[], double g[], const Integer *ldg, const Integer *sopt, double s[], const Integer *lds, const Integer *sds, double f[], const Integer *ldf, const double *tol, double *loglik, Integer *ifail)
The routine may be called by the names g03gbf or nagf_mv_gaussian_mixture_ld.

3 Description

g03gbf is identical to g03gaf except for the addition of array dimension arguments that allow submatrices to be passed as actual arguments for outputs f and g.
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 Arguments

1: n Integer Input
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 Integer Input
On entry: the total number of variables in array x.
Constraint: m1.
3: x(ldx,*) Real (Kind=nag_wp) array Input
Note: the second dimension of the array x must be at least m.
On entry: x(i,j) must contain the value of the jth variable for the ith object, for i=1,2,,n and j=1,2,,m.
4: ldx Integer Input
On entry: the first dimension of the array x as declared in the (sub)program from which g03gbf is called.
Constraint: ldxn.
5: isx(m) Integer array Input
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 and excluded if isx(j)=0, for j=1,2,,m.
Constraint: if nvarm, isx(j)=1 for nvar values of j and isx(j)=0 for the remaining m-nvar values of j, for j=1,2,,m.
6: nvar Integer Input
On entry: p, the number of variables included in the calculations.
Constraint: 1nvarm.
7: ng Integer Input
On entry: k, the number of groups in the mixture model.
Constraint: ng1.
8: popt Integer Input
On entry: if popt=1, the initial membership probabilities in prob are set internally; otherwise these probabilities must be supplied.
9: prob(lprob,*) Real (Kind=nag_wp) array Input/Output
Note: the second dimension of the array prob must be at least ng.
On entry: if popt1 , prob(i,j) is the probability that the ith object belongs to the jth group. (These probabilities are normalised internally.)
On exit: prob(i,j) is the probability of membership of the ith object to the jth group for the fitted model.
10: lprob Integer Input
On entry: the first dimension of the array prob as declared in the (sub)program from which g03gbf is called.
Constraint: lprobn.
11: niter Integer Input/Output
On entry: the maximum number of iterations.
Suggested value: 15
On exit: the number of completed iterations.
Constraint: niter1.
12: riter Integer Input
On entry: if riter>0, membership probabilities are rounded to 0.0 or 1.0 after the completion of the first riter iterations.
Suggested value: 0
13: w(ng) Real (Kind=nag_wp) array Output
On exit: wj, the mixing probability for the jth group.
14: g(ldg,*) Real (Kind=nag_wp) array Output
Note: the second dimension of the array g must be at least ng.
On exit: g(i,j) gives the estimated mean of the ith variable in the jth group.
15: ldg Integer Input
On entry: the first dimension of the array g as declared in the (sub)program from which g03gbf is called.
Constraint: ldgnvar.
16: sopt Integer Input
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.
17: s(lds,sds,*) Real (Kind=nag_wp) array Output
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, s(i,j,k) gives the (i,j)th element of the kth group.
If sopt=2, s(i,j,1) gives the (i,j)th element of the pooled covariance.
If sopt=3, s(j,k,1) gives the jth variance in the kth group.
If sopt=4, s(j,1,1) gives the jth pooled variance.
If sopt=5, s(1,1,1) gives the overall variance.
18: lds Integer Input
On entry: the first dimension of the (co)variance structure s.
Constraints:
  • if sopt=5, lds1;
  • otherwise ldsnvar.
19: sds Integer Input
On entry: the second dimension of the (co)variance structure s.
Constraints:
  • if sopt=1 or 2, sdsnvar;
  • if sopt=3, sdsng;
  • if sopt=4 or 5, sds1.
20: f(ldf,*) Real (Kind=nag_wp) array Output
Note: the second dimension of the array f must be at least ng.
On exit: f(i,j) gives the p-variate Normal (Gaussian) density of the ith object in the jth group.
21: ldf Integer Input
On entry: the first dimension of the array f as declared in the (sub)program from which g03gbf is called.
Constraint: ldfn.
22: 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.
23: loglik Real (Kind=nag_wp) Output
On exit: the log-likelihood for the fitted mixture model.
24: ifail Integer Input/Output
On entry: ifail must be set to 0, −1 or 1 to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of 0 causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of −1 means that an error message is printed while a value of 1 means that it is not.
If halting is not appropriate, the value −1 or 1 is recommended. If message printing is undesirable, then the value 1 is recommended. Otherwise, the value 0 is recommended. 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=15
On entry, ldg=value and nvar=value.
Constraint: ldgnvar.
ifail=16
On entry, sopt1, 2, 3, 4 or 5.
ifail=18
On entry, lds=value was invalid.
ifail=19
On entry, sds=value was invalid.
ifail=21
On entry, ldf=value and n=value.
Constraint: ldfn.
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=110
On entry, lprob=value and n=value.
Constraint: lprobn.
ifail=115
On entry, ldg=value and nvar=value.
Constraint: ldgnvar.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
ifail=-399
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
ifail=-999
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

7 Accuracy

Not applicable.

8 Parallelism and Performance

Background information to multithreading can be found in the Multithreading documentation.
g03gbf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
g03gbf 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 (g03gbfe.f90)

10.2 Program Data

Program Data (g03gbfe.d)

10.3 Program Results

Program Results (g03gbfe.r)