def test_summary_graph(self):
        original_graph = self.build_original_graph()
        summary_graph = self.build_summary_graph()

        relationship_attributes = ("type", )
        generated_summary_graph = nx.snap_aggregation(original_graph,
                                                      self.node_attributes)
        relabeled_summary_graph = self.deterministic_labels(
            generated_summary_graph)
        assert nx.is_isomorphic(summary_graph, relabeled_summary_graph)
def test_summarization_empty(graph_type):
    G = graph_type()
    summary_graph = nx.snap_aggregation(G, node_attributes=("color", ))
    assert nx.is_isomorphic(summary_graph, G)
Exemple #3
0
edge_type_visual_weight_lookup = {"Weak": 1.0, "Strong": 3.0}
edge_weights = [
    edge_type_visual_weight_lookup[d["type"]]
    for _, _, d in original_graph.edges(data=True)
]

nx.draw_networkx(original_graph,
                 pos=pos,
                 node_color=node_colors,
                 width=edge_weights,
                 **base_options)

node_attributes = ("color", )
edge_attributes = ("type", )
summary_graph = nx.snap_aggregation(original_graph,
                                    node_attributes,
                                    edge_attributes,
                                    prefix="S-")

plt.subplot(1, 2, 2)

plt.title("SNAP Aggregation (%s nodes, %s edges)" %
          (summary_graph.number_of_nodes(), summary_graph.number_of_edges()))
summary_pos = nx.spring_layout(summary_graph, seed=8375428)
node_colors = []
for node in summary_graph:
    color = summary_graph.nodes[node]["color"]
    node_colors.append(color)

edge_weights = []
for edge in summary_graph.edges():
    edge_types = summary_graph.get_edge_data(*edge)["types"]