-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathcollectiveMerging.m
54 lines (44 loc) · 1.6 KB
/
collectiveMerging.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
function [ clusterIndex ] = collectiveMerging( Zmatrix, para )
%COLLECTIVEMERGING extract components from Z matrix
% Mar.28,2013, Bolei Zhou
linkGraph = Zmatrix > para.threshold;
[ clusterIndex ] = linkGraph2cluster( linkGraph );
end
function [ clusterIndex ] = linkGraph2cluster( linkGraph )
[row,col] = find(linkGraph==1);
pairData = [row';col'];
clusterIndex = pairClustering(pairData,size(linkGraph,1));
end
function clusterIndex = pairClustering(pairwiseData,totalNum)
clusterNum = 0;
clusterIndex = zeros(1,totalNum);
for i = 1:size(pairwiseData,2)
curPair = pairwiseData(:,i);
curPairAlabel = clusterIndex(1,curPair(1));
curPairBlabel = clusterIndex(1,curPair(2));
if curPairAlabel == 0 && curPairBlabel == 0
clusterNum = clusterNum+1;
curPairLabel = clusterNum;
clusterIndex(1,curPair(1)) = curPairLabel;
clusterIndex(1,curPair(2)) = curPairLabel;
elseif curPairAlabel~=0 && curPairBlabel==0
clusterIndex(1,curPair(2)) = curPairAlabel;
elseif curPairBlabel~=0 && curPairAlabel==0
clusterIndex(1,curPair(1)) = curPairBlabel;
else
combineLabel = min(curPairAlabel,curPairBlabel);
clusterIndex(1,find(clusterIndex==curPairAlabel)) = combineLabel;
clusterIndex(1,find(clusterIndex==curPairBlabel)) = combineLabel;
end
end
newClusterNum = 0;
for i = 1:max(clusterNum)
curClusterIndex = find(clusterIndex==i);
if length(curClusterIndex)<10
clusterIndex(curClusterIndex) = 0;
else
newClusterNum = newClusterNum+1;
clusterIndex(curClusterIndex) = newClusterNum;
end
end
end