In [1]:
%load_ext autoreload
%autoreload 2
import networkx as nx
import nxtools
import nxtools as nxt
import scipy
import scipy.special
import logging

logging.basicConfig(format="[%(asctime)s] {%(filename)s:%(lineno)d} %(levelname)s - %(message)s")
logging.getLogger().setLevel(logging.INFO)

unwieghted/undirected

[2013-03-27 12:11:34,663] {quality.py:204} INFO - comm, len(comm), v1, v2 = mOv: 0 24 -0.400224368509 0.938405797101 [2013-03-27 12:11:34,666] {quality.py:204} INFO - comm, len(comm), v1, v2 = mOv: 1 21 -0.710741854157 1.05 [2013-03-27 12:11:34,669] {quality.py:204} INFO - comm, len(comm), v1, v2 = mOv: 2 38 -0.295849750399 0.866287339972 [2013-03-27 12:11:34,671] {quality.py:204} INFO - comm, len(comm), v1, v2 = mOv: 3 33 -0.354888129903 0.999053030303 [2013-03-27 12:11:34,677] {quality.py:204} INFO - comm, len(comm), v1, v2 = mOv: 4 63 -0.162494808781 1.01152073733 -0.0948530819054


In [2]:
graph_file = '/Users/aonghus/work/bike_networks/communities/oslom/large/complete.dat'
comm_file = '/Users/aonghus/work/bike_networks/communities/oslom/large/tp'

In [5]:
#directed, weighted = False, False
directed, weighted = True, True

create_using = nx.DiGraph() if directed else nx.Graph()
weight = 'weight' if weighted else None

graph = nx.read_weighted_edgelist(graph_file, nodetype=int, create_using=create_using)
comm = nxt.readCommunityFromTP(comm_file)
comm_aff = nxt.affiliation_dict(comm)
graph.remove_edges_from(graph.selfloop_edges())
print graph.is_directed(), graph.is_multigraph()


False False

In [6]:
#reload(nxt)
print nxt.modularityOverlap(graph, comm, affiliation_dict=comm_aff, weight=weight)


[2013-03-27 17:18:01,258] {quality.py:212} INFO - comm, len(comm), v1, v2 = mOv: 0 24 -0.416778806122 0.894927536232 -0.372986830116
[2013-03-27 17:18:01,261] {quality.py:212} INFO - comm, len(comm), v1, v2 = mOv: 1 21 -0.720847425975 1.0 -0.720847425975
[2013-03-27 17:18:01,265] {quality.py:212} INFO - comm, len(comm), v1, v2 = mOv: 2 38 -0.308647551536 0.839260312945 -0.259035640692
[2013-03-27 17:18:01,269] {quality.py:212} INFO - comm, len(comm), v1, v2 = mOv: 3 33 -0.367812877422 0.967803030303 -0.355970417354
[2013-03-27 17:18:01,278] {quality.py:212} INFO - comm, len(comm), v1, v2 = mOv: 4 63 -0.170179894826 0.995391705069 -0.169395655679
-0.0939117984908

In [ ]: