()
| 229 | |
| 230 | |
| 231 | def test_pgd_modification_attack(): |
| 232 | graph, dataset, test_mask, device, device_ids = init_dataset() |
| 233 | model_sur = init_surrogate_model(graph, dataset, test_mask, device, device_ids) |
| 234 | model_target = init_target_model(graph, dataset, test_mask, device, device_ids) |
| 235 | print("PGD modification attack...") |
| 236 | epsilon = 0.1 |
| 237 | n_epoch = 5 |
| 238 | n_mod_ratio = 0.01 |
| 239 | n_node_mod = int(graph.y.shape[0] * n_mod_ratio) |
| 240 | n_edge_mod = int(graph.to_scipy_csr()[test_mask.cpu()].getnnz() * n_mod_ratio) |
| 241 | feat_lim_min = 0.0 |
| 242 | feat_lim_max = 1.0 |
| 243 | early_stop_patience = 2 |
| 244 | attack = PGD_Modify(epsilon, |
| 245 | n_epoch, |
| 246 | n_node_mod, |
| 247 | n_edge_mod, |
| 248 | feat_lim_min, |
| 249 | feat_lim_max, |
| 250 | early_stop=True, |
| 251 | early_stop_patience=early_stop_patience, |
| 252 | early_stop_epsilon=1e-3, |
| 253 | device=device) |
| 254 | graph_attack = attack.attack(model_sur, graph) |
| 255 | print(graph_attack) |
| 256 | test_score = evaluate(model_sur, |
| 257 | graph_attack, |
| 258 | mask=test_mask, |
| 259 | device=device) |
| 260 | print("After attack, test score of surrogate model: {:.4f}".format(test_score)) |
| 261 | test_score = evaluate(model_target, |
| 262 | graph_attack, |
| 263 | mask=test_mask, |
| 264 | device=device) |
| 265 | print("After attack, test score of target model: {:.4f}".format(test_score)) |
| 266 | |
| 267 | |
| 268 | def test_prbcd_modification_attack(): |
no test coverage detected