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

Function test_nea_modification_attack

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

Source from the content-addressed store, hash-verified

181
182
183def test_nea_modification_attack():
184 graph, dataset, test_mask, device, device_ids = init_dataset()
185 model_sur = init_surrogate_model(graph, dataset, test_mask, device, device_ids)
186 model_target = init_target_model(graph, dataset, test_mask, device, device_ids)
187 print("NEA modification attack...")
188 n_mod_ratio = 0.01
189 n_edge_mod = int(graph.to_scipy_csr()[test_mask.cpu()].getnnz() * n_mod_ratio)
190 attack = NEA(n_edge_mod, device=device)
191 graph_attack = attack.attack(graph)
192 print(graph_attack)
193 test_score = evaluate(model_sur,
194 graph_attack,
195 mask=test_mask,
196 device=device)
197 print("After attack, test score of surrogate model: {:.4f}".format(test_score))
198 test_score = evaluate(model_target,
199 graph_attack,
200 mask=test_mask,
201 device=device)
202 print("After attack, test score of target model: {:.4f}".format(test_score))
203
204
205def test_stack_modification_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
NEAClass · 0.85
to_scipy_csrMethod · 0.45

Tested by

no test coverage detected