社团检测seed选择Low conductance cuts
社团检测相关,虽然实现了seed的选择,但由于时间仓促,程序写的比较low,时间复杂度高!
function [ leader , ratio ] = isLeader2( adj)
%Reference:A Local Seed Selection Algorithm for Overlapping Community Detection
%@Author:xianyu
%Data:2019.2.26
%Disadvantage:high time complexity
%Input:networks adjacency matrix ( unweighted and undirected )
%Output:seed(leader),ratio(conductance)
leader = [];
n = size(adj,1);
neig = cell(1,n);
egonet = cell(1,n);
deg_v = zeros(1,n);
mid_adj = adj;
for i = 1:n
mid_adj(i,i) = 1;
index1 = find(mid_adj(i,:)==1);
egonet(1,i) = {{index1}}; %egonet:v and the neighbors of v
index2 = find(adj(i,:)==1);
deg_v(1,i) = length(index2); %the degree of each node
neig(1,i) = {{index2}}; %the neighbors of each node
end
col = zeros(3,n);
for i = 1:n
for j = 1:n
if find(mid_adj(i,j)==1)
col(1,i) = col(1,i) + deg_v(1,j);
else
col(2,i) = col(2,i) + deg_v(1,j);
end
end
col(3,i) = min(col(1,i), col(2,i)); %the denominator
end
mol = zeros(1,n); %the molecular
for i = 1:n
array = neig{1,i}{1,1};
m = length(array);
for j = 1:m
x = array(1,j);
for k = 1:n
if (adj(x,k)==1 && k~= i && ~ismember(k,array))
mol(1,i) = mol(1,i) + 1;
end
end
end
end
ratio = zeros(1,n);
for i = 1:n
ratio(1,i) = mol(1,i)/col(3,i);
end
for i = 1:n
p = 0; %the counter
array = neig{1,i}{1,1};
m = length(array);
for j = 1:m
x = array(1,j);
if ratio(1,i) > ratio(1,x)
break;
else
p = p + 1;
end
end
if p == m
leader = [leader;i];
end
end
end