In February June this year, Alex Rodriguez and Alessandro laio published an article titled clustering by fast search and find of density peaks in science, it provides a new idea for designing clustering algorithms. Although the article has been questioned by many readers, the basic idea of the new clustering algorithm is novel and simple and clear, and it is worth learning. The core idea of this new clustering algorithm lies in the characterization of the clustering center. This article will introduce the principle of this algorithm in detail and discuss several details.
Finally, add the MATLAB sample program provided by the author in the supplemental materials (with appropriate code comments ).
Clear allclose alldisp ('the only input needed is a distance matrix file') disp ('the format of this file shocould be: ') disp ('column 1: ID of element I ') disp ('column 2: ID of element j') disp ('column 3: dist (I, j )') % read data from the file mdist = input ('name of the distance matrix file (with single quotes )? \ N'); disp ('reading input distance matrix ') xx = load (mdist); ND = max (XX (:, 2 )); NL = max (XX (:, 1); If (NL> Nd) Nd = nL; % make sure that the DN value is greater than the maximum value in the first two columns, and use it as the total number of data points endn = size (XX, 1); % XX the length of the first dimension, equivalent to the number of lines of the file (that is, the total number of distance) % Initialization is zero for I = 1: nd for j = 1: Nd dist (I, j) = 0; endend % assign values to the DIST Array Using XX, note that only 0.5 * DN (DN-1) values are saved in the input, which is filled with the full matrix % here the diagonal element for I = 1: n ii = XX (I, 1); JJ = XX (I, 2); dist (II, JJ) = XX (I, 3); dist (JJ, ii) = XX (I, 3 ); end % confirm dcpercent = 2.0; fprintf ('average percentage of neighbors (hard coded): % 5.6f \ n', percent); position = round (N * percent/100 ); % Round is a rounding function SDA = sort (XX (:, 3); % sort all distance values in ascending order Dc = SDA (position ); % calculate the local density (using the Gaussian Kernel) fprintf ('computing s4with Gaussian Kernel of radius: % 12.6f \ n', DC ); % initialize the guid of each data point to 0 for I = 1: Nd records (I) = 0 .; end % Gaussian kernelfor I = 1: ND-1 for J = I + 1: Nd ROV (I) = rock (I) + exp (-(Dist (I, j)/DC) *( Dist (I, j)/DC); rock (j) = rock (j) + exp (-(Dist (I, j)/DC) * (Dist (I, j)/DC); endend % "Cut off" kernel % for I = 1: ND-1 % for J = I + 1: Nd % IF (Dist (I, j) <DC) % rock (I) = rock (I) + 1 .; % rock (j) = rock (j) + 1 .; % end % first calculate the maximum value of the matrix column, then calculate the maximum value, and finally obtain the maximum value maxd = max (DIST) of all distance values )); % sort the records in a descending order, and ordrho maintains the order [fig, ordrho] = sort (rock, 'scend '); % delta (ordrho (1) =-1 .; nneigh (ordrho (1) = 0; % generate the delta and nneigh Arrays for II = 2: Nd Delta (ordrho (II) = maxd; for JJ = 1: II-1 if (Dist (ordrho (II), ordrho (jj) <delta (ordrho (II ))) delta (ordrho (II) = dist (ordrho (II), ordrho (jj); nneweigh (ordrho (II) = ordrho (jj ); % Number of ordrho (jj) from the point closest to ordrho (II) in the data point with a higher record value) end endend % generate delta (ordrho (1) = max (delta (:)); % Decision Chart disp ('generated file: demo-graph ') disp ('column 1: density') disp ('column 2: delta') FID = fopen ('destin_gra PH ', 'w'); for I = 1: Nd fprintf (FID,' % 6.2f % 6.2f \ n', rock (I), delta (I )); end % select a rectangle disp ('select a rectangle enclosing cluster centers') % each computer, the root object of the handle has only one, that is, the screen, its handle is always 0% %> scrsz = get (0, 'screensize') % scrsz = % 1 1280 800% % 1280 and 800 are the resolutions of your computer, scrsz (4) is 800, scrsz (3) is 1280 scrsz = get (0, 'screensize'); % is a specified location, it seems that there is no auto: :-) figure ('position', [6 72 scrsz (3)/4. scrsz (4)/1.3]); % IND and Gamma do not use for I = 1: Nd Ind (I) = I; gamma (I) = rock (I) * delta (I ); end % draws a so-called "Decision Chart" subplot (, 1) TT = plot (ROV (:), 'O ', 'markersize', 5, 'markerfacecolor', 'k', 'markeredgecolor', 'k'); Title ('demograph ', 'fontsize', 15.0) xlabel ('\ ror') ylabel (' \ delta') subplot (, 1) rect = getrect (1); % getrect uses the mouse to intercept a rectangular area, in the rect, the coordinates (x, y) in the lower left corner of the % rectangle and the width and height of the intercepted rectangle are stored. Fig = rect (1); deltamin = rect (2); % The author admitted this was an error, which has been changed from 4 to 2! % Number of cluster initialization nclust = 0; % Cl is the owner mark array, Cl (I) = J indicates that the data point I belongs to cluster J %. First, initialize Cl as-1for I = 1: Nd Cl (I) =-1; end % The number of statistical points (that is, the cluster center) in the rectangular area for I = 1: nd if (rock (I)> fig) & (delta (I)> deltamin) nclust = nclust + 1; CL (I) = nclust; % The number of I data points belongs to the nclust cluster ICL (nclust) = I; % ing, the center of the nclust cluster is the endendfprintf ('number of ters: % I \ n', nclust); disp ('grouping assignation') % place other data points Assignation for I = 1: nd if (CL (ordrho (I) =-1) Cl (ordrho (I )) = Cl (nneigh (ordrho (I); endend % because it is traversed in the order from the largest to the smallest number of records, after the loop ends, CL should all become a positive value. % process the halo point. The halo code should be moved to If (nclust> 1) for I = 1: Nd halo (I) = Cl (I ); endif (nclust> 1) % the initialization array bord_rov is 0, and each cluster defines a bord_rov value for I = 1: nclust bord_rov (I) = 0 .; end % gets a boundary of average density in each cluster bord_rov for I = 1: ND-1 for J = I + 1: nd % The distance between I and j if is small but not in the same cluster (CL (I )~ = Cl (j) & (Dist (I, j) <= Dc) fig = (rock (I) + rock (j)/2 .; % obtain the average local density of I and j points. If (Fig> bord_rov (CL (I) = fig; end if (Fig> fig (CL (j) = fig; the end % halo value is 0, indicating that Outlier for I = 1: nd if (I) <bord_rov (CL (I) halo (I) = 0; end endend % process each clusterfor I = 1: nclust NC = 0; % is used to accumulate the number of data points in the current cluster. nH = 0; % is used to accumulate the number of core data points in the current cluster for j = 1: nd if (CL (j) = I) NC = nC + 1; end if (halo (j) = I) nH = NH + 1; end fprintf ('Cluster: % I center: % I elements: % I core: % I halo: % I \ n ', i, ICL (I), NC, NH, NC-NH); endcmap = colormap; for I = 1: nclust Ic = int8 (I * 64 .) /(nclust * 1 .)); subplot (2, 1, 1) Hold on plot (rock (ICL (I), delta (ICL (I), 'O', 'markersize', 8, 'markerfacecolor ', cmap (IC, :), 'markeredgecolor', cmap (IC, :)); endsubplot (, 2) disp ('memory 2D nonclassical multidimensional scaling') Y1 = mdscale (Dist, 2, 'criterion ', 'metricstress'); plot (Y1 (:, 1), y1 (:, 2), 'O', 'markersize', 2, 'markerfacecolor', 'k', 'markeredgecolor', 'k'); Title ('2d nonclassical multidimen1_scaling', 'fontsize', 15.0) xlabel ('x ') ylabel ('y') for I = 1: nd a (I, 1) = 0 .; A (I, 2) = 0 .; endfor I = 1: nclust nn = 0; Ic = int8 (I * 64 .) /(nclust * 1 .)); for j = 1: nd if (halo (j) = I) nn = nn + 1; A (NN, 1) = Y1 (J, 1); A (NN, 2) = Y1 (J, 2); end hold on plot (A (1: NN, 1), a (1: NN, 2), 'O ', 'markersize', 2, 'markerfacecolor', cmap (IC, :), 'markeredgecolor', cmap (IC, :)); end % for I = 1: nd % IF (halo (I)> 0) % Ic = int8 (halo (I) * 64 .) /(nclust * 1 .)); % Hold on % plot (Y1 (I, 1), y1 (I, 2), 'O', 'markersize', 2, 'markerfacecolor', cmap (IC ,:), 'markeredgecolor', cmap (IC, :)); % end % endfaa = fopen ('Cluster _ assignation ', 'w'); disp ('generated file: cluster_assignation ') disp ('column 1: Element id') disp ('column 2: Cluster assignation without halo control') disp ('column 3: Cluster assignation with Halo control ') for I = 1: Nd fprintf (FAA, '% I \ n', I, Cl (I), Halo (I); End
Other links to this series of clustering algorithms:
Chapter 1 Introduction
Chapter 2 prerequisites
Chapter 3 direct Clustering
Chapter 4 K-means
Chapter 5 DBSCAN
Chapter 6 Optics
Chapter 7 Effectiveness Evaluation of cluster analysis
Chapter 8 Data Standardization
Author: peghoty
Source: http://blog.csdn.net/itplus/article/details/38926837
You are welcome to repost/share the article, but be sure to declare the source of the article.
A new clustering algorithm published on Science