(self,graph_list,topK)
| 669 | |
| 670 | |
| 671 | def update_cache(self,graph_list,topK): |
| 672 | merged_graph_list = self.MergeGraph(self.graph_cache,graph_list) |
| 673 | merged_graph_list = [g for g in merged_graph_list if g.GetGraphScore() > 0 and g.graph.number_of_nodes() > 10] |
| 674 | score = [x.GetGraphScore() for x in merged_graph_list] |
| 675 | if len(score) == 0: |
| 676 | return |
| 677 | print(score) |
| 678 | # if len(score) < 3: |
| 679 | # self.graph_cache = merged_graph_list[:topK] |
| 680 | # return |
| 681 | # cov = EllipticEnvelope(random_state=0).fit_predict(score) |
| 682 | # clf = OneClassSVM(kernel="rbf",gamma='auto').fit(score) |
| 683 | # cov = clf.predict(score) |
| 684 | # for g in merged_graph_list: |
| 685 | # print(g.GetGraphScore()) |
| 686 | cov = grubbs.max_test_indices(score, alpha=0.01) |
| 687 | # clf = OneClassSVM(kernel="rbf",gamma='auto').fit(score) |
| 688 | # cov = clf.predict(score) |
| 689 | # for g in merged_graph_list: |
| 690 | # print(g.GetGraphScore()) |
| 691 | for i in cov: |
| 692 | g = merged_graph_list[i].graph |
| 693 | # for k in g.nodes(): |
| 694 | # g.nodes[k]['label'] = self.GetNodeName(k) + ' ' + str(self.GetNodeScore(k)) |
| 695 | # nx.drawing.nx_pydot.write_dot(g, str(i) + '.dot') |
| 696 | print('[Alert]: ', score[i], len(g.nodes()),self.attack_node(g.nodes())) |
| 697 | # node_l = {i:self.GetNodeScore(i) for i in g.nodes()} |
| 698 | # sorted_l = sorted(node_l.items(), key=lambda d: d[1], reverse=True) |
| 699 | merged_graph_list.sort(key = lambda x: x.GetGraphScore(),reverse = True) |
| 700 | |
| 701 | |
| 702 | self.graph_cache = merged_graph_list[:topK] |
| 703 | |
| 704 | def attack_node(self,node_list): |
| 705 | result = [] |
no test coverage detected