Skip to content

Commit d6dcecc

Browse files
author
Jiayi Luo
committed
update
1 parent 8ca4b5f commit d6dcecc

17 files changed

+67
-2
lines changed

README.md

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# DiffSP
2+
3+
### Code Structure Overview
4+
5+
* **`checkpoint`**: This directory contains the trained models.
6+
* **`data`**: Designated for storing the datasets used in the experiments.
7+
* **`config`**: Contains the configuration files, which define the hyperparameters for training and testing.
8+
* **`g`**: Includes the code for training and testing on the graph classification task.
9+
* **`n`**: Includes the code for training and testing on the node classification task.
10+
* **`model`**: Houses the implementation of the DiffSP model.
11+
* **`utils`**: Contains the code for graph transfer entropy and node LID estimation.
12+
13+
### Data Download
14+
15+
To facilitate the reproduction of our experimental results, we provide the adversarial data used in our experiments.
16+
17+
Due to repository space limitations, the data is available through an anonymous account at: https://huggingface.co/datasets/anonymous-random/DiffSP-data/tree/main.
18+
19+
Please download the data and place it in the `./data/` directory before running the experiments.
20+
21+
### Run The Code
22+
23+
#### Node classification
24+
25+
For example, we run the experiments on the `Cora` dataset under the `PR-BCD` attack.
26+
27+
```
28+
python n/main.py --dataset Cora --attack prbcd
29+
```
30+
31+
If you want to retrain the DiffSP, use `--is_train` like:
32+
33+
```
34+
python n/main.py --dataset Cora --attack prbcd --is_train
35+
```
36+
37+
#### Graph classification
38+
39+
For example, we run the experiments on the `IMDB-BINARY` dataset under the `PR-BCD` attack.
40+
41+
```
42+
python g/main.py --dataset IMDB-BINARY --attack prbcd
43+
```
44+
45+
If you want to retrain the DiffSP, use `--is_train` like:
46+
47+
```
48+
python g/main.py --dataset IMDB-BINARY --attack prbcd --is_train
49+
```
50+
51+
#### Note
52+
53+
For graph classification, the classifier comprises two GCN layers, followed by a mean pooling layer and a linear layer, consistent across all models and identical to the surrogate model.
54+
55+
For node classification, the classifier consists of two GCN layers, consistent across all models and aligned with the surrogate model.

__pycache__/loss.cpython-311.pyc

-6.33 KB
Binary file not shown.

__pycache__/parameter.cpython-311.pyc

-2.3 KB
Binary file not shown.

__pycache__/train.cpython-311.pyc

-8.24 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{'device_id': '0', 'dataset': 'COLLAB', 'attack': 'prbcd', 'is_train': True, 'device': device(type='cpu'), 'seed': 102, 'T_E': 9, 'name': 'COLLAB', 'data': {'batch_size': 16384, 'val_batch_size': 131072}, 'train': {'num_epochs': 10000, 'max_grad_norm': 10, 'val_every_epochs': 5, 'patient_epochs': 50}, 'mlp_X': {'hidden_t': 32, 'hidden_X': 512, 'num_mlp_layers': 2, 'dropout': 0.1}, 'gnn_E': {'hidden_t': 32, 'hidden_X': 32, 'hidden_E': 128, 'use_att': True, 'num_layers': 2, 'dropout': 0.1}, 'optimizer_X': {'lr': 0.001, 'weight_decay': 0, 'amsgrad': True}, 'optimizer_E': {'lr': 0.0003, 'weight_decay': 0, 'amsgrad': True}, 'lr_scheduler': {'factor': 0.9, 'patience': 5, 'verbose': True}, 'purify': {'k': 6, 'basic_t': 2, 'adaptive_t': 2, 'lamb': 1000.0}}

environment.yml

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
channels:
2+
- pytorch
3+
- nvidia
4+
- ostrokach-forge
5+
- conda-forge
6+
- defaults
17
dependencies:
28
- _libgcc_mutex=0.1
39
- _openmp_mutex=4.5

g/__pycache__/layer.cpython-311.pyc

-6 Bytes
Binary file not shown.

g/__pycache__/model.cpython-311.pyc

-6 Bytes
Binary file not shown.

g/__pycache__/train.cpython-311.pyc

-6 Bytes
Binary file not shown.

g/main.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ def main(args):
107107
gcn = GCN(num_features, 16, num_classes).to(device)
108108

109109
ck_path = f'./checkpoint/diffusion/{name}/n_step_E{args.T_E}'
110-
# train_ddpm(args, model, train_val_dataset, device, ck_path)
110+
if args.is_train:
111+
train_ddpm(args, model, train_val_dataset, device, ck_path)
111112

112113
save_gcn_path = f'./checkpoint/classifier/{name}/GCN.pth'
113114
gcn.load_state_dict(torch.load(save_gcn_path, map_location=device))

n/__pycache__/layer.cpython-311.pyc

-6 Bytes
Binary file not shown.

n/__pycache__/model.cpython-311.pyc

-6 Bytes
Binary file not shown.

n/__pycache__/train.cpython-311.pyc

-6 Bytes
Binary file not shown.

n/main.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ def main(config):
141141
classifier = GCN(num_features, 16, num_classes).to(device)
142142

143143
# ====================model==================== #
144-
# train_ddpm(config, model, device, x, E_one_hot, ck_path)
144+
if config.is_train:
145+
train_ddpm(config, model, device, x, E_one_hot, ck_path)
145146
train_classifier(classifier, x, edge_index, y, idx_train)
146147

147148
# ====================purify==================== #

parameter.py

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ def parameter_parser():
1010
parser.add_argument('--device_id', type=str, default='0', help='device id')
1111
parser.add_argument('--dataset', type=str, default='Cora', help='dataset')
1212
parser.add_argument('--attack', type=str, default='prbcd', help='attack')
13+
parser.add_argument('--is_train', action='store_true', help='If set, train is True')
1314

1415
args = parser.parse_args()
1516

-6 Bytes
Binary file not shown.
-6 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)