Multisignals 1-D clustering
clusters data using hierarchical clustering. The input matrix s
= mdwtcluster(x
)x
is
decomposed in the row direction using the discrete wavelet transform (DWT) with the Haar
wavelet and the maximum allowed level fix(log2(size(x,2)))
.
Note
mdwtcluster
requires Statistics and Machine Learning Toolbox™.
specifies options using name-value pair arguments in addition to the input argument in the
previous syntax. For example, s
= mdwtcluster(___,Name,Value
)'level',4
specifies the decomposition
level.
Load the 1-D multisignal elecsig10
.
load elecsig10
Compute the structure resulting from multisignal clustering.
lst2clu = {'s','ca1','ca3','ca6'}; S = mdwtcluster(signals,'maxclust',4,'lst2clu',lst2clu)
S = struct with fields:
IdxCLU: [70x4 double]
Incons: [69x4 double]
Corr: [0.7920 0.7926 0.7947 0.7631]
Retrieve the cluster indices.
IdxCLU = S.IdxCLU;
Plot the first and third clusters.
plot(signals(IdxCLU(:,1)==1,:)','r') hold on plot(signals(IdxCLU(:,1)==3,:)','b') hold off title('Cluster 1 (Signal) and Cluster 3 (Coefficients)')
Check the equality of partitions. Confirm we obtain the same partitions using coefficients of approximation at level 3 instead of the original signals. Much less information is then used.
equalPART = isequal(IdxCLU(:,1),IdxCLU(:,3))
equalPART = logical
1
x
— Input dataInput data, specified as a matrix.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
Specify optional
comma-separated pairs of Name,Value
arguments. Name
is
the argument name and Value
is the corresponding value.
Name
must appear inside quotes. You can specify several name and value
pair arguments in any order as
Name1,Value1,...,NameN,ValueN
.
s = mdwtcluster(signals,'maxclust',4,'wname','db4')
specifies
four clusters and the wavelet db4
.'dirDec'
— Direction of decomposition'r'
(default) | 'c'
Direction of decomposition, specified as 'r'
(row) or
'c'
(column).
'level'
— Level of DWT decompositionfix(log2(size(x
,d)))
(default) | positive integerLevel of DWT decomposition, specified as a positive integer. The default value is
fix(log2(size(
, where
x
,d)))d=1
or d=2
, depending on the
dirDec
value.
'wname'
— Wavelet'haar'
(default) | character vector | string scalarWavelet used for the DWT, specified as a character vector or string scalar. The
default value is the Haar wavelet, 'haar'
.
'dwtEXTM'
— DWT extension modeDWT extension mode, specified as a character vector or string scalar. See
dwtmode
.
'pdist'
— Distance metric'euclidean'
(default) | character vector | string scalar | function handleDistance metric, specified as a character vector, string scalar, or function
handle. The default value is 'euclidean'
. See pdist
(Statistics and Machine Learning Toolbox).
'linkage'
— Algorithm for computing the distance between clusters'ward'
(default) | 'average'
| 'centroid'
| 'complete'
| ...Algorithm for computing the distance between clusters, specified as one of the values in this table.
Method | Description |
---|---|
'average' | Unweighted average distance (UPGMA) |
'centroid' | Centroid distance (UPGMC), appropriate for Euclidean distances only |
'complete' | Farthest distance |
'median' | Weighted center of mass distance (WPGMC), appropriate for Euclidean distances only |
'single' | Shortest distance |
'ward' | Inner squared distance (minimum variance algorithm), appropriate for Euclidean distances only |
'weighted' | Weighted average distance (WPGMA) |
See linkage
(Statistics and Machine Learning Toolbox).
'maxclust'
— Number of clustersNumber of clusters, specified as an integer or vector.
'lst2clu'
— Cell array that contains the list of data to classifyCell array of character vectors or string vector which contains the list of data to classify. If N is the level of decomposition, the allowed name values for the cells are:
's'
— Signal
'aj'
— Approximation at level
j
'dj'
— Detail at level
j
'caj'
— Coefficients of
approximation at level j
'cdj'
— Coefficients of detail
at level j
with j = 1, …,
N
.
The default value is {'s';'ca1';...;'caN'}
or ["s" "cal" ... "caN"]
.
s
— Output structureThe output structure s
is such that for each partition
j:
S.Idx(:,j) | Contains the cluster numbers obtained from the hierarchical cluster
tree. See |
S.Incons(:,j) | Contains the inconsistent values of each non-leaf node in the
hierarchical cluster tree. See |
S.Corr(j) | Contains the cophenetic correlation coefficients of the partition.
See |
Note
If maxclust
is a vector, then IdxCLU
is a
multidimensional array such that
IdxCLU(:,j,k)
contains
the cluster numbers obtained from the hierarchical cluster tree for
k clusters.
You have a modified version of this example. Do you want to open this example with your edits?