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.")
def compute_column_fingerprints(self, record_graphs): assert self.wl_state features = [] for hypergraph in record_graphs: new_features, self.wl_state = feature_extraction.extract_features(hypergraph, self.wl_iterations, self.wl_state) features += new_features column = set() for feature in features: shingles = shingle_extraction.extract_shingles(feature) fingerprints = fingerprint.get_fingerprints(shingles) column |= set(fingerprints) return sorted(column)
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.")
def get_shingle_fingerprints(): def inner(query_features): for features in query_features: for feature in features: shingles = shingle_extraction.extract_shingles(feature) fingerprints = fingerprint.get_fingerprints(shingles) for fp in fingerprints: yield fp new_wl_labels_list = wl_labels_list query_features = [] for query_graph in query_graph_list: if type(query_graph) is Hypergraph: query_hypergraph = query_graph else: query_hypergraph = Hypergraph(query_graph) features, new_wl_labels_list = feature_extraction.extract_features(query_hypergraph, wl_iterations, new_wl_labels_list) query_features.append(features) return set(inner(query_features)), new_wl_labels_list
def get_shingle_fingerprints(): def inner(query_features): for features in query_features: for feature in features: shingles = shingle_extraction.extract_shingles(feature) fingerprints = fingerprint.get_fingerprints(shingles) for fp in fingerprints: yield fp new_wl_labels_list = wl_labels_list query_features = [] for query_graph in query_graph_list: if type(query_graph) is Hypergraph: query_hypergraph = query_graph else: query_hypergraph = Hypergraph(query_graph) features, new_wl_labels_list = feature_extraction.extract_features( query_hypergraph, wl_iterations, new_wl_labels_list) query_features.append(features) return set(inner(query_features)), new_wl_labels_list