()
| 367 | |
| 368 | |
| 369 | def test_rand_injection_attack(): |
| 370 | graph, dataset, test_mask, device, device_ids = init_dataset() |
| 371 | model_sur = init_surrogate_model(graph, dataset, test_mask, device, device_ids) |
| 372 | model_target = init_target_model(graph, dataset, test_mask, device, device_ids) |
| 373 | print("RAND injection attack...") |
| 374 | attack = RAND_Inject(n_inject_max=10, |
| 375 | n_edge_max=20, |
| 376 | feat_lim_min=-1, |
| 377 | feat_lim_max=1, |
| 378 | device=device) |
| 379 | graph_attack = attack.attack(model=model_sur, |
| 380 | graph=graph, |
| 381 | adj_norm_func=GCNAdjNorm) |
| 382 | print(graph_attack) |
| 383 | test_score_sur = evaluate(model_sur, |
| 384 | graph_attack, |
| 385 | mask=test_mask, |
| 386 | device=device) |
| 387 | print("Test score after attack for surrogate model: {:.4f}.".format(test_score_sur)) |
| 388 | test_score_target_attack = evaluate(model_target, |
| 389 | graph_attack, |
| 390 | mask=test_mask, |
| 391 | device=device) |
| 392 | print("Test score after attack for target model: {:.4f}.".format(test_score_target_attack)) |
| 393 | |
| 394 | |
| 395 | def test_speit_injection_attack(): |
no test coverage detected