Skip to content
Snippets Groups Projects
Commit 030475fa authored by Jarrod Pas's avatar Jarrod Pas
Browse files

Finish up node community statistics

parent 3d4e40aa
No related branches found
No related tags found
2 merge requests!3Version 0.2,!1Full rewrite
...@@ -135,6 +135,7 @@ class Community: ...@@ -135,6 +135,7 @@ class Community:
def local_popularity(self, node): def local_popularity(self, node):
"""Return local popularity of a node.""" """Return local popularity of a node."""
graph = self.graph_old graph = self.graph_old
if node not in graph: if node not in graph:
return 0 return 0
...@@ -147,6 +148,7 @@ class Community: ...@@ -147,6 +148,7 @@ class Community:
def global_popularity(self, node): def global_popularity(self, node):
"""Return global popularity of a node.""" """Return global popularity of a node."""
graph = self.graph_old graph = self.graph_old
if node not in graph: if node not in graph:
return 0 return 0
...@@ -159,27 +161,43 @@ class Community: ...@@ -159,27 +161,43 @@ class Community:
def unique_interactions(self, node): def unique_interactions(self, node):
"""Unique interactions for a node within it's community.""" """Unique interactions for a node within it's community."""
graph = self.graph_old graph = self.graph_old
if node not in graph: if node not in graph:
return 0 return 0
return len( return len(
other other
for other in node.community for other in node.community
if other in graph[node] if graph.has_edge(node, node)
) )
def community_betweenness(self, node_a, node_b): def community_betweenness(self, node_a, node_b):
"""Return community betweenness for 2 nodes.""" """Return community betweenness for 2 nodes."""
graph = self.graph_old
community_a = self[node_a] community_a = self[node_a]
community_b = self[node_b] community_b = self[node_b]
if community_a == community_b: if community_a == community_b:
return float('inf') return float('inf')
return sum(
graph[a][b]['duration']
for a, b in product(community_a, community_b)
if graph.has_edge(a, b)
)
def nodal_contribution_factor(self, node_a, node_b):
"""Return nodal contribution factor of node_a in node_b's community."""
graph = self.graph_old graph = self.graph_old
community_b = self[node_b]
if node_a not in graph or node_a in community_b:
return 0
return sum( return sum(
graph[node_a][node_b]['duration'] graph[node_a][b]['duration']
for node_a, node_b in product(community_a, community_b) for b in community_b
if node_a in graph and node_b in graph[node_a] if graph.has_edge(node_a, b)
) )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment