feat(defense): add Revisiting (BaseDefense) #19
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
📋 Summary
feat(defense): add
Revisitingdefense (BaseDefense) + runnable exampleRevisitingatmodels/defense/Revisiting.py.models/defense/BaseDefense.defend()supported_api_types = {"dgl"}models/defense/__init__.py.examples/revisiting_cora.pyto demonstrate usage.models/attack/*(scope kept defense-only per review feedback).Method (high-level):
Localized neighbor-mixing on a subset of nodes (≈
attack_node_fraction * |V|):u:x[u] ← (1 − α)·x[u] + α·mean(x[N(u)])v: lighter mix0.5·α.defend()trains GraphSAGE on original features (baseline) and on transformed features (defended) and returns both test accuracies plus metadata.How to run
python -m examples.revisiting_cora # or python examples/revisiting_cora.pyReturn value from
.defend(){ "ok": True, "method": "Revisiting", "alpha": <float>, "focus_nodes": <int>, "baseline_test_acc": <float>, "defense_test_acc": <float>, "acc_delta": <float>, "sample_picked_nodes": <list[int]>, }🧪 Related Issues
models/defense/, and should use a.defend()API by inheritingBaseDefense.Closes #<id>,Fixes #<id>, etc.✅ Checklist
feat/revisiting-defense), notmain🧠 Additional Context (Optional)
Files added/updated
models/defense/Revisiting.py— new defense (inheritsBaseDefense)models/defense/__init__.py— exportRevisitingexamples/revisiting_cora.py— runnable exampleExample output on Cora (
alpha = 0.8,attack_node_fraction = 0.2)Small utility drop is expected with feature mixing; tuning
alpha(e.g., 0.4–0.6) can adjust the trade-off.Design notes
RandomWMpattern (DGL + NeighborSampler/NodeCollator + GraphSAGE).try/finallyto restore original features.