Skip to content

Commit

Permalink
add more GNN models and fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Munkhtenger19 committed May 27, 2024
1 parent dc9ceb1 commit 8eea836
Show file tree
Hide file tree
Showing 26 changed files with 1,127 additions and 451 deletions.
42 changes: 21 additions & 21 deletions configs/default_experiment.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
output_dir: ./output10
# resume_output: False
resume_output: True
# csv_save: True
# esd: True
experiment_templates:
- name: Local attack_3
seed: [0]
seed: [1]
device: cuda
model:
- name: GCN2
- name: [GCN_DPR]
params:
hidden_channels: 64
dataset:
name: [Cora]
# name: [CoraFull, CS, Physics, Computers, Photo, CoraCitationFull, DBLP, PubMedCitationFull, Reddit] # ogbn-arxiv
root: ./datasets
make_undirected: true
params:
split: full
# params:
# split: full
# train_ratio: 0.6
# test_ratio: 0.2
# val_ratio: 0.2
Expand All @@ -27,20 +27,20 @@ experiment_templates:
# params:
# value: 0.8

attack:
# - scope: local
# name: [LocalDICE]
# type: poison
# epsilon: [0.5]
# nodes: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
# - scope: global
# name: FGSM
# type: poison
# epsilon: [0.5]
- scope: global
name: DICE
type: poison
epsilon: [0.5]
# attack:
# # - scope: local
# # name: [LocalDICE]
# # type: poison
# # epsilon: [0.5]
# # nodes: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
# # - scope: global
# # name: FGSM
# # type: poison
# # epsilon: [0.5]
# - scope: global
# name: DICE
# type: poison
# epsilon: [0.25]

# - scope: local
# name: [LocalDICE]
Expand All @@ -64,8 +64,8 @@ experiment_templates:


training:
max_epochs: 100
patience: 70
max_epochs: 300
patience: 290

optimizer:
name: adam
Expand Down
76 changes: 38 additions & 38 deletions custom_components/attacks/base_attack.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,41 +311,41 @@ def adj_adversary_for_poisoning(self):
# from torch_geometric.datasets import Planetoid
# from torch_geometric.transforms import ToSparseTensor
# from torch_geometric.utils import dense_to_sparse
# class DenseAttack(BaseAttack):
# @typechecked
# def __init__(
# self,
# adj: Union[SparseTensor, TensorType],
# attr: TensorType,
# labels: TensorType,
# idx_attack: np.ndarray,
# model,
# device: Union[str, int, torch.device],
# make_undirected: bool = True,
# loss_type: str = "CE",
# **kwargs,
# ):
# if isinstance(adj, SparseTensor):
# adj = adj.to_dense()
# # adj = dense_to_sparse(adj)
# # cora = Planetoid(root='datasets', name='Cora',transform=ToSparseTensor(remove_edge_index=False))
# # data = cora[0]
# # row, col, edge_attr = data.adj_t.t().coo()
# # edge_index = torch.stack([row, col], dim=0)
# # adj = edge_index
# # adj = data.adj_t.to_dense()
# # ad

# super().__init__(
# adj,
# attr,
# labels,
# idx_attack,
# model,
# device,
# loss_type=loss_type,
# make_undirected=make_undirected,
# **kwargs,
# )

# self.n = adj.shape[0]
class DenseAttack(BaseAttack):
@typechecked
def __init__(
self,
adj: Union[SparseTensor, TensorType],
attr: TensorType,
labels: TensorType,
idx_attack: np.ndarray,
model,
device: Union[str, int, torch.device],
make_undirected: bool = True,
loss_type: str = "CE",
**kwargs,
):
if isinstance(adj, SparseTensor):
adj = adj.to_dense()
# adj = dense_to_sparse(adj)
# cora = Planetoid(root='datasets', name='Cora',transform=ToSparseTensor(remove_edge_index=False))
# data = cora[0]
# row, col, edge_attr = data.adj_t.t().coo()
# edge_index = torch.stack([row, col], dim=0)
# adj = edge_index
# adj = data.adj_t.to_dense()
# ad

super().__init__(
adj,
attr,
labels,
idx_attack,
model,
device,
loss_type=loss_type,
make_undirected=make_undirected,
**kwargs,
)

self.n = adj.shape[0]
Loading

0 comments on commit 8eea836

Please sign in to comment.