Code covered by the BSD License  

Highlights from
Recognizing Far-Near Relations of Clusters by GDEM, Visualization by Line-Pearl Pattern

image thumbnail

Recognizing Far-Near Relations of Clusters by GDEM, Visualization by Line-Pearl Pattern

by

 

21 Aug 2010 (Updated )

measure far-near degrees (distances) between clusters & dense degrees of border regions of clusters

clusterrun(whichAP,data,K,type,simatrix,Dist,...
function [label,Dist] = clusterrun(whichAP,data,K,type,simatrix,Dist,...
    truelabels,nrun,nconv,lam,splot)
disp(' '); disp('==> fastAP clustering is running ...');
nrow = size(data,1);
if ~simatrix
    Dist = simatrix_ap(data,type,0);
elseif simatrix == 1  % transform to similarity distances
    dpsim = min(min(Dist));
    if dpsim < 0
        Dist = -1+(1+Dist)/2;
    else
        Dist = -1+Dist;
    end
    for i=1:nrow
        Dist(i,i) = 0;
    end
end

% finding K clusters exactly
tic;
disp(['    to find ' int2str(K) ' clusters. ' 'Type = ' int2str(type) '. ' date]);
% finding preference bounds: lowp & highp
[labelid,netsim,dpsim,expref,pref,lowp,highp]=apclusterK_fast1(whichAP,Dist,1,0);

if strcmp(whichAP,'sparse') || strcmp(whichAP,'auto') && nrow>3000
    nap = nrow*nrow-nrow;
    s = zeros(nap,3);
    j=1;    
    for i=1:nrow
        for k = [1:i-1,i+1:nrow]
            s(j,1) = i;
            s(j,2) = k;
            s(j,3) = Dist(i,k);
            j = j+1;
        end;
    end;
    for i = 1:length(K)
        [labelid(:,i),netsim,dpsim,expref,pref]=apclusterK_fast1(whichAP,...
            s,K(i),0,nrun,nconv,lam,lowp,highp,nrow,splot);
    end
else
    for i = 1:length(K)
        [labelid(:,i),netsim,dpsim,expref,pref]=apclusterK_fast1(whichAP,...
            Dist,K(i),0,nrun,nconv,lam,lowp,highp,nrow,splot);
    end
end
trun = toc;
fprintf('## Running time = %g seconds \n', trun);
[Q, label] = ind2cluster(labelid);

% Error rates of clustering solution
if ~isempty(truelabels)
fprintf('\n## Error rate of clustering solution (if large, use FM index)');
fprintf('\n   Notice: cluster No. might not match that in "label".');
Rerror = valid_errorate(label, truelabels);
C = valid_external(label, truelabels);
fprintf('## Fowlkes-Mallows validity index: %f\n', C(4));
end

Contact us