-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraph_Entropy_measure.py
71 lines (61 loc) · 1.71 KB
/
Graph_Entropy_measure.py
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
# coding: utf-8
import networkx as nx
import Selection_Algorithm
import math
# In[ ]:
#TR_i = tr-ceyntrality i subgraph
def graph():
import graph
Graph = graph.H
return Graph
H = graph()
# In[ ]:
#Graph Entropy
def log1(i):
sum_sdeg_i = (Selection_Algorithm.subgraph_of(i).number_of_edges()*2)
s1 = math.log(sum_sdeg_i, 10)
return s1
def prob(i, j):
sum_sdeg_i = (Selection_Algorithm.subgraph_of(i).number_of_edges()*2)
nodes = Selection_Algorithm.subgraph_of(i).nodes
degree = Selection_Algorithm.subgraph_of(i).degree[j]
prob=-(degree/sum_sdeg_i )
return prob
def log2(i,j):
degree = Selection_Algorithm.subgraph_of(i).degree[j]
log_j = math.log(degree, 10)
return log_j
def probs(i):
probs=[]
for i in Selection_Algorithm.subgraph_of(i).nodes:
for j in Selection_Algorithm.subgraph_of(i).nodes:
enr = (prob(i, j)*log2(i,j))
#enr=(i, en)
probs.append(enr)
return probs
def PI_of(i):
sum_sdeg_i = (Selection_Algorithm.subgraph_of(i).number_of_edges()*2)
NT_i = nx.triangles(H,i)
sdeg=Selection_Algorithm.subgraph_of(i).degree(i)
s1 = (math.log(sum_sdeg_i, 10)+NT_i)
#equetion 4:en value of PI_i
PI_i =s1-sum(probs(i))
return PI_i
# In[ ]:
#LOOP PI of the selected Set Of Subgraph
def loop_PI():
i=0
PI_list=[]
for i in Selection_Algorithm.sel_subgraphs():
NT_i = nx.triangles(H,i)
if NT_i > 1:
PI_i = round(PI_of(i), 4)
PI = i, 1/PI_i
PI_list.append(PI)
return PI_list
# In[ ]:
#ranking PI_list
def PI_Ranking( val ):
return val [1]
PI_Rank = loop_PI()
PI_Rank.sort(key=lambda elem: elem[1])