def get_train_val_test(self): """Get training, validation, test splits according to self.setting (either 'nettack' or 'gcn'). """ if self.setting == 'nettack': return get_train_val_test(nnodes=self.adj.shape[0], val_size=0.1, test_size=0.8, stratify=self.labels, seed=self.seed) if self.setting == 'gcn': return get_train_val_test_gcn(self.labels, seed=self.seed)
def get_train_val_test(self): if self.setting == 'nettack': return get_train_val_test(nnodes=self.adj.shape[0], val_size=0.1, test_size=0.8, stratify=self.labels, seed=self.seed) if self.setting == 'gcn': return get_train_val_test_gcn(self.labels, seed=self.seed)
print(args) np.random.seed( 15 ) # Here the random seed is to split the train/val/test data, we need to set the random seed to be the same as that when you generate the perturbed graph data = Dataset(root='/tmp/', name=args.dataset, setting='nettack') adj, features, labels = data.adj, data.features, data.labels idx_train, idx_val, idx_test = data.idx_train, data.idx_val, data.idx_test if args.dataset == 'pubmed': # just for matching the results in the paper; seed details in https://github.com/ChandlerBang/Pro-GNN/issues/2 idx_train, idx_val, idx_test = get_train_val_test( adj.shape[0], val_size=0.1, test_size=0.8, stratify=encode_onehot(labels), seed=15) if args.attack == 'no': perturbed_adj = adj if args.attack == 'random': from deeprobust.graph.global_attack import Random # to fix the seed of generated random attack, you need to fix both np.random and random # you can uncomment the following code # import random; random.seed(args.seed) # np.random.seed(args.seed) attacker = Random() n_perturbations = int(args.ptb_rate * (adj.sum() // 2)) attacker.attack(adj, n_perturbations, type='add')