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

Function test_stack_modification_attack

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

Source from the content-addressed store, hash-verified

203
204
205def 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
231def test_pgd_modification_attack():

Callers 1

Calls 7

evaluateFunction · 0.90
init_datasetFunction · 0.85
init_surrogate_modelFunction · 0.85
init_target_modelFunction · 0.85
STACKClass · 0.85
to_scipy_csrMethod · 0.45
attackMethod · 0.45

Tested by

no test coverage detected