Skip to content

Commit

Permalink
🎨 documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
GiulioRossetti committed May 19, 2024
1 parent c7b44ef commit 8035ccd
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 18 deletions.
22 changes: 11 additions & 11 deletions cdlib/lifecycles/algorithms/event_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ def _analyze_one_struct(target, reference) -> dict:
# ids_for_entropy.extend(newels_ids)

return {
"U": facet_unicity(ids_for_entropy),
"I": facet_identity(target, reference),
"O": facet_outflow(target, reference),
"Unicity": facet_unicity(ids_for_entropy),
"Identity": facet_identity(target, reference),
"Outflow": facet_outflow(target, reference),
"size": len(target),
}

Expand Down Expand Up @@ -69,14 +69,14 @@ def event_weights_from_flow(analyzed_flows: dict, direction: str) -> dict:

def _compute_event_scores(analyzed_flow: dict) -> list:
return [
(analyzed_flow["U"]) * (1 - analyzed_flow["I"]) * analyzed_flow["O"],
(1 - analyzed_flow["U"]) * (1 - analyzed_flow["I"]) * analyzed_flow["O"],
(analyzed_flow["U"]) * analyzed_flow["I"] * analyzed_flow["O"],
(1 - analyzed_flow["U"]) * analyzed_flow["I"] * analyzed_flow["O"],
(analyzed_flow["U"]) * analyzed_flow["I"] * (1 - analyzed_flow["O"]),
(1 - analyzed_flow["U"]) * analyzed_flow["I"] * (1 - analyzed_flow["O"]),
(analyzed_flow["U"]) * (1 - analyzed_flow["I"]) * (1 - analyzed_flow["O"]),
(1 - analyzed_flow["U"]) * (1 - analyzed_flow["I"]) * (1 - analyzed_flow["O"]),
(analyzed_flow["Unicity"]) * (1 - analyzed_flow["Identity"]) * analyzed_flow["Outflow"],
(1 - analyzed_flow["Unicity"]) * (1 - analyzed_flow["Identity"]) * analyzed_flow["Outflow"],
(analyzed_flow["Unicity"]) * analyzed_flow["Identity"] * analyzed_flow["Outflow"],
(1 - analyzed_flow["Unicity"]) * analyzed_flow["Identity"] * analyzed_flow["Outflow"],
(analyzed_flow["Unicity"]) * analyzed_flow["Identity"] * (1 - analyzed_flow["Outflow"]),
(1 - analyzed_flow["Unicity"]) * analyzed_flow["Identity"] * (1 - analyzed_flow["Outflow"]),
(analyzed_flow["Unicity"]) * (1 - analyzed_flow["Identity"]) * (1 - analyzed_flow["Outflow"]),
(1 - analyzed_flow["Unicity"]) * (1 - analyzed_flow["Identity"]) * (1 - analyzed_flow["Outflow"]),
]


Expand Down
9 changes: 4 additions & 5 deletions cdlib/lifecycles/classes/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ def compute_events_from_explicit_matching(self):
}

for e in lifecycle:
xtid = e[0].split("_")[0]
ytid = e[1].split("_")[0]
xtid = int(e[0].split("_")[0])
ytid = int(e[1].split("_")[0])
if xtid < ytid:
flows["+"][e[0]][e[1]] = set(
self.clustering.get_community(e[0])
Expand Down Expand Up @@ -288,8 +288,8 @@ def compute_events_with_custom_matching(
}

for e in lifecycle:
xtid = e[0].split("_")[0]
ytid = e[1].split("_")[0]
xtid = int(e[0].split("_")[0])
ytid = int(e[1].split("_")[0])
if e[2] > threshold:
if xtid < ytid:
flows["+"][e[0]][e[1]] = set(
Expand Down Expand Up @@ -321,7 +321,6 @@ def __instantiate_events(self, flows, events):
self.events[cid].set_out_flow(flows["+"][cid])

for cid in flows["-"]:
print(cid)
if cid not in self.events:
self.events[cid] = CommunityEvent(cid)
self.events[cid].set_in_flow(flows["-"][cid])
Expand Down
19 changes: 19 additions & 0 deletions cdlib/test/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import networkx as nx
from networkx.generators.community import LFR_benchmark_graph
import matplotlib.pyplot as plt
import dynetx as dn
import os
from cdlib.viz import (
plot_flow,
Expand Down Expand Up @@ -78,6 +79,10 @@ def test_custom_matching(self):
c = events.analyze_flows("+")
self.assertIsInstance(c, dict)

events.compute_events_with_custom_matching(jaccard, two_sided=False, threshold=0)
c = events.analyze_flows("+")
self.assertIsInstance(c, dict)

def test_polytree(self):
tc = TemporalClustering()
for t in range(0, 10):
Expand Down Expand Up @@ -155,6 +160,20 @@ def test_viz(self):
plt.savefig("td.pdf")
os.remove("td.pdf")

def test_explicit(self):

dg = dn.DynGraph()
for x in range(10):
g = nx.erdos_renyi_graph(200, 0.05)
dg.add_interactions_from(list(g.edges()), t=x)
coms = algorithms.tiles(dg, 2)

events = LifeCycle(coms)
events.compute_events_from_explicit_matching()

c = events.analyze_flows("+")
self.assertIsInstance(c, dict)

def test_node_attributes(self):
import random

Expand Down
3 changes: 1 addition & 2 deletions docs/reference/events.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ To analyze such pre-computed events apply the following snippet:
dg.add_interactions_from(list(g.edges()), t=x)
coms = algorithms.tiles(dg, 2)
lc = LifeCycle()
lc.from_temporal_clustering(coms)
lc = LifeCycle(coms)
lc.compute_events_from_explicit_matching()
Expand Down

0 comments on commit 8035ccd

Please sign in to comment.