The following two examples use data in the both cited papers mentioned in the index page.
In [1]:
import networkx as nx
nx.__version__
Out[1]:
In [2]:
from modularity_maximization import partition
from modularity_maximization.utils import get_modularity
In [3]:
karate = nx.Graph(nx.read_pajek("data/karate.net"))
In [4]:
print(nx.info(karate))
In [5]:
comm_dict = partition(karate)
In [6]:
for comm in set(comm_dict.values()):
print("Community %d"%comm)
print(', '.join([node for node in comm_dict if comm_dict[node] == comm]))
In [7]:
print('Modularity of such partition for karate is %.3f' % get_modularity(karate, comm_dict))
In [8]:
jazz = nx.Graph(nx.read_pajek("data/jazz.net"))
In [9]:
print(nx.info(jazz))
In [10]:
comm_dict = partition(jazz)
In [11]:
for comm in set(comm_dict.values()):
print("Community %d"%comm)
print(', '.join([node for node in comm_dict if comm_dict[node] == comm]))
In [12]:
print('Modularity of such partition for jazz is %.3f' % get_modularity(jazz, comm_dict))
In [13]:
big_10_football = nx.read_gml("data/big_10_football_directed.gml")
In [14]:
print(nx.info(big_10_football))
In [15]:
comm_dict = partition(big_10_football)
In [16]:
for comm in set(comm_dict.values()):
print("Community %d"%comm)
print(', '.join([node for node in comm_dict if comm_dict[node] == comm]))
In [17]:
print('Modularity of such partition for karate is %.3f' %\
get_modularity(big_10_football, comm_dict))