Skip to content

Commit

Permalink
🐛 node perception graph conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
GiulioRossetti committed Mar 12, 2019
1 parent 8f13283 commit 6631553
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cdlib/algorithms/overlapping_partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,18 @@ def node_perception(g, threshold, overlap_threshold, min_comm_size=3):
"""
g = convert_graph_formats(g, nx.Graph)
tp = type(list(g.nodes())[0])

with suppress_stdout():
np = NodePerception(g, sim_threshold=threshold, overlap_threshold=overlap_threshold,
min_comm_size=min_comm_size)
coms = np.execute()
if tp != str:
communities = []
for c in coms:
c = list(map(tp, c))
communities.append(c)
coms = communities

return NodeClustering(coms, g, "Node Perception", method_parameters={"threshold": threshold,
"overlap_threshold": overlap_threshold,
Expand Down
8 changes: 8 additions & 0 deletions cdlib/test/test_community_discovery_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ def test_node_perception(self):
self.assertEqual(type(coms.communities[0]), list)
self.assertEqual(type(coms.communities[0][0]), str)

g = nx.karate_club_graph()

coms = algorithms.node_perception(g, threshold=0.25, overlap_threshold=0.25)
self.assertEqual(type(coms.communities), list)
if len(coms.communities) > 0:
self.assertEqual(type(coms.communities[0]), list)
self.assertEqual(type(coms.communities[0][0]), int)

def test_angel(self):
g = get_string_graph()
coms = algorithms.angel(g, threshold=0.25)
Expand Down

0 comments on commit 6631553

Please sign in to comment.