-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathECPCS_HC.m
59 lines (45 loc) · 2.06 KB
/
ECPCS_HC.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This is the code for ECPCS-HC, which is an ensemble clustering algorithm%
% proposed in the following paper: %
% %
% D. Huang, C.-D. Wang, H. Peng, J. Lai, & C.-K. Kwoh. "Enhanced Ensemble %
% Clustering via Fast Propagation of Cluster-wise Similarities."To appear %
% in IEEE Transactions on Systems, Man, and Cybernetics: Systems. %
% DOI: 10.1109/TSMC.2018.2876202 %
% %
% The code has been tested in Matlab R2016a and Matlab R2016b. %
% %
% www.researchgate.net/publication/328581758 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function Label = ECPCS_HC(baseCls, K, t)
% Dong Huang. Sep. 28, 2018.
if nargin < 3
t = 20;
end
[bcs, baseClsSegs] = getAllSegs(baseCls);
clsSim = full(simxjac(baseClsSegs)); % Build the cluster similarity matrix by Jaccard coefficient.
clsSimRW = computePTS_II(clsSim, t); % Perform random walks and obtain a new cluster-wise similarity matrix.
ECA = getECA(bcs,clsSimRW);
Label = runHC(ECA, K);
function Label = runHC(S, ks)
% Input: the similarity matrix
% and the numbers of clusters.
% Output: the clustering result.
N = size(S,1);
d = stod(S); clear S %convert similarity matrix to distance vector
% average linkage
Zal = linkage(d,'average'); clear d
Label = zeros(N,numel(ks));
for iK = 1:numel(ks)
Label(:,iK) = cluster(Zal,'maxclust',ks(iK));
end
function d = stod(S)
% Dong Huang. Apr. 19, 2018.
N = size(S,1);
s = zeros(1,(1+N-1)*(N-1)/2);
nextIdx = 1;
for a = 1:N-1 %change matrix's format to be input of linkage fn
s(nextIdx:nextIdx+(N-a-1)) = S(a,[a+1:end]);
nextIdx = nextIdx + N - a;
end
d = 1 - s;