()
| 203 | |
| 204 | |
| 205 | def test_stack_modification_attack(): |
| 206 | graph, dataset, test_mask, device, device_ids = init_dataset() |
| 207 | model_sur = init_surrogate_model(graph, dataset, test_mask, device, device_ids) |
| 208 | model_target = init_target_model(graph, dataset, test_mask, device, device_ids) |
| 209 | print("STACK modification attack...") |
| 210 | n_mod_ratio = 0.01 |
| 211 | n_edge_mod = int(graph.to_scipy_csr()[test_mask.cpu()].getnnz() * n_mod_ratio) |
| 212 | attacks = [ |
| 213 | STACK(n_edge_mod, allow_isolate=False, device=device), |
| 214 | STACK(n_edge_mod, allow_isolate=True, device=device) |
| 215 | ] |
| 216 | for attack in attacks: |
| 217 | graph_attack = attack.attack(graph) |
| 218 | print(graph_attack) |
| 219 | test_score = evaluate(model_sur, |
| 220 | graph_attack, |
| 221 | mask=test_mask, |
| 222 | device=device) |
| 223 | print("After attack, test score of surrogate model: {:.4f}".format(test_score)) |
| 224 | test_score = evaluate(model_target, |
| 225 | graph_attack, |
| 226 | mask=test_mask, |
| 227 | device=device) |
| 228 | print("After attack, test score of target model: {:.4f}".format(test_score)) |
| 229 | |
| 230 | |
| 231 | def test_pgd_modification_attack(): |
no test coverage detected