-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_SBM.m
73 lines (67 loc) · 1.89 KB
/
test_SBM.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
%
% Dec 2018
% This matlab code is to test the Improved Graph Clustering method, on
% graphs generated by standard SBM
%
%
%
addpath SRC;
n=1000;
% number of clusters should be fixed for fairness of comparison.
r=5;
ALM_p_avg=zeros([1 13]);
slink_p_avg=zeros([1 13]);
theory_p=zeros([1 13]);
step1=1.05;
step2=1.1;
i=0;
for q=0:0.05:0.6
syms p positive
eqn = p-q-sqrt(p*(1-q)*n)/(n/r);
solp = vpasolve(eqn,p);
p = double(solp)+0.02;
i=i+1;
disp(['#round ' num2str(i) ': q=' num2str(q) ' theory_p=' num2str(p)])
for j=1:20
ALM_pur=0;
ALM_p=p;
while ALM_pur<0.99 && ALM_p<1
ALM_p=step1*ALM_p;
[A, clusters] = standard_SBM(n,r,ALM_p,q);
[ALM_cluster, A_dual] = improved_graph_cluster(A,r);
ALM_pur=purity(clusters, ALM_cluster);
end
if ALM_p>1
ALM_p=1;
end
ALM_p_avg(i) = ALM_p_avg(i) + ALM_p;
slink_pur=0;
slink_p=p;
while slink_pur<0.99 && slink_p<1
slink_p=step2*slink_p;
[A, clusters] = standard_SBM(n,r,slink_p,q);
slink_tree = linkage(A, 'single');
slink_cluster = cluster(slink_tree,'Maxclust',r);
slink_pur=purity(clusters, slink_cluster);
end
if slink_p>1
slink_p=1;
end
slink_p_avg(i) = slink_p_avg(i) + slink_p;
disp([' #trial ' num2str(j) ': IGC_p=' num2str(ALM_p)...
' SLINK_p=' num2str(slink_p)])
end
ALM_p_avg(i)=ALM_p_avg(i)/j;
slink_p_avg(i) = slink_p_avg(i)/j;
theory_p(i)=p;
end
figure()
plot(0:0.05:0.6,slink_p_avg,'o-')
hold on
plot(0:0.05:0.6,ALM_p_avg,'^-')
plot(0:0.05:0.6,theory_p,'.-')
hold off
legend('SLINK','IGC','Theory')
title('avg minimum p satisfying purity > 0.99 over 20 trials')
xlabel('q')
ylabel('p')