-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calculate_EQ.m
67 lines (60 loc) · 1.53 KB
/
Calculate_EQ.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
function EQ=Calculate_EQ(community,Adj_mat)
%%计算EQ的值
%community是一个细胞结构
global vertex_num degree edges_num EP;
%clu_num = max(clu_assignment);
degree=sum(Adj_mat,1);
edges_num=sum(degree,2)/2;
vertex_num=size(Adj_mat,1);
%在计算EQ之前,先获得一张表,这张表示2*n,n为在community中出现的节点的个数(不包括重复的)
temp=[];
N=length(community);
for i=1:N
a=community{i};
temp=[temp a];
temp=unique(temp);%取temp的不重复元素
end;
n=length(temp);
Table=zeros(2,n);
for j=1:n
node=temp(j);
num=contain_num(community,node);
Table(1,j)=node;
Table(2,j)=num;
end;
N=length(community);
EQ=0;
for i=1:N
a=community{i};
v_num=length(a);%v_num为每个社团的节点数目
temp=0;
for j=1:v_num
v1=a(j);
%计算所有社团中包含v1节点的个数
contain_v1_num=Table(2,find(Table(1,:)==v1));
% contain_v1_num=contain(community,v1);
for k=j+1:v_num
v2=a(k);
contain_v2_num=Table(2,find(Table(1,:)==v2));
% contain_v2_num=contain(community,v2);
temp1=Adj_mat(v1,v2)-(degree(v1)*degree(v2)/(2*edges_num));
temp2=temp1/(contain_v1_num*contain_v2_num);
temp=temp+temp2;
end;
end;
EQ=EQ+temp;
end;
EQ=EQ/(2*edges_num);
function num=contain_num(community,v)
%%函数功能:输出community中包含节点v的社团的个数
%community是一个细胞结构
num=0;
n=length(community);
for i=1:n
a=community{i};
if any(a==v)==1
num=num+1;
end;
end;
end
end