-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathothercompare.m
65 lines (54 loc) · 1.52 KB
/
othercompare.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
%% compare with other methods.
nmit = [];
arit = [];
prty = [];
% compare given the number of clusters.
%% kmeans
[c_kmeans,C] = kmeans(data,n_g,'Replicates',50);
%% mixture models
obj = fitgmdist(data,n_g,'Replicates',10,'RegularizationValue',0.0001,'Start','RandSample');
c_gmm = cluster(obj,data);
%% hierarchical
Z = linkage(data,'complete','euclidean');
c_hcluster = cluster(Z,'maxclust',n_g);
%% ncut and NJW spectral clustering
neighbor_num = 12;
D = squareform(pdist(data,'euclidean'));
[D_LS,A_LS,LS] = scale_dist(D,floor(neighbor_num/2));
ZERO_DIAG = ~eye(size(data,1));
A_LS = A_LS.*ZERO_DIAG;
% spectral clustering with weighted matrix
n_c = n_g;
[c_ncut,x] = ncutW(A_LS,n_c);
c_ncut = transformHMatrixtoPartitionVector(c_ncut);
[c,x] = gcut(A_LS,n_c);
c_sc = c_ncut;
for i = 1:length(c)
c_sc(c{i}) = i;
end
% spectral clustering with Cknn graph
G = constructNetworkStructure(data',D,'cknn',7);
A = double(G);
[c_ncut1,x] = ncutW(A,n_c);
c_ncut1 = transformHMatrixtoPartitionVector(c_ncut1);
[c1,x] = gcut(A,n_c);
c_sc1 = c_ncut1;
for i = 1:length(c1)
c_sc1(c1{i}) = i;
end
%%
nmit(1) = nmi(c_kmeans,c_g);
nmit(2) = nmi(c_gmm,c_g);
nmit(3) = nmi(c_hcluster,c_g);
nmit(4) = nmi(c_ncut,c_g);
nmit(5) = nmi(c_sc,c_g);
arit(1) = adjrand(c_kmeans,c_g);
arit(2) = adjrand(c_gmm,c_g);
arit(3) = adjrand(c_hcluster,c_g);
arit(4) = adjrand(c_ncut,c_g);
arit(5) = adjrand(c_sc,c_g);
prty(1) = purity(c_kmeans,c_g);
prty(2) = purity(c_gmm,c_g);
prty(3) = purity(c_hcluster,c_g);
prty(4) = purity(c_ncut,c_g);
prty(5) = purity(c_sc,c_g);