-
Notifications
You must be signed in to change notification settings - Fork 0
/
script_gene_data.m
110 lines (94 loc) · 2.64 KB
/
script_gene_data.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
addpath(genpath('./lib/gpml-matlab-v4.2-2018-06-11'))
addpath(genpath('./lib/Ncut_9'))
addpath(genpath('./lib/ZPclustering'))
load('gene_data.mat')
%% compute distances
[bfm,d_breg] = BF_onehyp(data_s,t);
sm = bfm;
n = length(sm);
dist_bf = 1 + max(sm(:)) - sm;
dist_bf(1:n+1:end) = 0;
dist_dtw = zeros(n,n);
for i=1:n
for j=1:n
dist_dtw(i,j) = dtw(data_s(i,:),data_s(j,:));
end
end
%% hierarchical clustering
n_candi = 3:17;
lkge = 'complete';
Z = linkage(squareform(dist_bf),lkge);
ch = cluster(Z,'maxclust',n_candi);
dist_eu = squareform(pdist(data_s));
Z_eu = linkage(squareform(dist_eu),lkge);
ch_eu = cluster(Z_eu,'maxclust',n_candi);
Z_dtw = linkage(squareform(dist_dtw),lkge);
ch_dtw = cluster(Z_dtw,'maxclust',n_candi);
writeout_partition([ch,ch_eu,ch_dtw],'bf_complete_dtw.csv');
%% spectral clustering
neighbor_num = 10;
n_candi = 3:17;
D = dist_bf;
for k = 1:length(n_candi)
n_c = n_candi(k);
G = constructNetworkStructure(data',D,'knn',neighbor_num);
A = double(G);
[c_ncut,x] = ncutW(A,n_c);
c_ncut = transformHMatrixtoPartitionVector(c_ncut);
[c1,x] = gcut(A,n_c);
c_njw = c_ncut;
for i = 1:length(c1)
c_njw(c1{i}) = i;
end
C_ncut(:,k) = c_ncut;
C_njw(:,k) = c_njw;
end
D = squareform(pdist(data_s,'euclidean'));
for k = 1:length(n_candi)
n_c = n_candi(k);
G = constructNetworkStructure(data',D,'knn',neighbor_num);
A = double(G);
[c_ncut,x] = ncutW(A,n_c);
c_ncut = transformHMatrixtoPartitionVector(c_ncut);
[c1,x] = gcut(A,n_c);
c_njw = c_ncut;
for i = 1:length(c1)
c_njw(c1{i}) = i;
end
C_ncut_eu(:,k) = c_ncut;
C_njw_eu(:,k) = c_njw;
end
D = dist_dtw;
for k = 1:length(n_candi)
n_c = n_candi(k);
G = constructNetworkStructure(data',D,'knn',neighbor_num);
A = double(G);
[c_ncut,x] = ncutW(A,n_c);
c_ncut = transformHMatrixtoPartitionVector(c_ncut);
[c1,x] = gcut(A,n_c);
c_njw = c_ncut;
for i = 1:length(c1)
c_njw(c1{i}) = i;
end
C_ncut_dtw(:,k) = c_ncut;
C_njw_dtw(:,k) = c_njw;
end
D = d_breg;
for k = 1:length(n_candi)
n_c = n_candi(k);
G = constructNetworkStructure(data',D,'knn',neighbor_num);
A = double(G);
[c_ncut,x] = ncutW(A,n_c);
c_ncut = transformHMatrixtoPartitionVector(c_ncut);
[c1,x] = gcut(A,n_c);
c_njw = c_ncut;
for i = 1:length(c1)
c_njw(c1{i}) = i;
end
C_ncut_breg(:,k) = c_ncut;
C_njw_breg(:,k) = c_njw;
end
% save the partitions
writeout_partition([C_ncut_dtw,C_njw_dtw],'sc_dtw.csv');
writeout_partition([C_ncut,C_njw,C_ncut_eu,C_njw_eu],'sc_bf_eu.csv');
writeout_partition([C_ncut_breg,C_njw_breg],'sc_breg.csv');