-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDCHDP.m
83 lines (64 loc) · 1.74 KB
/
DCHDP.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
function [ Z ] = DCHDP(SimMatrix,dc,Tclass)
% DC-HDP clustering algorithm with hierarchical outputs
NumIns=size(SimMatrix,2);
Density=sum(SimMatrix'<=dc);
NeigDisList={};
NeigDisList{NumIns}=[];
NDL=zeros(1,NumIns);
NeigInsList={};
NeigInsList{NumIns}=[];
%% link to higher density points
[~,SortDensity]=sort(Density,'descend');
for j=2:NumIns
i=SortDensity(j);
index1=SortDensity(1:j-1);
index=index1(Tclass(index1)==Tclass(i));
[a, b]=min(SimMatrix(i,index));
if ~isempty(a)
NeigDisList{i}=a;
NeigInsList{i}=index(b);
NDL(i)=NeigDisList{i}(1);
% NIL(i)=NeigInsList{i}(1);
end
end
NDL(SortDensity(1))=max(NDL(:));
%% Normalise
Density=normalize(Density');
NDL=normalize(NDL');
Mult=(Density').*(NDL');
%% building tree
Z=[];
CanList=[];
Nindex=NumIns+1; % point label in tree
NLabel=1:NumIns;
scoreList=[Mult; NLabel]'; % combine Mult with point real index
M=max(max(SimMatrix));
while (~isempty(scoreList))
I=scoreList(:,1);
[a, ii]=min(I);
b=scoreList(ii,2); % find point real index
if isempty(NeigInsList{b})
CanList=[CanList b];
scoreList(ii,:)=[];
else
nZ=[NLabel(b) NLabel(NeigInsList{b}(1)) a];
NLabel(NLabel==NLabel(b))=Nindex;
NLabel(NLabel==NLabel(NeigInsList{b}(1)))=Nindex;
Nindex=Nindex+1;
scoreList(ii,:)=[];
Z=[Z;nZ];
end
end
if ~isempty(Z)
M=max(Z(:,3));
else
M=1;
end
for i=1:length(CanList)-1
nZ=[NLabel(CanList(i)) NLabel(CanList(i+1)) M*1.1];
NLabel(NLabel==NLabel(CanList(i)))=Nindex;
NLabel(NLabel==NLabel(CanList(i+1)))=Nindex;
Nindex=Nindex+1;
Z=[Z;nZ];
end
end