Multi-level clustering by kNN mode-seeking.
LAB = CLUSTM(A,K)
A kNN modeseeking method is used to assign each object to its nearest density mode. Object densities are related to the distances to neighbors. Modes are determined by recusively jumping to objects in the neighborhood with the highest density. As many clusters are found as there are objects that are the mode in their own neighborhood.
As modeseeking clustering does not return a predefined number of clusters a desired number of clusters K is realised by reclustering by RECLUSTK.
Note that finding exactly K clusters is computationally heavy for K > 500 and might be impossible for K > 5000. Users are advised in such cases to run this procedure with K =  and find a useful clustering by CLUSTNUM.
This routine is based on the same algorithm as DCLUSTM (for dissimilarity data), and MODECLUST and MODECLUSTF. It calls DCLUSTM if the distance matrix fits into memory. Otherwise it calls MODECLUSTF. Users should call these routines directly for more dedicated parameter settings.
Clusterings can be evaluated by CLUSTEVAL, CLUSTCERR or CLUSTC on the basis of (some) true labels.
randreset; % take care of reproducability
Cheng, Y. "Mean shift, mode Seeking, and clustering", IEEE Transactions on PAMI, vol. 17, no. 8, pp. 790-799, 1995.
R.P.W. Duin, A.L.N. Fred, M. Loog, and E. Pekalska, Mode Seeking Clustering by KNN and Mean Shift Evaluated, Proc. SSPR & SPR 2012, LNCS, vol. 7626, Springer, 2012, 51-59.
R.P.W. Duin and S. Verzakov, Fast kNN mode seeking clustering applied to active learning, arXiv:1712.07454, 2017, 1-23.