-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHclustering.m
93 lines (80 loc) · 2.81 KB
/
Hclustering.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
%Elaheh Rashedi
function [ cluster_matrix , num_of_clusters ] = Hclustering( R , C , upload_cluster, cluster_filename , upload_cluster_matrix, cluster_matrix_filename , num_of_clusters , norm_Intensity , norm_u_coef , features , cutoff , s_variance )
%====================CALCULATE CLUSTERING=====================
if upload_cluster == 1
% creating unsimilarity distance matrix for clustering
load(cluster_filename,'Z','Y'); % load distance from file
else
X = zeros (R*C,features);
%X = zeros (R*C,2);
Y = zeros (R*C,2);
% Intesity
if features==1
counter = 1 ;
for j=1:C
for i=1:R
%X (counter,1) = norm_Intensity(i,j);
X (counter,2) = norm_u_coef(i,j);
Y (counter,1) = j ;
Y (counter,2) = -i ;
counter = counter + 1 ;
end
end
% Intesity attenuation
elseif features==2
counter = 1 ;
for j=1:C
for i=1:R
X (counter,1) = norm_Intensity(i,j);
X (counter,2) = norm_u_coef(i,j);
Y (counter,1) = j ;
Y (counter,2) = -i ;
counter = counter + 1 ;
end
end
elseif features==3
counter = 1 ;
for j=1:C
for i=1:R
X (counter,1) = norm_Intensity(i,j);
X (counter,2) = norm_u_coef(i,j);
X (counter,3) = s_variance(i,j);
Y (counter,1) = j ;
Y (counter,2) = -i ;
counter = counter + 1 ;
end
end
end
tic;
cluster_timer = 0
%Z = linkage(X,'average','euclidean');
%Z = linkage(X,'single','euclidean');
Z = linkage(X,'ward','euclidean','savememory','on'); %minimum variance
%Z = linkage(X,'centroid','euclidean','savememory','on');
%Z = linkage(X,'median','euclidean','savememory','on');
cluster_timer = toc
save(cluster_filename,'Z','Y');
end
%=================CALCULATE CLUSTERING MATRXI=================
if upload_cluster_matrix == 1
load(cluster_matrix_filename,'cluster_matrix');
else
if cutoff == 0
clus = cluster(Z,'maxclust',num_of_clusters);
else % cutoff == 1
clus = cluster(Z,'cutoff',0.8);
end
figure, scatter(Y(:,1),Y(:,2),10,clus); title('\color{magenta}clustering result');
cluster_matrix = zeros (R,C);
% creating the cluster matrix
counter = 1 ;
for j=1:C
for i=1:R
%if ()
cluster_matrix (i,j) = clus (counter);
counter = counter + 1;
end
end
save(cluster_matrix_filename,'cluster_matrix');
end
end