Пример #1
0
    def testRBallHyper_CenterDefaultColor(self):
        dummy_hypergraph = Hypergraph(example_graphs.gt_dummy_graph)
        rball_in = algorithms.r_ball_hyper(dummy_hypergraph,
                                           "n_10",
                                           2,
                                           -1,
                                           center_default_color=True)
        rball_out = algorithms.r_ball_hyper(dummy_hypergraph,
                                            "n_10",
                                            2,
                                            1,
                                            center_default_color=True)
        rball_all = algorithms.r_ball_hyper(dummy_hypergraph,
                                            "n_10",
                                            2,
                                            0,
                                            center_default_color=True)
        d_rball_all = Hypergraph(example_graphs.gt_dummy_rball_10_r2_all)
        d_rball_out = Hypergraph(example_graphs.gt_dummy_rball_10_r2_out)
        d_rball_in = Hypergraph(example_graphs.gt_dummy_rball_10_r2_in)

        d_rball_all.node["n_10"]["labels"] = ["0"]
        d_rball_out.node["n_10"]["labels"] = ["0"]
        d_rball_in.node["n_10"]["labels"] = ["0"]

        all_isomorphic = algorithms.isomorphic(d_rball_all, rball_all)
        out_isomorphic = algorithms.isomorphic(d_rball_out, rball_out)
        in_isomorphic = algorithms.isomorphic(d_rball_in, rball_in)

        self.assertTrue(all_isomorphic,
                        "Problem extracting r-ball with edge_dir=0.")
        self.assertTrue(out_isomorphic,
                        "Problem extracting r-ball with edge_dir=1.")
        self.assertTrue(in_isomorphic,
                        "Problem extracting r-ball with edge_dir=-1.")
 def testFeatureExtraction(self):
     wl_state_exp = {
         "labels": {
             "g": "wl_0.0",
             "n": "wl_0.1",
             "r": "wl_0.2",
             "b": "wl_0.3",
             "wl_0.0;in(wl_0.2),out(wl_0.2)": "wl_1.0",
             "wl_0.1;in(wl_0.2),out(wl_0.2)": "wl_1.1",
             "wl_0.2;in(wl_0.1)": "wl_1.2",
             "wl_0.2;out(wl_0.0,wl_0.1)": "wl_1.3",
             "wl_0.2;in(wl_0.0)": "wl_1.4",
             "wl_0.1;in(wl_0.3),out(wl_0.2)": "wl_1.5",
             "wl_0.3;out(wl_0.1)": "wl_1.6",
             "wl_0.2;in(wl_0.1,wl_0.1)": "wl_1.7"
         },
         "next_labels": {
             0: 4,
             1: 8
         }
     }
     dummy_hypergraph = Hypergraph(example_graphs.snm_dummy_graph)
     rballs_database = [r_ball_hyper(dummy_hypergraph, "n_2", 1, edge_dir=1),
                        r_ball_hyper(dummy_hypergraph, "n_2", 1, edge_dir=-1)]
     features = []
     wl_state = None
     for rball in rballs_database:
         new_features, wl_state = feature_extraction.extract_features(rball, wl_iterations=1, wl_state=wl_state)
         features += new_features
     self.assertEqual(wl_state_exp, wl_state, "The wrong wl_state was computed by Weisfeiler-Lehman.")
     isomorphic = all([algorithms.isomorphic(features[i], example_graphs.snm_dummy_graph_features[i]) for i in range(len(features))])
     self.assertTrue(isomorphic, "Wrong features extracted.")
Пример #3
0
 def testRBallHyper(self):
     dummy_hypergraph = Hypergraph(example_graphs.gt_dummy_graph)
     rball_in = algorithms.r_ball_hyper(dummy_hypergraph, "n_10", 2, -1)
     rball_out = algorithms.r_ball_hyper(dummy_hypergraph, "n_10", 2, 1)
     rball_all = algorithms.r_ball_hyper(dummy_hypergraph, "n_10", 2, 0)
     d_rball_all = Hypergraph(example_graphs.gt_dummy_rball_10_r2_all)
     d_rball_out = Hypergraph(example_graphs.gt_dummy_rball_10_r2_out)
     d_rball_in = Hypergraph(example_graphs.gt_dummy_rball_10_r2_in)
     
     all_isomorphic = algorithms.isomorphic(d_rball_all, rball_all)
     out_isomorphic = algorithms.isomorphic(d_rball_out, rball_out)
     in_isomorphic = algorithms.isomorphic(d_rball_in, rball_in)
     
     self.assertTrue(all_isomorphic, "Problem extracting r-ball with edge_dir=0.")
     self.assertTrue(out_isomorphic, "Problem extracting r-ball with edge_dir=1.")
     self.assertTrue(in_isomorphic, "Problem extracting r-ball with edge_dir=-1.")
Пример #4
0
 def testHypergraph_subgraph_with_labels(self):
     dummy_hypergraph = Hypergraph(example_graphs.gt_dummy_graph)
     subgraph = dummy_hypergraph.subgraph_with_labels(
         set(["n_1", "n_6", "n_9", "n_10"]))
     isomorphic = algorithms.isomorphic(example_graphs.gt_dummy_subgraph,
                                        subgraph)
     self.assertTrue(isomorphic,
                     "Incorrect subgraph extraction from hypergraph.")
Пример #5
0
 def testRDFToNxGraphConvertionWithColoring(self):
     dummy_colored, _ = rdf.convert_rdf_to_nx_graph(
         ["test_files/dummy.rdf"], test_mode=True)
     isomorphic = algorithms.isomorphic(
         example_graphs.gt_dummy_colored_expected, dummy_colored)
     self.assertTrue(
         isomorphic,
         "Problem converting RDF graph to Networkx graph with colors.")
 def testFeatureTypes(self):
     dummy_hypergraph_2 = Hypergraph(example_graphs.snm_dummy_graph_2)
     features = []
     raw_features = arnborg_proskurowski.get_reduced_features(dummy_hypergraph_2)
     for raw_feature in raw_features:
         new_features = list(feature_extraction.process_raw_feature(raw_feature, dummy_hypergraph_2))
         features += new_features
     isomorphic = all([algorithms.isomorphic(features[i], example_graphs.snm_dummy_graph_features_2[i]) for i in range(len(features))])
     self.assertTrue(isomorphic, "Wrong features extracted.")
Пример #7
0
    def testRBallHyper(self):
        dummy_hypergraph = Hypergraph(example_graphs.gt_dummy_graph)
        rball_in = algorithms.r_ball_hyper(dummy_hypergraph, "n_10", 2, -1)
        rball_out = algorithms.r_ball_hyper(dummy_hypergraph, "n_10", 2, 1)
        rball_all = algorithms.r_ball_hyper(dummy_hypergraph, "n_10", 2, 0)
        d_rball_all = Hypergraph(example_graphs.gt_dummy_rball_10_r2_all)
        d_rball_out = Hypergraph(example_graphs.gt_dummy_rball_10_r2_out)
        d_rball_in = Hypergraph(example_graphs.gt_dummy_rball_10_r2_in)

        all_isomorphic = algorithms.isomorphic(d_rball_all, rball_all)
        out_isomorphic = algorithms.isomorphic(d_rball_out, rball_out)
        in_isomorphic = algorithms.isomorphic(d_rball_in, rball_in)

        self.assertTrue(all_isomorphic,
                        "Problem extracting r-ball with edge_dir=0.")
        self.assertTrue(out_isomorphic,
                        "Problem extracting r-ball with edge_dir=1.")
        self.assertTrue(in_isomorphic,
                        "Problem extracting r-ball with edge_dir=-1.")
Пример #8
0
 def testRBallHyper_CenterDefaultColor(self):
     dummy_hypergraph = Hypergraph(example_graphs.gt_dummy_graph)
     rball_in = algorithms.r_ball_hyper(dummy_hypergraph, "n_10", 2, -1, center_default_color=True)
     rball_out = algorithms.r_ball_hyper(dummy_hypergraph, "n_10", 2, 1, center_default_color=True)
     rball_all = algorithms.r_ball_hyper(dummy_hypergraph, "n_10", 2, 0, center_default_color=True)
     d_rball_all = Hypergraph(example_graphs.gt_dummy_rball_10_r2_all)
     d_rball_out = Hypergraph(example_graphs.gt_dummy_rball_10_r2_out)
     d_rball_in = Hypergraph(example_graphs.gt_dummy_rball_10_r2_in)
     
     d_rball_all.node["n_10"]["labels"] = ["0"]
     d_rball_out.node["n_10"]["labels"] = ["0"]
     d_rball_in.node["n_10"]["labels"] = ["0"]
     
     all_isomorphic = algorithms.isomorphic(d_rball_all, rball_all)
     out_isomorphic = algorithms.isomorphic(d_rball_out, rball_out)
     in_isomorphic = algorithms.isomorphic(d_rball_in, rball_in)
     
     self.assertTrue(all_isomorphic, "Problem extracting r-ball with edge_dir=0.")
     self.assertTrue(out_isomorphic, "Problem extracting r-ball with edge_dir=1.")
     self.assertTrue(in_isomorphic, "Problem extracting r-ball with edge_dir=-1.")
 def testFeatureTypes(self):
     dummy_hypergraph_2 = Hypergraph(example_graphs.snm_dummy_graph_2)
     features = []
     raw_features = arnborg_proskurowski.get_reduced_features(
         dummy_hypergraph_2)
     for raw_feature in raw_features:
         new_features = list(
             feature_extraction.process_raw_feature(raw_feature,
                                                    dummy_hypergraph_2))
         features += new_features
     isomorphic = all([
         algorithms.isomorphic(features[i],
                               example_graphs.snm_dummy_graph_features_2[i])
         for i in range(len(features))
     ])
     self.assertTrue(isomorphic, "Wrong features extracted.")
 def testFeatureExtraction(self):
     wl_state_exp = {
         "labels": {
             "g": "wl_0.0",
             "n": "wl_0.1",
             "r": "wl_0.2",
             "b": "wl_0.3",
             "wl_0.0;in(wl_0.2),out(wl_0.2)": "wl_1.0",
             "wl_0.1;in(wl_0.2),out(wl_0.2)": "wl_1.1",
             "wl_0.2;in(wl_0.1)": "wl_1.2",
             "wl_0.2;out(wl_0.0,wl_0.1)": "wl_1.3",
             "wl_0.2;in(wl_0.0)": "wl_1.4",
             "wl_0.1;in(wl_0.3),out(wl_0.2)": "wl_1.5",
             "wl_0.3;out(wl_0.1)": "wl_1.6",
             "wl_0.2;in(wl_0.1,wl_0.1)": "wl_1.7"
         },
         "next_labels": {
             0: 4,
             1: 8
         }
     }
     dummy_hypergraph = Hypergraph(example_graphs.snm_dummy_graph)
     rballs_database = [
         r_ball_hyper(dummy_hypergraph, "n_2", 1, edge_dir=1),
         r_ball_hyper(dummy_hypergraph, "n_2", 1, edge_dir=-1)
     ]
     features = []
     wl_state = None
     for rball in rballs_database:
         new_features, wl_state = feature_extraction.extract_features(
             rball, wl_iterations=1, wl_state=wl_state)
         features += new_features
     self.assertEqual(
         wl_state_exp, wl_state,
         "The wrong wl_state was computed by Weisfeiler-Lehman.")
     isomorphic = all([
         algorithms.isomorphic(features[i],
                               example_graphs.snm_dummy_graph_features[i])
         for i in range(len(features))
     ])
     self.assertTrue(isomorphic, "Wrong features extracted.")
Пример #11
0
 def testRDFToNxGraphConvertionWithColoring(self):
     dummy_colored, _ = rdf.convert_rdf_to_nx_graph(["test_files/dummy.rdf"], test_mode=True)
     isomorphic = algorithms.isomorphic(example_graphs.gt_dummy_colored_expected, dummy_colored)
     self.assertTrue(isomorphic, "Problem converting RDF graph to Networkx graph with colors.")
Пример #12
0
 def testHypergraph_subgraph_with_labels(self):
     dummy_hypergraph = Hypergraph(example_graphs.gt_dummy_graph)
     subgraph = dummy_hypergraph.subgraph_with_labels(set(["n_1", "n_6", "n_9", "n_10"]))
     isomorphic = algorithms.isomorphic(example_graphs.gt_dummy_subgraph, subgraph)
     self.assertTrue(isomorphic, "Incorrect subgraph extraction from hypergraph.")