-
Notifications
You must be signed in to change notification settings - Fork 0
/
edge_selection.m
70 lines (62 loc) · 1.95 KB
/
edge_selection.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
function [Kij2,e] = edge_selection(theta,SC,m,type)
if ~exist('type','var')
disp('No edge selection paradigm was given: most synchronized will be used by default')
type = 'Most';
end
n = size(SC,1);
N = size(SC,1);
inds = logical(triu(ones(N),1));
edges_flat = SC(inds);
edges_exist = find(edges_flat>0);
if type == 'Most'
theta_i = theta * ones(1,n); % (nxn) matrix with same theta values in each row
theta_j = ones(n,1) * theta'; % (nxn) matrix with same theta values in each col
r_i = exp(1i*theta_i);
r_j = exp(1i*theta_j);
r_ij = abs((r_i + r_j))./2; %take order parameter of all node pairs
q = (SC>0).*r_ij;
[~,I] = maxk(q,m);
Kij2 = zeros(n);
for ndx = 1:n
maxkind = I(:,ndx);
Kij2(maxkind,ndx) = SC(maxkind,ndx);
end
Kij2 = max(Kij2,Kij2');
e_tmp = Kij2(inds)>0;
e = e_tmp(edges_exist);
elseif type == 'Random'
q = SC>0;
z = 1:n;
Kij2 = zeros(n);
for ndx = 1:n
I = q(:,ndx);
if sum(I)<m
inds = I;
else
inds = datasample(z(I),m,'Replace',false);
end
Kij2(inds,ndx) = SC(inds,ndx);
end
Kij2 = max(Kij2,Kij2');
e_tmp = Kij2(inds)>0;
e = e_tmp(edges_exist);
elseif type == 'Least'
theta_i = theta * ones(1,n); % (nxn) matrix with same theta values in each row
theta_j = ones(n,1) * theta'; % (nxn) matrix with same theta values in each col
r_i = exp(1i*theta_i);
r_j = exp(1i*theta_j);
r_ij = abs((r_i + r_j))./2; %take order parameter of all node pairs
q = (SC>0).*r_ij;
q(SC==0) = inf;
[~,I] = mink(q,m);
Kij2 = zeros(n);
for ndx = 1:n
minkind = I(:,ndx);
Kij2(minkind,ndx) = SC(minkind,ndx);
end
Kij2 = max(Kij2,Kij2');
e_tmp = Kij2(inds)>0;
e = e_tmp(edges_exist);
else
disp('Type chosen is not an implemented one.')
end