예제 #1
0
 def test_empty(self):
     """
     Verify that an empty directed graph results in no compressor nodes
     """
     G = nx.DiGraph()
     compressed_graph, c_nodes = dedensify(G, threshold=2)
     assert c_nodes == set()
예제 #2
0
 def test_dedensify_edge_count(self):
     """
     Verifies that dedensify produced the correct number of comrpessor nodes
     in a directed graph
     """
     G = self.build_original_graph()
     original_edge_count = len(G.edges())
     c_G, c_nodes = dedensify(G, threshold=2)
     compressed_edge_count = len(c_G.edges())
     assert compressed_edge_count <= original_edge_count
     compressed_G = self.build_compressed_graph()
     assert compressed_edge_count == len(compressed_G.edges())
예제 #3
0
 def test_dedensify_edge_count(self):
     """
     Verifies that dedensify produced the correct number of edges in an
     undirected graph
     """
     G = self.build_original_graph()
     c_G, c_nodes = dedensify(G, threshold=2, copy=True)
     compressed_edge_count = len(c_G.edges())
     verified_original_edge_count = len(G.edges())
     assert compressed_edge_count <= verified_original_edge_count
     verified_compressed_G = self.build_compressed_graph()
     verified_compressed_edge_count = len(verified_compressed_G.edges())
     assert compressed_edge_count == verified_compressed_edge_count
예제 #4
0
 def test_dedensify_edges(self):
     """
     Verifies that dedensify produced the correct edges to/from compressor
     nodes in a directed graph
     """
     G = self.build_original_graph()
     compressed_G = self.build_compressed_graph()
     compressed_graph, c_nodes = dedensify(G, threshold=2)
     for s, t in compressed_graph.edges():
         o_s = "".join(sorted(s))
         o_t = "".join(sorted(t))
         compressed_graph_exists = compressed_graph.has_edge(s, t)
         verified_compressed_exists = compressed_G.has_edge(o_s, o_t)
         assert compressed_graph_exists == verified_compressed_exists
     assert len(c_nodes) == len(self.c_nodes)
예제 #5
0
 def test_dedensify_edges(self):
     """
     Verifies that dedensify produced correct compressor nodes and the
     correct edges to/from the compressor nodes in an undirected graph
     """
     G = self.build_original_graph()
     c_G, c_nodes = dedensify(G, threshold=2)
     v_compressed_G = self.build_compressed_graph()
     for s, t in c_G.edges():
         o_s = "".join(sorted(s))
         o_t = "".join(sorted(t))
         has_compressed_edge = c_G.has_edge(s, t)
         verified_has_compressed_edge = v_compressed_G.has_edge(o_s, o_t)
         assert has_compressed_edge == verified_has_compressed_edge
     assert len(c_nodes) == len(self.c_nodes)
예제 #6
0
    "3": (0, 1),
    "2": (0, 2),
    "1": (0, 3),
    "6": (1, 0),
    "A": (1, 1),
    "B": (1, 2),
    "C": (1, 3),
    "4": (2, 3),
    "5": (2, 1),
}
ax1 = plt.subplot(1, 2, 1)
plt.title("Original (%s edges)" % original_graph.number_of_edges())
nx.draw_networkx(original_graph, pos=pos, node_color=node_colors, **base_options)

nonexp_graph, compression_nodes = summarization.dedensify(
    original_graph, threshold=2, copy=False
)
nonexp_node_colors = list(node_colors)
nonexp_node_sizes = list(node_sizes)
for node in compression_nodes:
    nonexp_node_colors.append("yellow")
    nonexp_node_sizes.append(600)
plt.subplot(1, 2, 2)

plt.title("Dedensified (%s edges)" % nonexp_graph.number_of_edges())
nonexp_pos = {
    "5": (0, 0),
    "B": (0, 2),
    "1": (0, 3),
    "6": (1, 0.75),
    "3": (1.5, 1.5),