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
dynG = dn.readSnapshotsDir("/Users/cazabetremy/Dropbox/dev/GOT/")
print("nbNodes:",len(dynG.nodes()))
print("nbSteps: ",len(dynG.snapshots()))
print("apparitions Jon:",dynG.nodeLife()["Jon_Snow"])
(t,g) = dynG.snapshots().peekitem(0)
print("first time: ",t)
print("nodes: ",g.nodes())
First algorithm by Greene et al. : detect communities in each snaphsot. Match communities between t and t+1 according to Jaccard coefficient
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
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
coms = DCD.comSurvivalGraph(dynG,mt=0.3)
dn.show(coms,dynG)
Solution 2: reduce the granularity, i.e aggregate snapshots every x
dynG.aggregate(10)
coms = DCD.greene(dynG,mt=0.3)
dn.show(coms,dynG)
Let's try another algorithm with overlaps and "free" nodes
coms = DCD.rollingCPM(dynG,k=3)
dn.show(coms,dynG)
Let's try an algorithm with smoothing
coms = DCD.mucha(dynG,om=0.3)
dn.show(coms,dynG)