MCPcopy
hub / github.com/THUDM/CogDL / test_prbcd_modification_attack

Function test_prbcd_modification_attack

examples/GRB/test_attack_defense.py:268–304  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

266
267
268def test_prbcd_modification_attack():
269 graph, dataset, test_mask, device, device_ids = init_dataset()
270 model_sur = init_surrogate_model(graph, dataset, test_mask, device, device_ids)
271 model_target = init_target_model(graph, dataset, test_mask, device, device_ids)
272 print("PRBCD modification attack...")
273 device = "cpu"
274 epsilon = 0.3
275 n_epoch = 5
276 n_mod_ratio = 0.01
277 n_node_mod = int(graph.y.shape[0] * n_mod_ratio)
278 n_edge_mod = int(graph.to_scipy_csr()[test_mask.cpu()].getnnz() * n_mod_ratio)
279 feat_lim_min = 0.0
280 feat_lim_max = 1.0
281 early_stop_patience = 2
282 early_stop_epsilon = 1e-3
283 attack = PRBCD(epsilon,
284 n_epoch,
285 n_node_mod,
286 n_edge_mod,
287 feat_lim_min,
288 feat_lim_max,
289 early_stop=True,
290 early_stop_patience=early_stop_patience,
291 early_stop_epsilon=early_stop_epsilon,
292 device=device)
293 graph_attack = attack.attack(model_sur, graph)
294 print(graph_attack)
295 test_score = evaluate(model_sur,
296 graph_attack,
297 mask=test_mask,
298 device=device)
299 print("After attack, test score of surrogate model: {:.4f}".format(test_score))
300 test_score = evaluate(model_target,
301 graph_attack,
302 mask=test_mask,
303 device=device)
304 print("After attack, test score of target model: {:.4f}".format(test_score))
305
306
307def test_fgsm_injection_attack():

Callers 1

Calls 7

attackMethod · 0.95
evaluateFunction · 0.90
init_datasetFunction · 0.85
init_surrogate_modelFunction · 0.85
init_target_modelFunction · 0.85
PRBCDClass · 0.85
to_scipy_csrMethod · 0.45

Tested by

no test coverage detected