Code covered by the BSD License  

Highlights from
Estimating the number of clusters via System Evolution

from Estimating the number of clusters via System Evolution by Kaijun Wang
estimate number of clusters for far clusters, small-larger clusters, slightly overlapping clusters

walk_route(DM, A1, startpoint,ch)
function [Rout, id, route] = walk_route(DM, A1, startpoint,ch)

  ns = length(A1);
  m = round(ns/2);
  [nt, points] = sort(DM(startpoint,A1));
  points = A1(points);
  steppair = []; 
  route = [];
  nt = startpoint;
  
  for i=1:2
    ra=(i-1)*m+1; 
    rb=i*m; 
    rc=m;
    if i==2 
        rb=ns; 
        rc=rb-ra+1; 
    end
    na=points(ra:rb);
    nb=[nt na];
    [id,Dm]=walk_propagat(1-DM(nb,nb),1);
    Dm=1-Dm;
    
    if i==1 
        nb=nb(id);
    else
        nb=nb(id(2:rc+1));
    end
    nt = nb(rc);
    steppair = [steppair nb];
    route = [route Dm];
  end
  
route = route(2:ns);
steppair = steppair(2:ns+1);
nb = [fix(0.5*ns) fix(0.33*ns)];
if length(ns) < 4
   nb = [1 2];
end
id = steppair(nb);

Dm = DM(steppair,steppair);
stepRout = diag(Dm,1)';
sortRout = sort(-stepRout);
sortRout = -sortRout;
if ch == 10
na = 1;
else
na = round(0.1*ns);
na = max([na 1]);
end
nt = round(sqrt(ns));
nt = ns-nt;
middleRout = mean(sortRout(na:nt));

m = sortRout(na:ns-1);
rc = m;
ra = rc.*m;
rb = sum(rc);
weightRout = sum(ra)/rb;

weightroute = sort(-route);
weightroute = -weightroute;
m = weightroute(na:ns-1);
rc = m;
ra = rc.*m;
rb = sum(rc);
weightroute = sum(ra)/rb;

if ch == 10
   Rout = [0.5*(weightRout+middleRout) weightroute];
else
   Rout = [0.5*(weightRout+middleRout) mean(m)];
end

Contact us at files@mathworks.com