In [1]:
import sys
# the mock-0.3.1 dir contains testcase.py, testutils.py & mock.py
sys.path.append("/Users/cazabetremy/Documents/GitHub/dynetx")
import dynetx as dn
In [2]:
dynG = dn.readSnapshotsDir("/Users/cazabetremy/Dropbox/dev/GOT/")
In [3]:
print("nbNodes:",len(dynG.nodes()))
print("nbSteps: ",len(dynG.snapshots()))
nbNodes: 321
nbSteps:  104
In [4]:
print("apparitions Jon:",dynG.nodeLife()["Jon_Snow"])
apparitions Jon: ['GoT_S01E01_000', 'GoT_S01E01_010', 'GoT_S01E01_020', 'GoT_S01E01_030', 'GoT_S01E02_040', 'GoT_S01E03_061', 'GoT_S01E03_071', 'GoT_S01E03_081', 'GoT_S01E04_092', 'GoT_S01E04_102', 'GoT_S01E06_144', 'GoT_S01E07_155', 'GoT_S01E07_165', 'GoT_S01E08_176', 'GoT_S01E08_186', 'GoT_S01E08_196', 'GoT_S01E09_206', 'GoT_S01E09_216', 'GoT_S01E10_226', 'GoT_S01E10_236', 'GoT_S01E10_246', 'GoT_S02E01_257', 'GoT_S02E02_268', 'GoT_S02E02_278', 'GoT_S02E03_289', 'GoT_S02E05_330', 'GoT_S02E05_340', 'GoT_S02E06_351', 'GoT_S02E07_362', 'GoT_S02E07_372', 'GoT_S02E07_382', 'GoT_S02E08_392', 'GoT_S02E10_442', 'GoT_S02E10_452', 'GoT_S03E01_463', 'GoT_S03E01_473', 'GoT_S03E02_484', 'GoT_S03E02_494', 'GoT_S03E03_505', 'GoT_S03E04_536', 'GoT_S03E05_547', 'GoT_S03E05_557', 'GoT_S03E06_568', 'GoT_S03E06_578', 'GoT_S03E07_589', 'GoT_S03E07_599', 'GoT_S03E08_620', 'GoT_S03E10_652', 'GoT_S03E10_662', 'GoT_S04E01_673', 'GoT_S04E01_683', 'GoT_S04E03_705', 'GoT_S04E03_715', 'GoT_S04E04_726', 'GoT_S04E04_736', 'GoT_S04E05_747', 'GoT_S04E05_757', 'GoT_S04E06_768', 'GoT_S04E07_779', 'GoT_S04E07_789', 'GoT_S04E08_810', 'GoT_S04E09_821', 'GoT_S04E09_831', 'GoT_S04E10_841', 'GoT_S04E10_851', 'GoT_S05E01_862', 'GoT_S05E01_872', 'GoT_S05E02_882', 'GoT_S05E02_892', 'GoT_S05E02_902', 'GoT_S05E03_913', 'GoT_S05E03_923', 'GoT_S05E04_934', 'GoT_S05E04_944', 'GoT_S05E04_954', 'GoT_S05E05_965', 'GoT_S05E05_975', 'GoT_S05E06_985', 'GoT_S05E06_995', 'GoT_S05E07_1017', 'GoT_S05E08_1027', 'GoT_S05E09_1038', 'GoT_S05E09_1048', 'GoT_S05E10_1059']
In [5]:
(t,g) = dynG.snapshots().peekitem(0)
print("first time: ",t)
print("nodes: ",g.nodes())
first time:  GoT_S01E01_000
nodes:  ['Gared', 'Waymar_Royce', 'Will', 'Cersei_Lannister', 'Jaime_Lannister', 'Theon_Greyjoy', 'Robb_Stark', 'Jon_Snow', 'Eddard_Stark', 'Brandon_Stark', 'Sansa_Stark', 'Mordane', 'Rodrik_Cassel', 'Catelyn_Stark']

Communities

First algorithm by Greene et al. : detect communities in each snaphsot. Match communities between t and t+1 according to Jaccard coefficient

In [6]:
from dynetx import DCD
coms = DCD.greene(dynG,mt=0.3)
dn.show(coms,dynG)

Problem : too many nodes displayed. Filtering nodes appearing less than x times

In [7]:
durations = dynG.nodeLife()
unfrequentNodes = [n for n in durations if len(durations[n])<=10]
dynG.remove_nodes_from(unfrequentNodes)
coms = DCD.greene(dynG,mt=0.3)
dn.show(coms,dynG)

Problem: the network is not stable enough to obtain stable communities.

Solution 1: Use another algorithm allowing to match communities at longer temporal distance

In [8]:
coms = DCD.comSurvivalGraph(dynG,mt=0.3)
dn.show(coms,dynG)

Solution 2: reduce the granularity, i.e aggregate snapshots every x

In [9]:
dynG.aggregate(10)
coms = DCD.greene(dynG,mt=0.3)
dn.show(coms,dynG)

Let's try another algorithm with overlaps and "free" nodes

In [10]:
coms = DCD.rollingCPM(dynG,k=3)
dn.show(coms,dynG)

Let's try an algorithm with smoothing

In [18]:
coms = DCD.mucha(dynG,om=0.3)
dn.show(coms,dynG)
In [ ]: