-
Notifications
You must be signed in to change notification settings - Fork 2
/
densityBasedCharacteristics.py
38 lines (36 loc) · 1.07 KB
/
densityBasedCharacteristics.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
from igraph import *
import numpy as np
from auxiliaryFunctions import *
def hubDensity(g):
"""
g: Graph, each component of the graph is a hub
return: The average density of subgraphs induced by hubs
"""
components = g.components()
n_components = len(components)
sum = 0
for c in components:
sum += len(c)
return sum / n_components
def definition523(g, k= 1, degreeProduct= True):
"""
g: Graph
k: Number of edge removal, default = 1
degreeProduct: Degree product is the strategy for the removal, if false, edge betweenness
return: The average fraction of edges in the largest connected component after k edge removals
"""
aux = g.copy()
sum = 0
for q in range(k):
if degreeProduct:
id_edge = maxDegreeProduct(aux)
else:
id_edge = maxEdgeBetweenness(aux)
aux.delete_edges(id_edge)
comp = aux.components()
max_len = 0
for c in comp:
if len(c) > max_len:
max_len = len(c)
sum += max_len
return sum / k