-
Notifications
You must be signed in to change notification settings - Fork 0
/
bramila_netTh.m
50 lines (45 loc) · 926 Bytes
/
bramila_netTh.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
function [idsout, MST]=bramila_netTh(A,th,MST)
% A = adj matrix
% th = vector of percetages of link density
R=size(A,1);
L=(R^2-R)/2;
ids=find(triu(ones(size(A)),1));
[vals edgt]=sort(A(ids),'descend');
edg=ids(edgt);
if(size(MST,1)>1)
MST=sign(MST);
else
%% build mst
GCC=0;
MST=zeros(size(A));
counter=1;
oldcosiz=-1;
while(GCC<R)
temp=triu(MST,1);
temp(edg(counter))=1;
temp=temp+temp';
[co,cosiz]=get_components(temp);
if(max(cosiz)>oldcosiz)
MST=temp;
oldcosiz=max(cosiz);
GCC=max(cosiz);
end
counter=counter+1;
fprintf([num2str(counter) '..'])
end
end
idsMST=find(triu(MST,1));
size(idsMST)
edg=setdiff(edg,idsMST,'stable');
edg=[idsMST;edg];
tt=round(th*L/100);
for t=1:length(tt)
idsout{t}=edg(1:tt(t));
%temp=zeros(size(A));
%temp(idsout{t})=1;
%temp=temp+temp';
%[co,cosiz]=get_components(temp);
%if(max(cosiz)<R)
% disp([num2str(th(t)) ' would need an MST']);
% end
end