def run(self): with self.input()[0] as i: graphIndex, GR = i.query() with self.input()[1] as i: R = i.query() train_index = np.array(self.train_index) test_index = list(range(len(GR))) test_index = [i for i in test_index if i not in train_index] y_bin = [None] * len(GR) for index, D in R.items(): if index not in graphIndex: continue gI = graphIndex[index] score = D['score'] time = evalTime(D['time_rank']) y_bin[gI] = (score['IUV'], score['ESBMC'], time) y_bin = np.array(y_bin) y_test = y_bin[test_index] y_train = y_bin[train_index] TGR = GR[train_index][:, train_index] EGR = GR[test_index][:, train_index] param_grid = { 'C_tester': self.C_tester.value, 'C_verifier': self.C_verifier.value, 'C_time': self.C_time.value } max_mean = -math.inf max_param = None for params in ParameterGrid(param_grid): tick(self) mean, _ = self._k_fold_cv_gram( TGR, y_train, (params['C_tester'], params['C_verifier'], params['C_time'])) if mean > max_mean: max_mean = mean max_param = params max_param['mean'] = max_mean max_param['h'] = self.h max_param['D'] = self.D max_param['train_matrix'] = TGR.tolist() max_param['train_y'] = y_train.tolist() max_param['test_matrix'] = EGR.tolist() max_param['test_y'] = y_test.tolist() with self.output() as o: o.emit(max_param)
def _collect_labels(self, graph): ret = {} for u, v, d in graph.in_edges(data=True): tick(self) source = graph.node[u]['label'] edge_t = d['type'] truth = d['truth'] long_edge_label = self._describe(source, [edge_t, truth]) if v not in ret: ret[v] = [] ret[v].append(long_edge_label) return ret
def run(self): max_param = None max_mean = -math.inf for inp in self.input(): tick(self) if inp is not None: with inp as i: param = i.query() if param['mean'] > max_mean: max_mean = param['mean'] max_param = param del param with self.output() as o: o.emit(max_param)
def run(self): with self.input()[0] as graphInput: graph = graphInput.query() count = {} if self.h > 0: # Step 1 M = self._collect_labels(graph) # Step 2, 3, 4 for n, d in graph.nodes(data=True): tick(self) if n not in M: continue label = self._describe(d['label'], sorted(M[n])) if label not in count: count[label] = 0 count[label] += 1 d['label'] = label else: for n, d in graph.nodes(data=True): tick(self) label = d['label'] if label not in count: count[label] = 0 count[label] += 1 graph.graph['label_count'] = count if hasattr(self, 'rainbow_table'): graph.graph['rainbow_table'] = self.rainbow_table with self.output() as out_dirput: out_dirput.emit(graph)
def run(self): with self.input()[0] as i: graph = i.query() remV = set([]) remE = set([]) types = self.__get_allowed() for n, nbrs in graph.adjacency(): depth = graph.node[n]['depth'] if depth > self.maxDepth: remV.add(n) for nbr, keydict in nbrs.items(): for key, eattr in keydict.items(): tick(self) if eattr['type'] not in types: remE.add((n, nbr)) graph.remove_nodes_from(remV) graph.remove_edges_from(remE) with self.output() as o: o.emit(graph)
def run(self): graph_path, node_labels_path, edge_types_path, edge_truth_path,\ node_depths_path = self.run_first() tick(self) nx_digraph = nx.read_graphml(graph_path) node_labels = _read_node_labeling(node_labels_path, self.node_relabel.value) nx.set_node_attributes(nx_digraph, name='label', values=node_labels) tick(self) edge_types = _read_edge_labeling(edge_types_path) parsed_edge_types = _parse_edge(edge_types) nx.set_edge_attributes(nx_digraph, name='type', values=parsed_edge_types) tick(self) edge_truth = _read_edge_labeling(edge_truth_path) parsed_edge_truth = _parse_edge(edge_truth) nx.set_edge_attributes(nx_digraph, name='truth', values=parsed_edge_truth) tick(self) node_depths = _read_node_labeling(node_depths_path) parsed_node_depths = _parse_node_depth(node_depths) nx.set_node_attributes(nx_digraph, name='depth', values=parsed_node_depths) self.cleanup(graph_path, node_labels_path, edge_types_path, edge_truth_path, node_depths_path) with self.output() as o: o.emit(nx_digraph)