-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathesvcLabel.m
133 lines (113 loc) · 4.61 KB
/
esvcLabel.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
function [model] = esvcLabel(data,model)
%==========================================================================
% E-SVC Labeling
%
% Reference
% J. Lee and D. Lee, Dynamic Characterization of Cluster Structures for
% Robust and Inductive Support Vector Clustering, IEEE TPAMI 28-(11),
% 1869-1874, 2006.
%
%==========================================================================
% January 13, 2009
% Implemented by Daewon Lee
% WWW: http://sites.google.com/site/daewonlee/
%==========================================================================
%
X=data.X';
y=data.y';
K=model.options.NofK;
[N, attr] = size(X);
% Find SEPs
[rep_locals,locals,local_val,match_local]=FindLocal(X,model);
NofLocals=size(locals,1);
model.local=locals';
% Find transition points and label the SEPs
[ts]=Find_TSs(locals,model);
nOfTS=length(ts.f);
%% Cluster assignment of each data point
% --- Automatic determination of cluster number based on the cluster boundary
if K==0
disp('Automatic determination of cluster numbers based on the SVDD boundearies defined by R^2');
adjacent = zeros(NofLocals,NofLocals);
tmp=find(ts.f<model.r+10^(-7));
if ~isempty(tmp) % only check the connectivity of TSs inside the sphere
for j=1:length(tmp)
adjacent(ts.neighbor(tmp(j),1),ts.neighbor(tmp(j),2))=1;
adjacent(ts.neighbor(tmp(j),2),ts.neighbor(tmp(j),1))=1;
end
%% To connect nodes which can be connected via directly connected edges.
for i=1:NofLocals
for j=1:i
if (adjacent(i,j) == 1)
adjacent(i,:) = (adjacent(i,:) | adjacent(j,:));
end
end
end
local_clusters_assignments = FindConnectedComponents(adjacent);
end
% model update
model.ts.x=ts.x(tmp,:);
model.ts.f=ts.f(tmp,:);
model.ts.purturb=ts.purturb(tmp,:);
model.ts.neighbor=ts.neighbor(tmp,:);
model.ts.cuttingLevel=model.r;
% cluster assignment into entire data points
model.cluster_labels = local_clusters_assignments(match_local)';
% --- Controling the number of clusters
else
local_clusters_assignments=[];
%ts.f
%model.rsq
f_sort=sort(ts.f);
adjacent = zeros(NofLocals,NofLocals,nOfTS);
a=[];
flag=0;
for m=1:nOfTS
cur_f=f_sort(end+1-m); % cutting level:large --> small (small number of clusters --> large number of clusters)
%cur_f=f_sort(i); % cutting level: small --> large (large number of clusters --> small number of clusters)
tmp=find(ts.f<cur_f);
if ~isempty(tmp) % No TSs inside the sphere
for j=1:length(tmp)
adjacent(ts.neighbor(tmp(j),1),ts.neighbor(tmp(j),2),m)=1;
adjacent(ts.neighbor(tmp(j),2),ts.neighbor(tmp(j),1),m)=1;
end
%% To connect nodes which can be connected via directly connected edges.
for i=1:NofLocals
for j=1:i
if (adjacent(i,j,m) == 1)
adjacent(i,:,m) = (adjacent(i,:,m) | adjacent(j,:,m));
end
end
end
end % end of current TS
a=[a;cur_f];
my_ts.x=ts.x(tmp,:);
my_ts.f=ts.f(tmp,:);
my_ts.purturb=ts.purturb(tmp,:);
my_ts.neighbor=ts.neighbor(tmp,:);
my_ts.cuttingLevel=cur_f;
ind=find(ts.f==cur_f);
my_ts.levelx=ts.x(ind(1),:);
tmp_ts{m}=my_ts;
assignment = FindConnectedComponents(adjacent(:,:,m));
if max(assignment)==K
disp('We can find the number of K clusters');
% model update
model.ts=tmp_ts{m};
% cluster assignment into entire data points
model.cluster_labels = assignment(match_local)';
flag=1;
break;
end
local_clusters_assignments = [local_clusters_assignments assignment];
end % end of K-control
% cannot find k clusters
if flag==0
disp('Cannot find cluster assignments with K number of clusters, instead that we find cluster assignmentsthe with the nearest number of clusters to K !');
[dummy,ind]=min(dist2(max(local_clusters_assignments)',K));
%ts=[];
model.ts=tmp_ts{ind(1)};
local_clusters_assignments=local_clusters_assignments(:,ind(1));
model.cluster_labels = local_clusters_assignments(match_local);
end
end