N
AG Library Manual, Mark 30.3
Interfaces:
FL
CL
CPP
AD
PY
MB
N
AG CL Interface Introduction
G03 (Mv) Chapter Contents
G03 (Mv) Chapter Introduction
g03gb:
FL
CL
CPP
AD
PY
MB
N
AG CL Interface
g03gbc (gaussian_mixture_ld)
Keyword Search:
N
AG Library Manual, Mark 30.3
Interfaces:
FL
CL
CPP
AD
PY
MB
N
AG CL Interface Introduction
G03 (Mv) Chapter Contents
G03 (Mv) Chapter Introduction
g03gb:
FL
CL
CPP
AD
PY
MB
▸
▿
Contents
1
Purpose
2
Specification
3
Description
4
References
5
Arguments
6
Error Indicators and Warnings
7
Accuracy
8
Parallelism and Performance
9
Further Comments
▸
▿
10
Example
10.1
Program Text
10.2
Program Data
10.3
Program Results
Copyright
N
AG 2024
Settings help
CL Name Style:
Short (
a00aac
)
Long (
impl_details
)
Full (
nag_info_impl_details
)
1
Purpose
g03gbc
performs a mixture of Normals (Gaussians) for a given (co)variance structure allowing for submatrix arguments.
2
Specification
copy
#include <nag.h>
void
g03gbc
(
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
[],
Integer
pdg
,
Nag_VarCovar
sopt
,
double
s
[],
Integer
pds
,
Integer
tds
,
double
f
[],
Integer
pdf
,
double
tol
,
double *
loglik
,
NagError *
fail
)
The function may be called by the names:
g03gbc
or
nag_mv_gaussian_mixture_ld
.
3
Description
g03gbc
is identical to
g03gac
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
(
x
∣
w
,
μ
,
Σ
)
=
∑
j
=
1
k
w
j
g
(
x
∣
μ
j
,
Σ
j
)
,
x
∈
ℝ
p
where:
x
is a
p
-dimensional object of interest;
w
j
is the mixture weight for the
j
th group and
∑
j
=
1
k
w
j
=
1
;
μ
j
is a
p
-dimensional vector of means for the
j
th group;
Σ
j
is the covariance structure for the
j
th group;
g
(
·
)
is the
p
-variate Normal density:
g
(
x
∣
μ
j
,
Σ
j
)
=
1
(
2
π
)
p
/
2
|
Σ
j
|
1
/
2
exp
[
-
1
2
(
x
-
μ
j
)
Σ
j
−1
(
x
-
μ
j
)
T
]
.
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
=
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:
m
–
Integer
Input
On entry
: the total number of variables in array
x
.
Constraint
:
m
≥
1
.
3:
x
[
dim
]
–
const double
Input
Note:
the dimension,
dim
, of the array
x
must be at least
n
×
pdx
.
On entry
:
x
[
(
i
-
1
)
×
pdx
+
j
-
1
]
must contain the value of the
j
th variable for the
i
th object, for
i
=
1
,
2
,
…
,
n
and
j
=
1
,
2
,
…
,
m
.
4:
pdx
–
Integer
Input
On entry
: the stride separating matrix column elements in the array
x
.
Constraint
:
pdx
≥
m
5:
isx
[
m
]
–
const Integer
Input
On entry
: if
nvar
=
m
all available variables are included in the model and
isx
is not referenced; otherwise the
j
th 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
nvar
≠
m
,
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:
nvar
–
Integer
Input
On entry
:
p
, the number of variables included in the calculations.
Constraint
:
1
≤
nvar
≤
m
.
7:
ng
–
Integer
Input
On entry
:
k
, the number of groups in the mixture model.
Constraint
:
ng
≥
1
.
8:
popt
–
Nag_Boolean
Input
On entry
: if
popt
=
Nag_TRUE
, the initial membership probabilities in
prob
are set internally; otherwise these probabilities must be supplied.
9:
prob
[
dim
]
–
double
Input/Output
Note:
the dimension,
dim
, of the array
prob
must be at least
n
×
tdprob
.
On entry
: if
popt
≠
Nag_TRUE
,
prob
[
(
i
-
1
)
×
tdprob
+
j
-
1
]
is the probability that the
i
th object belongs to the
j
th group. (These probabilities are normalised internally.)
On exit
:
prob
[
(
i
-
1
)
×
tdprob
+
j
-
1
]
is the probability of membership of the
i
th object to the
j
th group for the fitted model.
10:
tdprob
–
Integer
Input
On entry
: the stride separating matrix column elements in the array
prob
.
Constraint
:
tdprob
≥
ng
11:
niter
–
Integer *
Input/Output
On entry
: the maximum number of iterations.
Suggested value
:
15
On exit
: the number of completed iterations.
Constraint
:
niter
≥
1
.
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
]
–
double
Output
On exit
:
w
j
, the mixing probability for the
j
th group.
14:
g
[
dim
]
–
double
Output
Note:
the dimension,
dim
, of the array
g
must be at least
nvar
×
pdg
.
On exit
:
g
[
(
i
-
1
)
×
pdg
+
j
-
1
]
gives the estimated mean of the
i
th variable in the
j
th group.
15:
pdg
–
Integer
Input
On entry
: the stride separating matrix column elements in the array
g
.
Constraint
:
pdg
≥
ng
16:
sopt
–
Nag_VarCovar
Input
On entry
: determines the (co)variance structure:
sopt
=
Nag_GroupCovar
Groupwise covariance matrices.
sopt
=
Nag_PooledCovar
Pooled covariance matrix.
sopt
=
Nag_GroupVar
Groupwise variances.
sopt
=
Nag_PooledVar
Pooled variances.
sopt
=
Nag_OverallVar
Overall variance.
Constraint
:
sopt
=
Nag_GroupCovar
,
Nag_PooledCovar
,
Nag_GroupVar
,
Nag_PooledVar
or
Nag_OverallVar
.
17:
s
[
dim
]
–
double
Output
Note:
the dimension,
dim
, of the array
s
must be at least
pds
×
tds
×
c
.
where
S
(
i
,
j
,
k
)
appears in this document, it refers to the array element
s
[
(
k
-
1
)
×
pds
×
tds
+
(
j
-
1
)
×
pds
+
i
-
1
]
.
On exit
: if
sopt
=
Nag_GroupCovar
,
S
(
i
,
j
,
k
)
gives the
(
i
,
j
)
th element of the
k
th group.
If
sopt
=
Nag_PooledCovar
,
S
(
i
,
j
,
1
)
gives the
(
i
,
j
)
th element of the pooled covariance.
If
sopt
=
Nag_GroupVar
,
S
(
j
,
k
,
1
)
gives the
j
th variance in the
k
th group.
If
sopt
=
Nag_PooledVar
,
S
(
j
,
1
,
1
)
gives the
j
th pooled variance.
If
sopt
=
Nag_OverallVar
,
S
(
1
,
1
,
1
)
gives the overall variance.
18:
pds
–
Integer
Input
On entry
: the first dimension of the matrix
S
as stored in the array
s
.
Constraints
:
if
sopt
=
Nag_OverallVar
,
pds
≥
1
;
otherwise
pds
≥
nvar
.
19:
tds
–
Integer
Input
On entry
: the second dimension of the matrix
S
as stored in the array
s
.
Constraints
:
if
sopt
=
Nag_GroupCovar
or
Nag_PooledCovar
,
tds
≥
nvar
;
if
sopt
=
Nag_GroupVar
,
tds
≥
ng
;
if
sopt
=
Nag_PooledVar
or
Nag_OverallVar
,
tds
≥
1
.
20:
f
[
dim
]
–
double
Output
Note:
the dimension,
dim
, of the array
f
must be at least
n
×
pdf
.
On exit
:
f
[
(
i
-
1
)
×
pdf
+
j
-
1
]
gives the
p
-variate Normal (Gaussian) density of the
i
th object in the
j
th group.
21:
pdf
–
Integer
Input
On entry
: the stride separating matrix column elements in the array
f
.
Constraint
:
pdf
≥
ng
22:
tol
–
double
Input
On entry
: iterations cease the first time an improvement in log-likelihood is less than
tol
. If
tol
≤
0
a value of
10
−3
is used.
23:
loglik
–
double *
Output
On exit
: the log-likelihood for the fitted mixture model.
24:
fail
–
NagError *
Input/Output
The
N
AG error argument (see
Section 7
in the Introduction to the
N
AG Library CL Interface).
6
Error Indicators and Warnings
NE_ALLOC_FAIL
Dynamic memory allocation failed.
See
Section 3.1.2
in the Introduction to the
N
AG Library CL Interface for further information.
NE_ARRAY_SIZE
On entry,
pdf
=
⟨
value
⟩
and
ng
=
⟨
value
⟩
.
Constraint:
pdf
≥
ng
.
On entry,
pdg
=
⟨
value
⟩
and
ng
=
⟨
value
⟩
.
Constraint:
pdg
≥
ng
.
On entry,
pds
=
⟨
value
⟩
was invalid.
On entry,
pdx
=
⟨
value
⟩
and
m
=
⟨
value
⟩
.
Constraint:
pdx
≥
m
.
On entry,
tdprob
=
⟨
value
⟩
and
n
=
⟨
value
⟩
.
Constraint:
tdprob
≥
ng
.
On entry,
tds
=
⟨
value
⟩
was invalid.
NE_BAD_PARAM
On entry, argument
⟨
value
⟩
had an illegal value.
NE_CLUSTER_EMPTY
An iteration cannot continue due to an empty group, try a different initial allocation.
NE_INT
On entry,
m
=
⟨
value
⟩
.
Constraint:
m
≥
1
.
On entry,
ng
=
⟨
value
⟩
.
Constraint:
ng
≥
1
.
On entry,
niter
=
⟨
value
⟩
.
Constraint:
niter
≥
1
.
NE_INT_2
On entry,
nvar
=
⟨
value
⟩
and
m
=
⟨
value
⟩
.
Constraint:
1
≤
nvar
≤
m
.
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
N
AG
for assistance.
See
Section 7.5
in the Introduction to the
N
AG Library CL Interface for further information.
NE_MAT_NOT_POS_DEF
A covariance matrix is not positive definite, try a different initial allocation.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See
Section 8
in the Introduction to the
N
AG Library CL Interface for further information.
NE_OBSERVATIONS
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.
NE_PROBABILITY
On entry, row
⟨
value
⟩
of supplied
prob
does not sum to
1
.
NE_VAR_INCL_INDICATED
On entry,
nvar
≠
m
and
isx
is invalid.
7
Accuracy
Not applicable.
8
Parallelism and Performance
Background information to multithreading can be found in the
Multithreading
documentation.
g03gbc
is threaded by
N
AG for parallel execution in multithreaded implementations of the NAG Library.
g03gbc
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.
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 (g03gbce.c)
10.2
Program Data
Program Data (g03gbce.d)
10.3
Program Results
Program Results (g03gbce.r)
N
AG Library Manual, Mark 30.3
Interfaces:
FL
CL
CPP
AD
PY
MB
N
AG CL Interface Introduction
G03 (Mv) Chapter Contents
G03 (Mv) Chapter Introduction
g03gb:
FL
CL
CPP
AD
PY
MB
Copyright
N
AG 2024