NAG CL Interface
g03eac (distance_mat)
1
Purpose
g03eac computes a distance (dissimilarity) matrix.
2
Specification
void |
g03eac (Nag_MatUpdate update,
Nag_DistanceType dist,
Nag_VarScaleType scale,
Integer n,
Integer m,
const double x[],
Integer tdx,
const Integer isx[],
double s[],
double d[],
NagError *fail) |
|
The function may be called by the names: g03eac or nag_mv_distance_mat.
3
Description
Given objects, a distance or dissimilarity matrix, is a symmetric matrix with zero diagonal elements such that the th element represents how far apart or how dissimilar the th and th objects are.
Let
be an
by
data matrix of observations of
variables on
objects, then the distance between object
and object
,
, can be defined as:
where
and
are the
th and
th elements of
,
is a standardization for the
th variable and
is a suitable function. Three functions are provided in
g03eac:
-
(a)Euclidean distance: and .
-
(b)Euclidean squared distance: and .
-
(c)Absolute distance (city block metric): and .
Three standardizations are available:
-
1.Standard deviation:
-
2.Range:
-
3.User-supplied values of .
In addition to the above distances there are a large number of other dissimilarity measures, particularly for dichotomous variables (see
Krzanowski (1990) and
Everitt (1974)). For the dichotomous case these measures are simple to compute and can, if suitable scaling is used, be combined with the distances computed by
g03eac using the updating option.
Dissimilarity measures for variables can be based on the correlation coefficient for continuous variables and contingency table statistics for dichotomous data, see the
G02 Chapter Introduction and the
G11 Chapter Introduction respectively.
g03eac returns the strictly lower triangle of the distance matrix.
4
References
Everitt B S (1974) Cluster Analysis Heinemann
Krzanowski W J (1990) Principles of Multivariate Analysis Oxford University Press
5
Arguments
-
1:
– Nag_MatUpdate
Input
-
On entry: indicates whether or not an existing matrix is to be updated.
- The matrix is updated and distances are added to .
- The matrix is initialized to zero before the distances are added to .
Constraint:
or .
-
2:
– Nag_DistanceType
Input
-
On entry: indicates which type of distances are computed.
- Absolute distances.
- Euclidean distances.
- Euclidean squared distances.
Constraint:
, or .
-
3:
– Nag_VarScaleType
Input
-
On entry: indicates the standardization of the variables to be used.
- Standard deviation.
- Range.
- Standardizations given in array .
- Unscaled.
Constraint:
, , or .
-
4:
– Integer
Input
-
On entry: , the number of observations.
Constraint:
.
-
5:
– Integer
Input
-
On entry: the total number of variables in array
x.
Constraint:
.
-
6:
– const double
Input
-
On entry: must contain the value of the th variable for the th object, for and .
-
7:
– Integer
Input
-
On entry: the stride separating matrix column elements in the array
x.
Constraint:
.
-
8:
– const Integer
Input
-
On entry:
indicates whether or not the
th variable in
x is to be included in the distance computations.
If the th variable is included, for ; otherwise it is not referenced.
Constraint:
for at least one , for .
-
9:
– double
Input/Output
-
On entry: if and then must contain the scaling for variable , for .
Constraint:
if and ,
, for .
On exit: if
and
then
contains the standard deviation of the variable in the
th column of
x.
If
and
then
contains the range of the variable in the
th column of
x.
If
and
then
and if
then
s is unchanged.
-
10:
– double
Input/Output
-
On entry: if
then
d must contain the strictly lower triangle of the distance matrix
to be updated.
must be stored packed by rows, i.e.,
,
must contain
.
Constraint:
if ,
, for .
On exit: the strictly lower triangle of the distance matrix stored packed by rows, i.e., is contained in , .
-
11:
– NagError *
Input/Output
-
The NAG error argument (see
Section 7 in the Introduction to the NAG Library CL Interface).
6
Error Indicators and Warnings
- NE_2_INT_ARG_LT
-
On entry, while . These arguments must satisfy .
- NE_BAD_PARAM
-
On entry, argument
dist had an illegal value.
On entry, argument
scale had an illegal value.
On entry, argument
update had an illegal value.
- NE_IDEN_ELEM_COND
-
On entry, or , and , for , for some with .
- NE_INT_ARG_LE
-
On entry, .
Constraint: .
- NE_INT_ARG_LT
-
On entry, .
Constraint: .
- NE_INTARR
-
On entry, .
Constraint: , for at least one .
- 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
NAG for assistance.
- NE_REALARR
-
On entry, .
Constraint: , for , when .
On entry, .
Constraint: , for , when and .
7
Accuracy
The computations are believed to be stable.
8
Parallelism and Performance
g03eac 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.
g03ecc can be used to perform cluster analysis on the computed distance matrix.
10
Example
A data matrix of five observations and three variables is read in and a distance matrix is calculated from variables 2 and 3 using squared Euclidean distance with no scaling. This matrix is then printed.
10.1
Program Text
10.2
Program Data
10.3
Program Results