├── PyG ├── cora │ ├── cora.py │ └── layer.py └── ogbn-arxiv │ ├── README.md │ ├── arxiv.py │ └── layer.py ├── README.md ├── data ├── ind.citeseer.allx ├── ind.citeseer.ally ├── ind.citeseer.graph ├── ind.citeseer.test.index ├── ind.citeseer.tx ├── ind.citeseer.ty ├── ind.citeseer.x ├── ind.citeseer.y ├── ind.cora.allx ├── ind.cora.ally ├── ind.cora.graph ├── ind.cora.test.index ├── ind.cora.tx ├── ind.cora.ty ├── ind.cora.x ├── ind.cora.y ├── ind.pubmed.allx ├── ind.pubmed.ally ├── ind.pubmed.graph ├── ind.pubmed.test.index ├── ind.pubmed.tx ├── ind.pubmed.ty ├── ind.pubmed.x └── ind.pubmed.y ├── full-supervised.py ├── full.sh ├── model.py ├── new_data ├── chameleon │ ├── out1_graph_edges.txt │ └── out1_node_feature_label.txt ├── cornell │ ├── out1_graph_edges.txt │ └── out1_node_feature_label.txt ├── texas │ ├── out1_graph_edges.txt │ └── out1_node_feature_label.txt └── wisconsin │ ├── out1_graph_edges.txt │ └── out1_node_feature_label.txt ├── ppi.py ├── ppi.sh ├── pretrained └── README.md ├── process.py ├── semi.sh ├── splits ├── chameleon_split_0.6_0.2_0.npz ├── chameleon_split_0.6_0.2_1.npz ├── chameleon_split_0.6_0.2_2.npz ├── chameleon_split_0.6_0.2_3.npz ├── chameleon_split_0.6_0.2_4.npz ├── chameleon_split_0.6_0.2_5.npz ├── chameleon_split_0.6_0.2_6.npz ├── chameleon_split_0.6_0.2_7.npz ├── chameleon_split_0.6_0.2_8.npz ├── chameleon_split_0.6_0.2_9.npz ├── citeseer_split_0.6_0.2_0.npz ├── citeseer_split_0.6_0.2_1.npz ├── citeseer_split_0.6_0.2_2.npz ├── citeseer_split_0.6_0.2_3.npz ├── citeseer_split_0.6_0.2_4.npz ├── citeseer_split_0.6_0.2_5.npz ├── citeseer_split_0.6_0.2_6.npz ├── citeseer_split_0.6_0.2_7.npz ├── citeseer_split_0.6_0.2_8.npz ├── citeseer_split_0.6_0.2_9.npz ├── cora_split_0.6_0.2_0.npz ├── cora_split_0.6_0.2_1.npz ├── cora_split_0.6_0.2_2.npz ├── cora_split_0.6_0.2_3.npz ├── cora_split_0.6_0.2_4.npz ├── cora_split_0.6_0.2_5.npz ├── cora_split_0.6_0.2_6.npz ├── cora_split_0.6_0.2_7.npz ├── cora_split_0.6_0.2_8.npz ├── cora_split_0.6_0.2_9.npz ├── cornell_split_0.6_0.2_0.npz ├── cornell_split_0.6_0.2_1.npz ├── cornell_split_0.6_0.2_2.npz ├── cornell_split_0.6_0.2_3.npz ├── cornell_split_0.6_0.2_4.npz ├── cornell_split_0.6_0.2_5.npz ├── cornell_split_0.6_0.2_6.npz ├── cornell_split_0.6_0.2_7.npz ├── cornell_split_0.6_0.2_8.npz ├── cornell_split_0.6_0.2_9.npz ├── pubmed_split_0.6_0.2_0.npz ├── pubmed_split_0.6_0.2_1.npz ├── pubmed_split_0.6_0.2_2.npz ├── pubmed_split_0.6_0.2_3.npz ├── pubmed_split_0.6_0.2_4.npz ├── pubmed_split_0.6_0.2_5.npz ├── pubmed_split_0.6_0.2_6.npz ├── pubmed_split_0.6_0.2_7.npz ├── pubmed_split_0.6_0.2_8.npz ├── pubmed_split_0.6_0.2_9.npz ├── texas_split_0.6_0.2_0.npz ├── texas_split_0.6_0.2_1.npz ├── texas_split_0.6_0.2_2.npz ├── texas_split_0.6_0.2_3.npz ├── texas_split_0.6_0.2_4.npz ├── texas_split_0.6_0.2_5.npz ├── texas_split_0.6_0.2_6.npz ├── texas_split_0.6_0.2_7.npz ├── texas_split_0.6_0.2_8.npz ├── texas_split_0.6_0.2_9.npz ├── wisconsin_split_0.6_0.2_0.npz ├── wisconsin_split_0.6_0.2_1.npz ├── wisconsin_split_0.6_0.2_2.npz ├── wisconsin_split_0.6_0.2_3.npz ├── wisconsin_split_0.6_0.2_4.npz ├── wisconsin_split_0.6_0.2_5.npz ├── wisconsin_split_0.6_0.2_6.npz ├── wisconsin_split_0.6_0.2_7.npz ├── wisconsin_split_0.6_0.2_8.npz └── wisconsin_split_0.6_0.2_9.npz ├── train.py └── utils.py /PyG/cora/cora.py: -------------------------------------------------------------------------------- 1 | import os.path as osp 2 | import argparse 3 | import torch 4 | import torch.nn.functional as F 5 | from torch_geometric.datasets import Planetoid 6 | import torch_geometric.transforms as T 7 | from layer import GCNIIdenseConv 8 | import math 9 | 10 | parser = argparse.ArgumentParser() 11 | parser.add_argument('--layer', type=int, default=128, help='Number of layers.') 12 | args = parser.parse_args() 13 | 14 | dataset = 'Cora' 15 | path = osp.join(osp.dirname(osp.realpath(__file__)), '.', 'data', dataset) 16 | dataset = Planetoid(path, dataset,split="public", transform = T.NormalizeFeatures()) 17 | data = dataset[0] 18 | 19 | print(data.train_mask.sum()) 20 | print(data.val_mask.sum()) 21 | print(data.test_mask.sum()) 22 | 23 | ###################hyperparameters 24 | nlayer = args.layer 25 | dropout = 0.6 26 | alpha = 0.1 27 | lamda = 0.5 28 | hidden_dim = 64 29 | weight_decay1 = 0.01 30 | weight_decay2 = 5e-4 31 | lr = 0.01 32 | patience = 100 33 | ##################### 34 | 35 | GConv = GCNIIdenseConv 36 | 37 | 38 | class GCNII_model(torch.nn.Module): 39 | def __init__(self): 40 | super(GCNII_model, self).__init__() 41 | self.convs = torch.nn.ModuleList() 42 | self.convs.append(torch.nn.Linear(dataset.num_features, hidden_dim)) 43 | for _ in range(nlayer): 44 | self.convs.append(GConv(hidden_dim, hidden_dim)) 45 | self.convs.append(torch.nn.Linear(hidden_dim,dataset.num_classes)) 46 | self.reg_params = list(self.convs[1:-1].parameters()) 47 | self.non_reg_params = list(self.convs[0:1].parameters())+list(self.convs[-1:].parameters()) 48 | 49 | def forward(self): 50 | x, edge_index, edge_weight = data.x, data.edge_index, data.edge_attr 51 | _hidden = [] 52 | x = F.dropout(x, dropout ,training=self.training) 53 | x = F.relu(self.convs[0](x)) 54 | _hidden.append(x) 55 | for i,con in enumerate(self.convs[1:-1]): 56 | x = F.dropout(x, dropout ,training=self.training) 57 | beta = math.log(lamda/(i+1)+1) 58 | x = F.relu(con(x, edge_index,alpha, _hidden[0],beta,edge_weight)) 59 | x = F.dropout(x, dropout ,training=self.training) 60 | x = self.convs[-1](x) 61 | return F.log_softmax(x, dim=1) 62 | 63 | 64 | 65 | device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu') 66 | 67 | model, data = GCNII_model().to(device), data.to(device) 68 | optimizer = torch.optim.Adam([ 69 | dict(params=model.reg_params, weight_decay=weight_decay1), 70 | dict(params=model.non_reg_params, weight_decay=weight_decay2) 71 | ], lr=lr) 72 | 73 | def train(): 74 | model.train() 75 | optimizer.zero_grad() 76 | loss_train = F.nll_loss(model()[data.train_mask], data.y[data.train_mask]) 77 | loss_train.backward() 78 | optimizer.step() 79 | return loss_train.item() 80 | 81 | 82 | @torch.no_grad() 83 | def test(): 84 | model.eval() 85 | logits = model() 86 | loss_val = F.nll_loss(logits[data.val_mask], data.y[data.val_mask]).item() 87 | for _, mask in data('test_mask'): 88 | pred = logits[mask].max(1)[1] 89 | accs = pred.eq(data.y[mask]).sum().item() / mask.sum().item() 90 | return loss_val,accs 91 | 92 | 93 | best_val_loss = 9999999 94 | test_acc = 0 95 | bad_counter = 0 96 | best_epoch = 0 97 | for epoch in range(1, 1500): 98 | loss_tra = train() 99 | loss_val,acc_test_tmp = test() 100 | if loss_val < best_val_loss: 101 | best_val_loss = loss_val 102 | test_acc = acc_test_tmp 103 | bad_counter = 0 104 | best_epoch = epoch 105 | else: 106 | bad_counter+=1 107 | if epoch%20 == 0: 108 | log = 'Epoch: {:03d}, Train loss: {:.4f}, Val loss: {:.4f}, Test acc: {:.4f}' 109 | print(log.format(epoch, loss_tra, loss_val, test_acc)) 110 | if bad_counter == patience: 111 | break 112 | log = 'best Epoch: {:03d}, Val loss: {:.4f}, Test acc: {:.4f}' 113 | print(log.format(best_epoch, best_val_loss, test_acc)) 114 | -------------------------------------------------------------------------------- /PyG/cora/layer.py: -------------------------------------------------------------------------------- 1 | from typing import Tuple, Optional, Union 2 | import torch 3 | from torch import Tensor 4 | from torch.nn import Parameter 5 | import torch.nn as nn 6 | from torch_scatter import scatter_add 7 | from torch_sparse import SparseTensor, matmul, fill_diag, sum, mul_ 8 | from torch_geometric.nn.conv import MessagePassing 9 | from torch_geometric.utils import add_remaining_self_loops 10 | from torch_geometric.utils.num_nodes import maybe_num_nodes 11 | 12 | from torch_geometric.nn.inits import glorot, zeros 13 | 14 | Adj = Union[Tensor, SparseTensor] 15 | OptTensor = Optional[Tensor] 16 | PairTensor = Tuple[Tensor, Tensor] 17 | OptPairTensor = Tuple[Tensor, Optional[Tensor]] 18 | PairOptTensor = Tuple[Optional[Tensor], Optional[Tensor]] 19 | Size = Optional[Tuple[int, int]] 20 | NoneType = Optional[Tensor] 21 | 22 | 23 | @torch.jit._overload 24 | def gcn_norm(edge_index, edge_weight=None, num_nodes=None, improved=False, 25 | add_self_loops=True, dtype=None): 26 | # type: (Tensor, OptTensor, Optional[int], bool, bool, Optional[int]) -> PairTensor # noqa 27 | pass 28 | 29 | 30 | @torch.jit._overload 31 | def gcn_norm(edge_index, edge_weight=None, num_nodes=None, improved=False, 32 | add_self_loops=True, dtype=None): 33 | # type: (SparseTensor, OptTensor, Optional[int], bool, bool, Optional[int]) -> SparseTensor # noqa 34 | pass 35 | 36 | 37 | def gcn_norm(edge_index, edge_weight=None, num_nodes=None, improved=False, 38 | add_self_loops=True, dtype=None): 39 | 40 | fill_value = 2. if improved else 1. 41 | 42 | if isinstance(edge_index, SparseTensor): 43 | adj_t = edge_index 44 | if not adj_t.has_value(): 45 | adj_t.fill_value(1., dtype=dtype) 46 | if add_self_loops: 47 | adj_t = fill_diag(adj_t, fill_value) 48 | deg = sum(adj_t, dim=1) 49 | deg_inv_sqrt = deg.pow_(-0.5) 50 | deg_inv_sqrt.masked_fill_(deg_inv_sqrt == float('inf'), 0.) 51 | adj_t = mul_(adj_t, deg_inv_sqrt.view(-1, 1)) 52 | adj_t = mul_(adj_t, deg_inv_sqrt.view(1, -1)) 53 | return adj_t 54 | 55 | else: 56 | num_nodes = maybe_num_nodes(edge_index, num_nodes) 57 | 58 | if edge_weight is None: 59 | edge_weight = torch.ones((edge_index.size(1), ), dtype=dtype, 60 | device=edge_index.device) 61 | 62 | if add_self_loops: 63 | edge_index, tmp_edge_weight = add_remaining_self_loops( 64 | edge_index, edge_weight, fill_value, num_nodes) 65 | assert tmp_edge_weight is not None 66 | edge_weight = tmp_edge_weight 67 | 68 | row, col = edge_index[0], edge_index[1] 69 | deg = scatter_add(edge_weight, col, dim=0, dim_size=num_nodes) 70 | deg_inv_sqrt = deg.pow_(-0.5) 71 | deg_inv_sqrt.masked_fill_(deg_inv_sqrt == float('inf'), 0) 72 | return edge_index, deg_inv_sqrt[row] * edge_weight * deg_inv_sqrt[col] 73 | 74 | class GCNIIdenseConv(MessagePassing): 75 | _cached_edge_index: Optional[Tuple[torch.Tensor, torch.Tensor]] 76 | _cached_adj_t: Optional[SparseTensor] 77 | 78 | def __init__(self, in_channels: int, out_channels: int, 79 | improved: bool = False, cached: bool = True, 80 | add_self_loops: bool = True, normalize: bool = True, 81 | **kwargs): 82 | 83 | super(GCNIIdenseConv, self).__init__(aggr='add', **kwargs) 84 | 85 | self.in_channels = in_channels 86 | self.out_channels = out_channels 87 | self.improved = improved 88 | self.cached = cached 89 | self.normalize = normalize 90 | self.add_self_loops = add_self_loops 91 | 92 | self._cached_edge_index = None 93 | self._cached_adj_t = None 94 | 95 | self.weight1 = Parameter(torch.Tensor(in_channels, out_channels)) 96 | self.weight2 = Parameter(torch.Tensor(in_channels, out_channels)) 97 | 98 | self.reset_parameters() 99 | 100 | def reset_parameters(self): 101 | glorot(self.weight1) 102 | glorot(self.weight2) 103 | self._cached_edge_index = None 104 | self._cached_adj_t = None 105 | 106 | def forward(self, x: Tensor, edge_index: Adj, alpha, h0, beta, 107 | edge_weight: OptTensor = None) -> Tensor: 108 | """""" 109 | 110 | if self.normalize: 111 | if isinstance(edge_index, Tensor): 112 | cache = self._cached_edge_index 113 | if cache is None: 114 | edge_index, edge_weight = gcn_norm( # yapf: disable 115 | edge_index, edge_weight, x.size(self.node_dim), 116 | self.improved, self.add_self_loops, dtype=x.dtype) 117 | if self.cached: 118 | self._cached_edge_index = (edge_index, edge_weight) 119 | else: 120 | edge_index, edge_weight = cache[0], cache[1] 121 | 122 | elif isinstance(edge_index, SparseTensor): 123 | cache = self._cached_adj_t 124 | if cache is None: 125 | edge_index = gcn_norm( # yapf: disable 126 | edge_index, edge_weight, x.size(self.node_dim), 127 | self.improved, self.add_self_loops, dtype=x.dtype) 128 | if self.cached: 129 | self._cached_adj_t = edge_index 130 | else: 131 | edge_index = cache 132 | 133 | 134 | 135 | support = (1-beta)*(1-alpha)*x + beta*torch.matmul(x, self.weight1) 136 | initial = (1-beta)*(alpha)*h0 + beta*torch.matmul(h0, self.weight2) 137 | 138 | # propagate_type: (x: Tensor, edge_weight: OptTensor) 139 | out = self.propagate(edge_index, x=support, edge_weight=edge_weight, 140 | size=None)+initial 141 | return out 142 | 143 | def message(self, x_j: Tensor, edge_weight: OptTensor) -> Tensor: 144 | assert edge_weight is not None 145 | return edge_weight.view(-1, 1) * x_j 146 | 147 | def message_and_aggregate(self, adj_t: SparseTensor, x: Tensor) -> Tensor: 148 | return matmul(adj_t, x, reduce=self.aggr) 149 | 150 | def __repr__(self): 151 | return '{}({}, {})'.format(self.__class__.__name__, self.in_channels, 152 | self.out_channels) -------------------------------------------------------------------------------- /PyG/ogbn-arxiv/README.md: -------------------------------------------------------------------------------- 1 | # ogbn-arxiv 2 | This repository includes a simple *PyTorch Geometric* implementation of "Simple and Deep Graph Convolutional Networks". 3 | 4 | ## Requirements 5 | - CUDA 10.1 6 | - python 3.6.10 7 | - pytorch 1.5.1 8 | - torch-geometric 1.5.0 9 | - ogb 1.2.0 10 | 11 | ## Training & Evaluation 12 | ``` 13 | python arxiv.py 14 | ``` 15 | - Accuracy: 0.7274 ± 0.0016 16 | - Params: 2,148,648 17 | - Hardware: Quadro RTX 8000 (48GB GPU) -------------------------------------------------------------------------------- /PyG/ogbn-arxiv/arxiv.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import torch 3 | from torch.nn import Parameter 4 | import torch.nn.functional as F 5 | from torch_sparse import SparseTensor 6 | from torch_geometric.utils import to_undirected 7 | from ogb.nodeproppred import PygNodePropPredDataset, Evaluator 8 | from layer import GCNIIdenseConv 9 | import math 10 | import numpy as np 11 | 12 | class GCNIIdense_model(torch.nn.Module): 13 | def __init__(self, in_channels, hidden_channels, out_channels, num_layers,dropout,alpha,norm): 14 | super(GCNIIdense_model, self).__init__() 15 | self.convs = torch.nn.ModuleList() 16 | self.convs.append(torch.nn.Linear(in_channels, hidden_channels)) 17 | for _ in range(num_layers): 18 | self.convs.append(GCNIIdenseConv(hidden_channels, hidden_channels,bias=norm)) 19 | self.convs.append(torch.nn.Linear(hidden_channels,out_channels)) 20 | self.reg_params = list(self.convs[1:-1].parameters()) 21 | self.non_reg_params = list(self.convs[0:1].parameters())+list(self.convs[-1:].parameters()) 22 | self.dropout = dropout 23 | self.alpha = alpha 24 | 25 | def forward(self,data): 26 | x, edge_index, edge_weight = data.x, data.edge_index, data.edge_attr 27 | _hidden = [] 28 | x = F.dropout(x, self.dropout ,training=self.training) 29 | x = F.relu(self.convs[0](x)) 30 | _hidden.append(x) 31 | for i,con in enumerate(self.convs[1:-1]): 32 | x = F.dropout(x, self.dropout ,training=self.training) 33 | x = F.relu(con(x, edge_index,self.alpha, _hidden[0],edge_weight))+_hidden[-1] 34 | _hidden.append(x) 35 | x = F.dropout(x, self.dropout ,training=self.training) 36 | x = self.convs[-1](x) 37 | return F.log_softmax(x, dim=1) 38 | 39 | def train(model, data, train_idx, optimizer): 40 | model.train() 41 | 42 | optimizer.zero_grad() 43 | 44 | pred = model(data)[train_idx] 45 | 46 | loss = F.nll_loss(pred, data.y.squeeze(1)[train_idx]) 47 | loss.backward() 48 | optimizer.step() 49 | 50 | return loss.item() 51 | 52 | 53 | 54 | @torch.no_grad() 55 | def test(model, data, y_true,split_idx, evaluator): 56 | model.eval() 57 | 58 | out = model(data) 59 | y_pred = out.argmax(dim=-1, keepdim=True) 60 | 61 | train_acc = evaluator.eval({ 62 | 'y_true': y_true[split_idx['train']], 63 | 'y_pred': y_pred[split_idx['train']], 64 | })['acc'] 65 | valid_acc = evaluator.eval({ 66 | 'y_true': y_true[split_idx['valid']], 67 | 'y_pred': y_pred[split_idx['valid']], 68 | })['acc'] 69 | test_acc = evaluator.eval({ 70 | 'y_true': y_true[split_idx['test']], 71 | 'y_pred': y_pred[split_idx['test']], 72 | })['acc'] 73 | 74 | return train_acc, valid_acc, test_acc 75 | 76 | 77 | def main(): 78 | parser = argparse.ArgumentParser(description='OGBN-Arxiv (Full-Batch)') 79 | parser.add_argument('--device', type=int, default=1) 80 | parser.add_argument('--log_steps', type=int, default=10) 81 | parser.add_argument('--num_layers', type=int, default=16) 82 | parser.add_argument('--hidden_channels', type=int, default=256) 83 | parser.add_argument('--dropout', type=float, default=0.1) 84 | parser.add_argument('--weight_decay', type=float, default=0, help='weight decay (L2 loss on parameters).') 85 | parser.add_argument('--lr', type=float, default=0.001) 86 | parser.add_argument('--epochs', type=int, default=1000) 87 | parser.add_argument('--runs', type=int, default=10) 88 | parser.add_argument('--patience', type=int, default=200, help='patience') 89 | parser.add_argument('--alpha', type=float, default=0.5, help='alpha_l') 90 | parser.add_argument('--norm', default='bn', help='norm layer.') 91 | args = parser.parse_args() 92 | print(args) 93 | 94 | device = f'cuda:{args.device}' if torch.cuda.is_available() else 'cpu' 95 | device = torch.device(device) 96 | 97 | dataset = PygNodePropPredDataset(name='ogbn-arxiv') 98 | split_idx = dataset.get_idx_split() 99 | data = dataset[0] 100 | data = data.to(device) 101 | train_idx = split_idx['train'].to(device) 102 | data.edge_index = to_undirected(data.edge_index, data.num_nodes) 103 | Net = GCNIIdense_model 104 | evaluator = Evaluator(name='ogbn-arxiv') 105 | acc_list = [] 106 | for run in range(args.runs): 107 | model = Net(data.x.size(-1), args.hidden_channels, 108 | dataset.num_classes, args.num_layers, 109 | args.dropout,args.alpha,args.norm).to(device) 110 | optimizer = torch.optim.Adam(model.parameters(), lr=args.lr,weight_decay=args.weight_decay) 111 | bad_counter = 0 112 | best_val = 0 113 | final_test_acc = 0 114 | for epoch in range(1, 1 + args.epochs): 115 | loss = train(model, data, train_idx, optimizer) 116 | result = test(model, data, data.y,split_idx, evaluator) 117 | train_acc, valid_acc, test_acc = result 118 | if epoch % args.log_steps == 0: 119 | train_acc, valid_acc, test_acc = result 120 | print(f'Run: {run + 1:02d}, ' 121 | f'Epoch: {epoch:02d}, ' 122 | f'Loss: {loss:.4f}, ' 123 | f'Train: {100 * train_acc:.2f}%, ' 124 | f'Valid: {100 * valid_acc:.2f}% ' 125 | f'Test: {100 * test_acc:.2f}%') 126 | if valid_acc > best_val: 127 | best_val = valid_acc 128 | final_test_acc = test_acc 129 | bad_counter = 0 130 | else: 131 | bad_counter += 1 132 | 133 | if bad_counter == args.patience: 134 | break 135 | acc_list.append(final_test_acc*100) 136 | print(run+1,':',acc_list[-1]) 137 | acc_list=torch.tensor(acc_list) 138 | print(f'Avg Test: {acc_list.mean():.2f} ± {acc_list.std():.2f}') 139 | 140 | 141 | 142 | 143 | if __name__ == "__main__": 144 | main() 145 | -------------------------------------------------------------------------------- /PyG/ogbn-arxiv/layer.py: -------------------------------------------------------------------------------- 1 | from typing import Tuple, Optional, Union 2 | import torch 3 | from torch import Tensor 4 | from torch.nn import Parameter 5 | import torch.nn as nn 6 | from torch_scatter import scatter_add 7 | from torch_sparse import SparseTensor, matmul, fill_diag, sum, mul_ 8 | from torch_geometric.nn.conv import MessagePassing 9 | from torch_geometric.utils import add_remaining_self_loops 10 | from torch_geometric.utils.num_nodes import maybe_num_nodes 11 | 12 | from torch_geometric.nn.inits import glorot, zeros 13 | 14 | Adj = Union[Tensor, SparseTensor] 15 | OptTensor = Optional[Tensor] 16 | PairTensor = Tuple[Tensor, Tensor] 17 | OptPairTensor = Tuple[Tensor, Optional[Tensor]] 18 | PairOptTensor = Tuple[Optional[Tensor], Optional[Tensor]] 19 | Size = Optional[Tuple[int, int]] 20 | NoneType = Optional[Tensor] 21 | 22 | 23 | @torch.jit._overload 24 | def gcn_norm(edge_index, edge_weight=None, num_nodes=None, improved=False, 25 | add_self_loops=True, dtype=None): 26 | # type: (Tensor, OptTensor, Optional[int], bool, bool, Optional[int]) -> PairTensor # noqa 27 | pass 28 | 29 | 30 | @torch.jit._overload 31 | def gcn_norm(edge_index, edge_weight=None, num_nodes=None, improved=False, 32 | add_self_loops=True, dtype=None): 33 | # type: (SparseTensor, OptTensor, Optional[int], bool, bool, Optional[int]) -> SparseTensor # noqa 34 | pass 35 | 36 | 37 | def gcn_norm(edge_index, edge_weight=None, num_nodes=None, improved=False, 38 | add_self_loops=True, dtype=None): 39 | 40 | fill_value = 2. if improved else 1. 41 | 42 | if isinstance(edge_index, SparseTensor): 43 | adj_t = edge_index 44 | if not adj_t.has_value(): 45 | adj_t.fill_value(1., dtype=dtype) 46 | if add_self_loops: 47 | adj_t = fill_diag(adj_t, fill_value) 48 | deg = sum(adj_t, dim=1) 49 | deg_inv_sqrt = deg.pow_(-0.5) 50 | deg_inv_sqrt.masked_fill_(deg_inv_sqrt == float('inf'), 0.) 51 | adj_t = mul_(adj_t, deg_inv_sqrt.view(-1, 1)) 52 | adj_t = mul_(adj_t, deg_inv_sqrt.view(1, -1)) 53 | return adj_t 54 | 55 | else: 56 | num_nodes = maybe_num_nodes(edge_index, num_nodes) 57 | 58 | if edge_weight is None: 59 | edge_weight = torch.ones((edge_index.size(1), ), dtype=dtype, 60 | device=edge_index.device) 61 | 62 | if add_self_loops: 63 | edge_index, tmp_edge_weight = add_remaining_self_loops( 64 | edge_index, edge_weight, fill_value, num_nodes) 65 | assert tmp_edge_weight is not None 66 | edge_weight = tmp_edge_weight 67 | 68 | row, col = edge_index[0], edge_index[1] 69 | deg = scatter_add(edge_weight, col, dim=0, dim_size=num_nodes) 70 | deg_inv_sqrt = deg.pow_(-0.5) 71 | deg_inv_sqrt.masked_fill_(deg_inv_sqrt == float('inf'), 0) 72 | return edge_index, deg_inv_sqrt[row] * edge_weight * deg_inv_sqrt[col] 73 | 74 | class GCNIIdenseConv(MessagePassing): 75 | 76 | _cached_edge_index: Optional[Tuple[torch.Tensor, torch.Tensor]] 77 | _cached_adj_t: Optional[SparseTensor] 78 | 79 | def __init__(self, in_channels: int, out_channels: int, 80 | improved: bool = False, cached: bool = True, 81 | add_self_loops: bool = True, normalize: bool = True, 82 | bias='bn', **kwargs): 83 | 84 | super(GCNIIdenseConv, self).__init__(aggr='add', **kwargs) 85 | 86 | self.in_channels = in_channels 87 | self.out_channels = out_channels 88 | self.improved = improved 89 | self.cached = cached 90 | self.normalize = normalize 91 | self.add_self_loops = add_self_loops 92 | 93 | self._cached_edge_index = None 94 | self._cached_adj_t = None 95 | 96 | self.weight1 = Parameter(torch.Tensor(in_channels, out_channels)) 97 | self.weight2 = Parameter(torch.Tensor(in_channels, out_channels)) 98 | if bias == 'bn': 99 | self.norm = nn.BatchNorm1d(out_channels) 100 | elif bias == 'ln': 101 | self.norm = nn.LayerNorm(out_channels) 102 | 103 | self.reset_parameters() 104 | 105 | def reset_parameters(self): 106 | glorot(self.weight1) 107 | glorot(self.weight2) 108 | self._cached_edge_index = None 109 | self._cached_adj_t = None 110 | 111 | def forward(self, x: Tensor, edge_index: Adj, alpha, h0, 112 | edge_weight: OptTensor = None) -> Tensor: 113 | """""" 114 | 115 | if self.normalize: 116 | if isinstance(edge_index, Tensor): 117 | cache = self._cached_edge_index 118 | if cache is None: 119 | edge_index, edge_weight = gcn_norm( # yapf: disable 120 | edge_index, edge_weight, x.size(self.node_dim), 121 | self.improved, self.add_self_loops, dtype=x.dtype) 122 | if self.cached: 123 | self._cached_edge_index = (edge_index, edge_weight) 124 | else: 125 | edge_index, edge_weight = cache[0], cache[1] 126 | 127 | elif isinstance(edge_index, SparseTensor): 128 | cache = self._cached_adj_t 129 | if cache is None: 130 | edge_index = gcn_norm( # yapf: disable 131 | edge_index, edge_weight, x.size(self.node_dim), 132 | self.improved, self.add_self_loops, dtype=x.dtype) 133 | if self.cached: 134 | self._cached_adj_t = edge_index 135 | else: 136 | edge_index = cache 137 | 138 | support = x + torch.matmul(x, self.weight1) 139 | initial = alpha*h0 + torch.matmul(h0, self.weight2) 140 | 141 | # propagate_type: (x: Tensor, edge_weight: OptTensor) 142 | out = self.propagate(edge_index, x=support, edge_weight=edge_weight, 143 | size=None)+initial 144 | 145 | out = self.norm(out) 146 | return out 147 | 148 | def message(self, x_j: Tensor, edge_weight: OptTensor) -> Tensor: 149 | assert edge_weight is not None 150 | return edge_weight.view(-1, 1) * x_j 151 | 152 | def message_and_aggregate(self, adj_t: SparseTensor, x: Tensor) -> Tensor: 153 | return matmul(adj_t, x, reduce=self.aggr) 154 | 155 | def __repr__(self): 156 | return '{}({}, {})'.format(self.__class__.__name__, self.in_channels, 157 | self.out_channels) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Simple and Deep Graph Convolutional Networks 2 | [![PWC](https://img.shields.io/endpoint.svg?url=https://paperswithcode.com/badge/simple-and-deep-graph-convolutional-networks/node-classification-on-cora-full-supervised)](https://paperswithcode.com/sota/node-classification-on-cora-full-supervised?p=simple-and-deep-graph-convolutional-networks) 3 | [![PWC](https://img.shields.io/endpoint.svg?url=https://paperswithcode.com/badge/simple-and-deep-graph-convolutional-networks/node-classification-on-pubmed-full-supervised)](https://paperswithcode.com/sota/node-classification-on-pubmed-full-supervised?p=simple-and-deep-graph-convolutional-networks) 4 | [![PWC](https://img.shields.io/endpoint.svg?url=https://paperswithcode.com/badge/simple-and-deep-graph-convolutional-networks/node-classification-on-cora-with-public-split)](https://paperswithcode.com/sota/node-classification-on-cora-with-public-split?p=simple-and-deep-graph-convolutional-networks) 5 | [![PWC](https://img.shields.io/endpoint.svg?url=https://paperswithcode.com/badge/simple-and-deep-graph-convolutional-networks/node-classification-on-ppi)](https://paperswithcode.com/sota/node-classification-on-ppi?p=simple-and-deep-graph-convolutional-networks) 6 | 7 | This repository contains a PyTorch implementation of "Simple and Deep Graph Convolutional Networks".(https://arxiv.org/abs/2007.02133) 8 | 9 | ## Dependencies 10 | - CUDA 10.1 11 | - python 3.6.9 12 | - pytorch 1.3.1 13 | - networkx 2.1 14 | - scikit-learn 15 | 16 | ## Datasets 17 | 18 | The `data` folder contains three benchmark datasets(Cora, Citeseer, Pubmed), and the `newdata` folder contains four datasets(Chameleon, Cornell, Texas, Wisconsin) from [Geom-GCN](https://github.com/graphdml-uiuc-jlu/geom-gcn). We use the same semi-supervised setting as [GCN](https://github.com/tkipf/gcn) and the same full-supervised setting as Geom-GCN. PPI can be downloaded from [GraphSAGE](http://snap.stanford.edu/graphsage/). 19 | 20 | ## Results 21 | Testing accuracy summarized below. 22 | | Dataset | Depth | Metric | Dataset | Depth | Metric | 23 | |:---:|:---:|:---:|:---:|:---:|:---:| 24 | | Cora | 64 | 85.5 | Cham | 8 | 62.48 | 25 | | Cite | 32 | 73.4 | Corn | 16 | 76.49 | 26 | | Pubm | 16 | 80.3 | Texa | 32 | 77.84 | 27 | | Cora(full) | 64 | 88.49 | Wisc | 16 | 81.57 | 28 | | Cite(full) | 64 | 77.13 | PPI | 9 | 99.56 | 29 | | Pubm(full) | 64 | 90.30 | obgn-arxiv | 16 | 72.74 | 30 | 31 | 32 | ## Usage 33 | 34 | - To replicate the semi-supervised results, run the following script 35 | ```sh 36 | sh semi.sh 37 | ``` 38 | - To replicate the full-supervised results, run the following script 39 | ```sh 40 | sh full.sh 41 | ``` 42 | - To replicate the inductive results of PPI, run the following script 43 | ```sh 44 | sh ppi.sh 45 | ``` 46 | ## Reference implementation 47 | The `PyG` folder includes a simple *PyTorch Geometric* implementation of GCNII. 48 | Requirements: `torch-geometric >= 1.5.0` and `ogb >= 1.2.0`. 49 | - Running examples 50 | ``` 51 | python cora.py 52 | python arxiv.py 53 | ``` 54 | 55 | ## Citation 56 | ``` 57 | @article{chenWHDL2020gcnii, 58 | title = {Simple and Deep Graph Convolutional Networks}, 59 | author = {Ming Chen, Zhewei Wei and Zengfeng Huang, Bolin Ding and Yaliang Li}, 60 | year = {2020}, 61 | booktitle = {Proceedings of the 37th International Conference on Machine Learning}, 62 | } 63 | ``` 64 | -------------------------------------------------------------------------------- /data/ind.citeseer.allx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/data/ind.citeseer.allx -------------------------------------------------------------------------------- /data/ind.citeseer.ally: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/data/ind.citeseer.ally -------------------------------------------------------------------------------- /data/ind.citeseer.graph: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/data/ind.citeseer.graph -------------------------------------------------------------------------------- /data/ind.citeseer.test.index: -------------------------------------------------------------------------------- 1 | 2488 2 | 2644 3 | 3261 4 | 2804 5 | 3176 6 | 2432 7 | 3310 8 | 2410 9 | 2812 10 | 2520 11 | 2994 12 | 3282 13 | 2680 14 | 2848 15 | 2670 16 | 3005 17 | 2977 18 | 2592 19 | 2967 20 | 2461 21 | 3184 22 | 2852 23 | 2768 24 | 2905 25 | 2851 26 | 3129 27 | 3164 28 | 2438 29 | 2793 30 | 2763 31 | 2528 32 | 2954 33 | 2347 34 | 2640 35 | 3265 36 | 2874 37 | 2446 38 | 2856 39 | 3149 40 | 2374 41 | 3097 42 | 3301 43 | 2664 44 | 2418 45 | 2655 46 | 2464 47 | 2596 48 | 3262 49 | 3278 50 | 2320 51 | 2612 52 | 2614 53 | 2550 54 | 2626 55 | 2772 56 | 3007 57 | 2733 58 | 2516 59 | 2476 60 | 2798 61 | 2561 62 | 2839 63 | 2685 64 | 2391 65 | 2705 66 | 3098 67 | 2754 68 | 3251 69 | 2767 70 | 2630 71 | 2727 72 | 2513 73 | 2701 74 | 3264 75 | 2792 76 | 2821 77 | 3260 78 | 2462 79 | 3307 80 | 2639 81 | 2900 82 | 3060 83 | 2672 84 | 3116 85 | 2731 86 | 3316 87 | 2386 88 | 2425 89 | 2518 90 | 3151 91 | 2586 92 | 2797 93 | 2479 94 | 3117 95 | 2580 96 | 3182 97 | 2459 98 | 2508 99 | 3052 100 | 3230 101 | 3215 102 | 2803 103 | 2969 104 | 2562 105 | 2398 106 | 3325 107 | 2343 108 | 3030 109 | 2414 110 | 2776 111 | 2383 112 | 3173 113 | 2850 114 | 2499 115 | 3312 116 | 2648 117 | 2784 118 | 2898 119 | 3056 120 | 2484 121 | 3179 122 | 3132 123 | 2577 124 | 2563 125 | 2867 126 | 3317 127 | 2355 128 | 3207 129 | 3178 130 | 2968 131 | 3319 132 | 2358 133 | 2764 134 | 3001 135 | 2683 136 | 3271 137 | 2321 138 | 2567 139 | 2502 140 | 3246 141 | 2715 142 | 3066 143 | 2390 144 | 2381 145 | 3162 146 | 2741 147 | 2498 148 | 2790 149 | 3038 150 | 3321 151 | 2481 152 | 3050 153 | 3161 154 | 3122 155 | 2801 156 | 2957 157 | 3177 158 | 2965 159 | 2621 160 | 3208 161 | 2921 162 | 2802 163 | 2357 164 | 2677 165 | 2519 166 | 2860 167 | 2696 168 | 2368 169 | 3241 170 | 2858 171 | 2419 172 | 2762 173 | 2875 174 | 3222 175 | 3064 176 | 2827 177 | 3044 178 | 2471 179 | 3062 180 | 2982 181 | 2736 182 | 2322 183 | 2709 184 | 2766 185 | 2424 186 | 2602 187 | 2970 188 | 2675 189 | 3299 190 | 2554 191 | 2964 192 | 2597 193 | 2753 194 | 2979 195 | 2523 196 | 2912 197 | 2896 198 | 2317 199 | 3167 200 | 2813 201 | 2482 202 | 2557 203 | 3043 204 | 3244 205 | 2985 206 | 2460 207 | 2363 208 | 3272 209 | 3045 210 | 3192 211 | 2453 212 | 2656 213 | 2834 214 | 2443 215 | 3202 216 | 2926 217 | 2711 218 | 2633 219 | 2384 220 | 2752 221 | 3285 222 | 2817 223 | 2483 224 | 2919 225 | 2924 226 | 2661 227 | 2698 228 | 2361 229 | 2662 230 | 2819 231 | 3143 232 | 2316 233 | 3196 234 | 2739 235 | 2345 236 | 2578 237 | 2822 238 | 3229 239 | 2908 240 | 2917 241 | 2692 242 | 3200 243 | 2324 244 | 2522 245 | 3322 246 | 2697 247 | 3163 248 | 3093 249 | 3233 250 | 2774 251 | 2371 252 | 2835 253 | 2652 254 | 2539 255 | 2843 256 | 3231 257 | 2976 258 | 2429 259 | 2367 260 | 3144 261 | 2564 262 | 3283 263 | 3217 264 | 3035 265 | 2962 266 | 2433 267 | 2415 268 | 2387 269 | 3021 270 | 2595 271 | 2517 272 | 2468 273 | 3061 274 | 2673 275 | 2348 276 | 3027 277 | 2467 278 | 3318 279 | 2959 280 | 3273 281 | 2392 282 | 2779 283 | 2678 284 | 3004 285 | 2634 286 | 2974 287 | 3198 288 | 2342 289 | 2376 290 | 3249 291 | 2868 292 | 2952 293 | 2710 294 | 2838 295 | 2335 296 | 2524 297 | 2650 298 | 3186 299 | 2743 300 | 2545 301 | 2841 302 | 2515 303 | 2505 304 | 3181 305 | 2945 306 | 2738 307 | 2933 308 | 3303 309 | 2611 310 | 3090 311 | 2328 312 | 3010 313 | 3016 314 | 2504 315 | 2936 316 | 3266 317 | 3253 318 | 2840 319 | 3034 320 | 2581 321 | 2344 322 | 2452 323 | 2654 324 | 3199 325 | 3137 326 | 2514 327 | 2394 328 | 2544 329 | 2641 330 | 2613 331 | 2618 332 | 2558 333 | 2593 334 | 2532 335 | 2512 336 | 2975 337 | 3267 338 | 2566 339 | 2951 340 | 3300 341 | 2869 342 | 2629 343 | 2747 344 | 3055 345 | 2831 346 | 3105 347 | 3168 348 | 3100 349 | 2431 350 | 2828 351 | 2684 352 | 3269 353 | 2910 354 | 2865 355 | 2693 356 | 2884 357 | 3228 358 | 2783 359 | 3247 360 | 2770 361 | 3157 362 | 2421 363 | 2382 364 | 2331 365 | 3203 366 | 3240 367 | 2351 368 | 3114 369 | 2986 370 | 2688 371 | 2439 372 | 2996 373 | 3079 374 | 3103 375 | 3296 376 | 2349 377 | 2372 378 | 3096 379 | 2422 380 | 2551 381 | 3069 382 | 2737 383 | 3084 384 | 3304 385 | 3022 386 | 2542 387 | 3204 388 | 2949 389 | 2318 390 | 2450 391 | 3140 392 | 2734 393 | 2881 394 | 2576 395 | 3054 396 | 3089 397 | 3125 398 | 2761 399 | 3136 400 | 3111 401 | 2427 402 | 2466 403 | 3101 404 | 3104 405 | 3259 406 | 2534 407 | 2961 408 | 3191 409 | 3000 410 | 3036 411 | 2356 412 | 2800 413 | 3155 414 | 3224 415 | 2646 416 | 2735 417 | 3020 418 | 2866 419 | 2426 420 | 2448 421 | 3226 422 | 3219 423 | 2749 424 | 3183 425 | 2906 426 | 2360 427 | 2440 428 | 2946 429 | 2313 430 | 2859 431 | 2340 432 | 3008 433 | 2719 434 | 3058 435 | 2653 436 | 3023 437 | 2888 438 | 3243 439 | 2913 440 | 3242 441 | 3067 442 | 2409 443 | 3227 444 | 2380 445 | 2353 446 | 2686 447 | 2971 448 | 2847 449 | 2947 450 | 2857 451 | 3263 452 | 3218 453 | 2861 454 | 3323 455 | 2635 456 | 2966 457 | 2604 458 | 2456 459 | 2832 460 | 2694 461 | 3245 462 | 3119 463 | 2942 464 | 3153 465 | 2894 466 | 2555 467 | 3128 468 | 2703 469 | 2323 470 | 2631 471 | 2732 472 | 2699 473 | 2314 474 | 2590 475 | 3127 476 | 2891 477 | 2873 478 | 2814 479 | 2326 480 | 3026 481 | 3288 482 | 3095 483 | 2706 484 | 2457 485 | 2377 486 | 2620 487 | 2526 488 | 2674 489 | 3190 490 | 2923 491 | 3032 492 | 2334 493 | 3254 494 | 2991 495 | 3277 496 | 2973 497 | 2599 498 | 2658 499 | 2636 500 | 2826 501 | 3148 502 | 2958 503 | 3258 504 | 2990 505 | 3180 506 | 2538 507 | 2748 508 | 2625 509 | 2565 510 | 3011 511 | 3057 512 | 2354 513 | 3158 514 | 2622 515 | 3308 516 | 2983 517 | 2560 518 | 3169 519 | 3059 520 | 2480 521 | 3194 522 | 3291 523 | 3216 524 | 2643 525 | 3172 526 | 2352 527 | 2724 528 | 2485 529 | 2411 530 | 2948 531 | 2445 532 | 2362 533 | 2668 534 | 3275 535 | 3107 536 | 2496 537 | 2529 538 | 2700 539 | 2541 540 | 3028 541 | 2879 542 | 2660 543 | 3324 544 | 2755 545 | 2436 546 | 3048 547 | 2623 548 | 2920 549 | 3040 550 | 2568 551 | 3221 552 | 3003 553 | 3295 554 | 2473 555 | 3232 556 | 3213 557 | 2823 558 | 2897 559 | 2573 560 | 2645 561 | 3018 562 | 3326 563 | 2795 564 | 2915 565 | 3109 566 | 3086 567 | 2463 568 | 3118 569 | 2671 570 | 2909 571 | 2393 572 | 2325 573 | 3029 574 | 2972 575 | 3110 576 | 2870 577 | 3284 578 | 2816 579 | 2647 580 | 2667 581 | 2955 582 | 2333 583 | 2960 584 | 2864 585 | 2893 586 | 2458 587 | 2441 588 | 2359 589 | 2327 590 | 3256 591 | 3099 592 | 3073 593 | 3138 594 | 2511 595 | 2666 596 | 2548 597 | 2364 598 | 2451 599 | 2911 600 | 3237 601 | 3206 602 | 3080 603 | 3279 604 | 2934 605 | 2981 606 | 2878 607 | 3130 608 | 2830 609 | 3091 610 | 2659 611 | 2449 612 | 3152 613 | 2413 614 | 2722 615 | 2796 616 | 3220 617 | 2751 618 | 2935 619 | 3238 620 | 2491 621 | 2730 622 | 2842 623 | 3223 624 | 2492 625 | 3074 626 | 3094 627 | 2833 628 | 2521 629 | 2883 630 | 3315 631 | 2845 632 | 2907 633 | 3083 634 | 2572 635 | 3092 636 | 2903 637 | 2918 638 | 3039 639 | 3286 640 | 2587 641 | 3068 642 | 2338 643 | 3166 644 | 3134 645 | 2455 646 | 2497 647 | 2992 648 | 2775 649 | 2681 650 | 2430 651 | 2932 652 | 2931 653 | 2434 654 | 3154 655 | 3046 656 | 2598 657 | 2366 658 | 3015 659 | 3147 660 | 2944 661 | 2582 662 | 3274 663 | 2987 664 | 2642 665 | 2547 666 | 2420 667 | 2930 668 | 2750 669 | 2417 670 | 2808 671 | 3141 672 | 2997 673 | 2995 674 | 2584 675 | 2312 676 | 3033 677 | 3070 678 | 3065 679 | 2509 680 | 3314 681 | 2396 682 | 2543 683 | 2423 684 | 3170 685 | 2389 686 | 3289 687 | 2728 688 | 2540 689 | 2437 690 | 2486 691 | 2895 692 | 3017 693 | 2853 694 | 2406 695 | 2346 696 | 2877 697 | 2472 698 | 3210 699 | 2637 700 | 2927 701 | 2789 702 | 2330 703 | 3088 704 | 3102 705 | 2616 706 | 3081 707 | 2902 708 | 3205 709 | 3320 710 | 3165 711 | 2984 712 | 3185 713 | 2707 714 | 3255 715 | 2583 716 | 2773 717 | 2742 718 | 3024 719 | 2402 720 | 2718 721 | 2882 722 | 2575 723 | 3281 724 | 2786 725 | 2855 726 | 3014 727 | 2401 728 | 2535 729 | 2687 730 | 2495 731 | 3113 732 | 2609 733 | 2559 734 | 2665 735 | 2530 736 | 3293 737 | 2399 738 | 2605 739 | 2690 740 | 3133 741 | 2799 742 | 2533 743 | 2695 744 | 2713 745 | 2886 746 | 2691 747 | 2549 748 | 3077 749 | 3002 750 | 3049 751 | 3051 752 | 3087 753 | 2444 754 | 3085 755 | 3135 756 | 2702 757 | 3211 758 | 3108 759 | 2501 760 | 2769 761 | 3290 762 | 2465 763 | 3025 764 | 3019 765 | 2385 766 | 2940 767 | 2657 768 | 2610 769 | 2525 770 | 2941 771 | 3078 772 | 2341 773 | 2916 774 | 2956 775 | 2375 776 | 2880 777 | 3009 778 | 2780 779 | 2370 780 | 2925 781 | 2332 782 | 3146 783 | 2315 784 | 2809 785 | 3145 786 | 3106 787 | 2782 788 | 2760 789 | 2493 790 | 2765 791 | 2556 792 | 2890 793 | 2400 794 | 2339 795 | 3201 796 | 2818 797 | 3248 798 | 3280 799 | 2570 800 | 2569 801 | 2937 802 | 3174 803 | 2836 804 | 2708 805 | 2820 806 | 3195 807 | 2617 808 | 3197 809 | 2319 810 | 2744 811 | 2615 812 | 2825 813 | 2603 814 | 2914 815 | 2531 816 | 3193 817 | 2624 818 | 2365 819 | 2810 820 | 3239 821 | 3159 822 | 2537 823 | 2844 824 | 2758 825 | 2938 826 | 3037 827 | 2503 828 | 3297 829 | 2885 830 | 2608 831 | 2494 832 | 2712 833 | 2408 834 | 2901 835 | 2704 836 | 2536 837 | 2373 838 | 2478 839 | 2723 840 | 3076 841 | 2627 842 | 2369 843 | 2669 844 | 3006 845 | 2628 846 | 2788 847 | 3276 848 | 2435 849 | 3139 850 | 3235 851 | 2527 852 | 2571 853 | 2815 854 | 2442 855 | 2892 856 | 2978 857 | 2746 858 | 3150 859 | 2574 860 | 2725 861 | 3188 862 | 2601 863 | 2378 864 | 3075 865 | 2632 866 | 2794 867 | 3270 868 | 3071 869 | 2506 870 | 3126 871 | 3236 872 | 3257 873 | 2824 874 | 2989 875 | 2950 876 | 2428 877 | 2405 878 | 3156 879 | 2447 880 | 2787 881 | 2805 882 | 2720 883 | 2403 884 | 2811 885 | 2329 886 | 2474 887 | 2785 888 | 2350 889 | 2507 890 | 2416 891 | 3112 892 | 2475 893 | 2876 894 | 2585 895 | 2487 896 | 3072 897 | 3082 898 | 2943 899 | 2757 900 | 2388 901 | 2600 902 | 3294 903 | 2756 904 | 3142 905 | 3041 906 | 2594 907 | 2998 908 | 3047 909 | 2379 910 | 2980 911 | 2454 912 | 2862 913 | 3175 914 | 2588 915 | 3031 916 | 3012 917 | 2889 918 | 2500 919 | 2791 920 | 2854 921 | 2619 922 | 2395 923 | 2807 924 | 2740 925 | 2412 926 | 3131 927 | 3013 928 | 2939 929 | 2651 930 | 2490 931 | 2988 932 | 2863 933 | 3225 934 | 2745 935 | 2714 936 | 3160 937 | 3124 938 | 2849 939 | 2676 940 | 2872 941 | 3287 942 | 3189 943 | 2716 944 | 3115 945 | 2928 946 | 2871 947 | 2591 948 | 2717 949 | 2546 950 | 2777 951 | 3298 952 | 2397 953 | 3187 954 | 2726 955 | 2336 956 | 3268 957 | 2477 958 | 2904 959 | 2846 960 | 3121 961 | 2899 962 | 2510 963 | 2806 964 | 2963 965 | 3313 966 | 2679 967 | 3302 968 | 2663 969 | 3053 970 | 2469 971 | 2999 972 | 3311 973 | 2470 974 | 2638 975 | 3120 976 | 3171 977 | 2689 978 | 2922 979 | 2607 980 | 2721 981 | 2993 982 | 2887 983 | 2837 984 | 2929 985 | 2829 986 | 3234 987 | 2649 988 | 2337 989 | 2759 990 | 2778 991 | 2771 992 | 2404 993 | 2589 994 | 3123 995 | 3209 996 | 2729 997 | 3252 998 | 2606 999 | 2579 1000 | 2552 1001 | -------------------------------------------------------------------------------- /data/ind.citeseer.tx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/data/ind.citeseer.tx -------------------------------------------------------------------------------- /data/ind.citeseer.ty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/data/ind.citeseer.ty -------------------------------------------------------------------------------- /data/ind.citeseer.x: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/data/ind.citeseer.x -------------------------------------------------------------------------------- /data/ind.citeseer.y: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/data/ind.citeseer.y -------------------------------------------------------------------------------- /data/ind.cora.allx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/data/ind.cora.allx -------------------------------------------------------------------------------- /data/ind.cora.ally: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/data/ind.cora.ally -------------------------------------------------------------------------------- /data/ind.cora.graph: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/data/ind.cora.graph -------------------------------------------------------------------------------- /data/ind.cora.test.index: -------------------------------------------------------------------------------- 1 | 2692 2 | 2532 3 | 2050 4 | 1715 5 | 2362 6 | 2609 7 | 2622 8 | 1975 9 | 2081 10 | 1767 11 | 2263 12 | 1725 13 | 2588 14 | 2259 15 | 2357 16 | 1998 17 | 2574 18 | 2179 19 | 2291 20 | 2382 21 | 1812 22 | 1751 23 | 2422 24 | 1937 25 | 2631 26 | 2510 27 | 2378 28 | 2589 29 | 2345 30 | 1943 31 | 1850 32 | 2298 33 | 1825 34 | 2035 35 | 2507 36 | 2313 37 | 1906 38 | 1797 39 | 2023 40 | 2159 41 | 2495 42 | 1886 43 | 2122 44 | 2369 45 | 2461 46 | 1925 47 | 2565 48 | 1858 49 | 2234 50 | 2000 51 | 1846 52 | 2318 53 | 1723 54 | 2559 55 | 2258 56 | 1763 57 | 1991 58 | 1922 59 | 2003 60 | 2662 61 | 2250 62 | 2064 63 | 2529 64 | 1888 65 | 2499 66 | 2454 67 | 2320 68 | 2287 69 | 2203 70 | 2018 71 | 2002 72 | 2632 73 | 2554 74 | 2314 75 | 2537 76 | 1760 77 | 2088 78 | 2086 79 | 2218 80 | 2605 81 | 1953 82 | 2403 83 | 1920 84 | 2015 85 | 2335 86 | 2535 87 | 1837 88 | 2009 89 | 1905 90 | 2636 91 | 1942 92 | 2193 93 | 2576 94 | 2373 95 | 1873 96 | 2463 97 | 2509 98 | 1954 99 | 2656 100 | 2455 101 | 2494 102 | 2295 103 | 2114 104 | 2561 105 | 2176 106 | 2275 107 | 2635 108 | 2442 109 | 2704 110 | 2127 111 | 2085 112 | 2214 113 | 2487 114 | 1739 115 | 2543 116 | 1783 117 | 2485 118 | 2262 119 | 2472 120 | 2326 121 | 1738 122 | 2170 123 | 2100 124 | 2384 125 | 2152 126 | 2647 127 | 2693 128 | 2376 129 | 1775 130 | 1726 131 | 2476 132 | 2195 133 | 1773 134 | 1793 135 | 2194 136 | 2581 137 | 1854 138 | 2524 139 | 1945 140 | 1781 141 | 1987 142 | 2599 143 | 1744 144 | 2225 145 | 2300 146 | 1928 147 | 2042 148 | 2202 149 | 1958 150 | 1816 151 | 1916 152 | 2679 153 | 2190 154 | 1733 155 | 2034 156 | 2643 157 | 2177 158 | 1883 159 | 1917 160 | 1996 161 | 2491 162 | 2268 163 | 2231 164 | 2471 165 | 1919 166 | 1909 167 | 2012 168 | 2522 169 | 1865 170 | 2466 171 | 2469 172 | 2087 173 | 2584 174 | 2563 175 | 1924 176 | 2143 177 | 1736 178 | 1966 179 | 2533 180 | 2490 181 | 2630 182 | 1973 183 | 2568 184 | 1978 185 | 2664 186 | 2633 187 | 2312 188 | 2178 189 | 1754 190 | 2307 191 | 2480 192 | 1960 193 | 1742 194 | 1962 195 | 2160 196 | 2070 197 | 2553 198 | 2433 199 | 1768 200 | 2659 201 | 2379 202 | 2271 203 | 1776 204 | 2153 205 | 1877 206 | 2027 207 | 2028 208 | 2155 209 | 2196 210 | 2483 211 | 2026 212 | 2158 213 | 2407 214 | 1821 215 | 2131 216 | 2676 217 | 2277 218 | 2489 219 | 2424 220 | 1963 221 | 1808 222 | 1859 223 | 2597 224 | 2548 225 | 2368 226 | 1817 227 | 2405 228 | 2413 229 | 2603 230 | 2350 231 | 2118 232 | 2329 233 | 1969 234 | 2577 235 | 2475 236 | 2467 237 | 2425 238 | 1769 239 | 2092 240 | 2044 241 | 2586 242 | 2608 243 | 1983 244 | 2109 245 | 2649 246 | 1964 247 | 2144 248 | 1902 249 | 2411 250 | 2508 251 | 2360 252 | 1721 253 | 2005 254 | 2014 255 | 2308 256 | 2646 257 | 1949 258 | 1830 259 | 2212 260 | 2596 261 | 1832 262 | 1735 263 | 1866 264 | 2695 265 | 1941 266 | 2546 267 | 2498 268 | 2686 269 | 2665 270 | 1784 271 | 2613 272 | 1970 273 | 2021 274 | 2211 275 | 2516 276 | 2185 277 | 2479 278 | 2699 279 | 2150 280 | 1990 281 | 2063 282 | 2075 283 | 1979 284 | 2094 285 | 1787 286 | 2571 287 | 2690 288 | 1926 289 | 2341 290 | 2566 291 | 1957 292 | 1709 293 | 1955 294 | 2570 295 | 2387 296 | 1811 297 | 2025 298 | 2447 299 | 2696 300 | 2052 301 | 2366 302 | 1857 303 | 2273 304 | 2245 305 | 2672 306 | 2133 307 | 2421 308 | 1929 309 | 2125 310 | 2319 311 | 2641 312 | 2167 313 | 2418 314 | 1765 315 | 1761 316 | 1828 317 | 2188 318 | 1972 319 | 1997 320 | 2419 321 | 2289 322 | 2296 323 | 2587 324 | 2051 325 | 2440 326 | 2053 327 | 2191 328 | 1923 329 | 2164 330 | 1861 331 | 2339 332 | 2333 333 | 2523 334 | 2670 335 | 2121 336 | 1921 337 | 1724 338 | 2253 339 | 2374 340 | 1940 341 | 2545 342 | 2301 343 | 2244 344 | 2156 345 | 1849 346 | 2551 347 | 2011 348 | 2279 349 | 2572 350 | 1757 351 | 2400 352 | 2569 353 | 2072 354 | 2526 355 | 2173 356 | 2069 357 | 2036 358 | 1819 359 | 1734 360 | 1880 361 | 2137 362 | 2408 363 | 2226 364 | 2604 365 | 1771 366 | 2698 367 | 2187 368 | 2060 369 | 1756 370 | 2201 371 | 2066 372 | 2439 373 | 1844 374 | 1772 375 | 2383 376 | 2398 377 | 1708 378 | 1992 379 | 1959 380 | 1794 381 | 2426 382 | 2702 383 | 2444 384 | 1944 385 | 1829 386 | 2660 387 | 2497 388 | 2607 389 | 2343 390 | 1730 391 | 2624 392 | 1790 393 | 1935 394 | 1967 395 | 2401 396 | 2255 397 | 2355 398 | 2348 399 | 1931 400 | 2183 401 | 2161 402 | 2701 403 | 1948 404 | 2501 405 | 2192 406 | 2404 407 | 2209 408 | 2331 409 | 1810 410 | 2363 411 | 2334 412 | 1887 413 | 2393 414 | 2557 415 | 1719 416 | 1732 417 | 1986 418 | 2037 419 | 2056 420 | 1867 421 | 2126 422 | 1932 423 | 2117 424 | 1807 425 | 1801 426 | 1743 427 | 2041 428 | 1843 429 | 2388 430 | 2221 431 | 1833 432 | 2677 433 | 1778 434 | 2661 435 | 2306 436 | 2394 437 | 2106 438 | 2430 439 | 2371 440 | 2606 441 | 2353 442 | 2269 443 | 2317 444 | 2645 445 | 2372 446 | 2550 447 | 2043 448 | 1968 449 | 2165 450 | 2310 451 | 1985 452 | 2446 453 | 1982 454 | 2377 455 | 2207 456 | 1818 457 | 1913 458 | 1766 459 | 1722 460 | 1894 461 | 2020 462 | 1881 463 | 2621 464 | 2409 465 | 2261 466 | 2458 467 | 2096 468 | 1712 469 | 2594 470 | 2293 471 | 2048 472 | 2359 473 | 1839 474 | 2392 475 | 2254 476 | 1911 477 | 2101 478 | 2367 479 | 1889 480 | 1753 481 | 2555 482 | 2246 483 | 2264 484 | 2010 485 | 2336 486 | 2651 487 | 2017 488 | 2140 489 | 1842 490 | 2019 491 | 1890 492 | 2525 493 | 2134 494 | 2492 495 | 2652 496 | 2040 497 | 2145 498 | 2575 499 | 2166 500 | 1999 501 | 2434 502 | 1711 503 | 2276 504 | 2450 505 | 2389 506 | 2669 507 | 2595 508 | 1814 509 | 2039 510 | 2502 511 | 1896 512 | 2168 513 | 2344 514 | 2637 515 | 2031 516 | 1977 517 | 2380 518 | 1936 519 | 2047 520 | 2460 521 | 2102 522 | 1745 523 | 2650 524 | 2046 525 | 2514 526 | 1980 527 | 2352 528 | 2113 529 | 1713 530 | 2058 531 | 2558 532 | 1718 533 | 1864 534 | 1876 535 | 2338 536 | 1879 537 | 1891 538 | 2186 539 | 2451 540 | 2181 541 | 2638 542 | 2644 543 | 2103 544 | 2591 545 | 2266 546 | 2468 547 | 1869 548 | 2582 549 | 2674 550 | 2361 551 | 2462 552 | 1748 553 | 2215 554 | 2615 555 | 2236 556 | 2248 557 | 2493 558 | 2342 559 | 2449 560 | 2274 561 | 1824 562 | 1852 563 | 1870 564 | 2441 565 | 2356 566 | 1835 567 | 2694 568 | 2602 569 | 2685 570 | 1893 571 | 2544 572 | 2536 573 | 1994 574 | 1853 575 | 1838 576 | 1786 577 | 1930 578 | 2539 579 | 1892 580 | 2265 581 | 2618 582 | 2486 583 | 2583 584 | 2061 585 | 1796 586 | 1806 587 | 2084 588 | 1933 589 | 2095 590 | 2136 591 | 2078 592 | 1884 593 | 2438 594 | 2286 595 | 2138 596 | 1750 597 | 2184 598 | 1799 599 | 2278 600 | 2410 601 | 2642 602 | 2435 603 | 1956 604 | 2399 605 | 1774 606 | 2129 607 | 1898 608 | 1823 609 | 1938 610 | 2299 611 | 1862 612 | 2420 613 | 2673 614 | 1984 615 | 2204 616 | 1717 617 | 2074 618 | 2213 619 | 2436 620 | 2297 621 | 2592 622 | 2667 623 | 2703 624 | 2511 625 | 1779 626 | 1782 627 | 2625 628 | 2365 629 | 2315 630 | 2381 631 | 1788 632 | 1714 633 | 2302 634 | 1927 635 | 2325 636 | 2506 637 | 2169 638 | 2328 639 | 2629 640 | 2128 641 | 2655 642 | 2282 643 | 2073 644 | 2395 645 | 2247 646 | 2521 647 | 2260 648 | 1868 649 | 1988 650 | 2324 651 | 2705 652 | 2541 653 | 1731 654 | 2681 655 | 2707 656 | 2465 657 | 1785 658 | 2149 659 | 2045 660 | 2505 661 | 2611 662 | 2217 663 | 2180 664 | 1904 665 | 2453 666 | 2484 667 | 1871 668 | 2309 669 | 2349 670 | 2482 671 | 2004 672 | 1965 673 | 2406 674 | 2162 675 | 1805 676 | 2654 677 | 2007 678 | 1947 679 | 1981 680 | 2112 681 | 2141 682 | 1720 683 | 1758 684 | 2080 685 | 2330 686 | 2030 687 | 2432 688 | 2089 689 | 2547 690 | 1820 691 | 1815 692 | 2675 693 | 1840 694 | 2658 695 | 2370 696 | 2251 697 | 1908 698 | 2029 699 | 2068 700 | 2513 701 | 2549 702 | 2267 703 | 2580 704 | 2327 705 | 2351 706 | 2111 707 | 2022 708 | 2321 709 | 2614 710 | 2252 711 | 2104 712 | 1822 713 | 2552 714 | 2243 715 | 1798 716 | 2396 717 | 2663 718 | 2564 719 | 2148 720 | 2562 721 | 2684 722 | 2001 723 | 2151 724 | 2706 725 | 2240 726 | 2474 727 | 2303 728 | 2634 729 | 2680 730 | 2055 731 | 2090 732 | 2503 733 | 2347 734 | 2402 735 | 2238 736 | 1950 737 | 2054 738 | 2016 739 | 1872 740 | 2233 741 | 1710 742 | 2032 743 | 2540 744 | 2628 745 | 1795 746 | 2616 747 | 1903 748 | 2531 749 | 2567 750 | 1946 751 | 1897 752 | 2222 753 | 2227 754 | 2627 755 | 1856 756 | 2464 757 | 2241 758 | 2481 759 | 2130 760 | 2311 761 | 2083 762 | 2223 763 | 2284 764 | 2235 765 | 2097 766 | 1752 767 | 2515 768 | 2527 769 | 2385 770 | 2189 771 | 2283 772 | 2182 773 | 2079 774 | 2375 775 | 2174 776 | 2437 777 | 1993 778 | 2517 779 | 2443 780 | 2224 781 | 2648 782 | 2171 783 | 2290 784 | 2542 785 | 2038 786 | 1855 787 | 1831 788 | 1759 789 | 1848 790 | 2445 791 | 1827 792 | 2429 793 | 2205 794 | 2598 795 | 2657 796 | 1728 797 | 2065 798 | 1918 799 | 2427 800 | 2573 801 | 2620 802 | 2292 803 | 1777 804 | 2008 805 | 1875 806 | 2288 807 | 2256 808 | 2033 809 | 2470 810 | 2585 811 | 2610 812 | 2082 813 | 2230 814 | 1915 815 | 1847 816 | 2337 817 | 2512 818 | 2386 819 | 2006 820 | 2653 821 | 2346 822 | 1951 823 | 2110 824 | 2639 825 | 2520 826 | 1939 827 | 2683 828 | 2139 829 | 2220 830 | 1910 831 | 2237 832 | 1900 833 | 1836 834 | 2197 835 | 1716 836 | 1860 837 | 2077 838 | 2519 839 | 2538 840 | 2323 841 | 1914 842 | 1971 843 | 1845 844 | 2132 845 | 1802 846 | 1907 847 | 2640 848 | 2496 849 | 2281 850 | 2198 851 | 2416 852 | 2285 853 | 1755 854 | 2431 855 | 2071 856 | 2249 857 | 2123 858 | 1727 859 | 2459 860 | 2304 861 | 2199 862 | 1791 863 | 1809 864 | 1780 865 | 2210 866 | 2417 867 | 1874 868 | 1878 869 | 2116 870 | 1961 871 | 1863 872 | 2579 873 | 2477 874 | 2228 875 | 2332 876 | 2578 877 | 2457 878 | 2024 879 | 1934 880 | 2316 881 | 1841 882 | 1764 883 | 1737 884 | 2322 885 | 2239 886 | 2294 887 | 1729 888 | 2488 889 | 1974 890 | 2473 891 | 2098 892 | 2612 893 | 1834 894 | 2340 895 | 2423 896 | 2175 897 | 2280 898 | 2617 899 | 2208 900 | 2560 901 | 1741 902 | 2600 903 | 2059 904 | 1747 905 | 2242 906 | 2700 907 | 2232 908 | 2057 909 | 2147 910 | 2682 911 | 1792 912 | 1826 913 | 2120 914 | 1895 915 | 2364 916 | 2163 917 | 1851 918 | 2391 919 | 2414 920 | 2452 921 | 1803 922 | 1989 923 | 2623 924 | 2200 925 | 2528 926 | 2415 927 | 1804 928 | 2146 929 | 2619 930 | 2687 931 | 1762 932 | 2172 933 | 2270 934 | 2678 935 | 2593 936 | 2448 937 | 1882 938 | 2257 939 | 2500 940 | 1899 941 | 2478 942 | 2412 943 | 2107 944 | 1746 945 | 2428 946 | 2115 947 | 1800 948 | 1901 949 | 2397 950 | 2530 951 | 1912 952 | 2108 953 | 2206 954 | 2091 955 | 1740 956 | 2219 957 | 1976 958 | 2099 959 | 2142 960 | 2671 961 | 2668 962 | 2216 963 | 2272 964 | 2229 965 | 2666 966 | 2456 967 | 2534 968 | 2697 969 | 2688 970 | 2062 971 | 2691 972 | 2689 973 | 2154 974 | 2590 975 | 2626 976 | 2390 977 | 1813 978 | 2067 979 | 1952 980 | 2518 981 | 2358 982 | 1789 983 | 2076 984 | 2049 985 | 2119 986 | 2013 987 | 2124 988 | 2556 989 | 2105 990 | 2093 991 | 1885 992 | 2305 993 | 2354 994 | 2135 995 | 2601 996 | 1770 997 | 1995 998 | 2504 999 | 1749 1000 | 2157 1001 | -------------------------------------------------------------------------------- /data/ind.cora.tx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/data/ind.cora.tx -------------------------------------------------------------------------------- /data/ind.cora.ty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/data/ind.cora.ty -------------------------------------------------------------------------------- /data/ind.cora.x: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/data/ind.cora.x -------------------------------------------------------------------------------- /data/ind.cora.y: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/data/ind.cora.y -------------------------------------------------------------------------------- /data/ind.pubmed.allx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/data/ind.pubmed.allx -------------------------------------------------------------------------------- /data/ind.pubmed.ally: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/data/ind.pubmed.ally -------------------------------------------------------------------------------- /data/ind.pubmed.graph: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/data/ind.pubmed.graph -------------------------------------------------------------------------------- /data/ind.pubmed.test.index: -------------------------------------------------------------------------------- 1 | 18747 2 | 19392 3 | 19181 4 | 18843 5 | 19221 6 | 18962 7 | 19560 8 | 19097 9 | 18966 10 | 19014 11 | 18756 12 | 19313 13 | 19000 14 | 19569 15 | 19359 16 | 18854 17 | 18970 18 | 19073 19 | 19661 20 | 19180 21 | 19377 22 | 18750 23 | 19401 24 | 18788 25 | 19224 26 | 19447 27 | 19017 28 | 19241 29 | 18890 30 | 18908 31 | 18965 32 | 19001 33 | 18849 34 | 19641 35 | 18852 36 | 19222 37 | 19172 38 | 18762 39 | 19156 40 | 19162 41 | 18856 42 | 18763 43 | 19318 44 | 18826 45 | 19712 46 | 19192 47 | 19695 48 | 19030 49 | 19523 50 | 19249 51 | 19079 52 | 19232 53 | 19455 54 | 18743 55 | 18800 56 | 19071 57 | 18885 58 | 19593 59 | 19394 60 | 19390 61 | 18832 62 | 19445 63 | 18838 64 | 19632 65 | 19548 66 | 19546 67 | 18825 68 | 19498 69 | 19266 70 | 19117 71 | 19595 72 | 19252 73 | 18730 74 | 18913 75 | 18809 76 | 19452 77 | 19520 78 | 19274 79 | 19555 80 | 19388 81 | 18919 82 | 19099 83 | 19637 84 | 19403 85 | 18720 86 | 19526 87 | 18905 88 | 19451 89 | 19408 90 | 18923 91 | 18794 92 | 19322 93 | 19431 94 | 18912 95 | 18841 96 | 19239 97 | 19125 98 | 19258 99 | 19565 100 | 18898 101 | 19482 102 | 19029 103 | 18778 104 | 19096 105 | 19684 106 | 19552 107 | 18765 108 | 19361 109 | 19171 110 | 19367 111 | 19623 112 | 19402 113 | 19327 114 | 19118 115 | 18888 116 | 18726 117 | 19510 118 | 18831 119 | 19490 120 | 19576 121 | 19050 122 | 18729 123 | 18896 124 | 19246 125 | 19012 126 | 18862 127 | 18873 128 | 19193 129 | 19693 130 | 19474 131 | 18953 132 | 19115 133 | 19182 134 | 19269 135 | 19116 136 | 18837 137 | 18872 138 | 19007 139 | 19212 140 | 18798 141 | 19102 142 | 18772 143 | 19660 144 | 19511 145 | 18914 146 | 18886 147 | 19672 148 | 19360 149 | 19213 150 | 18810 151 | 19420 152 | 19512 153 | 18719 154 | 19432 155 | 19350 156 | 19127 157 | 18782 158 | 19587 159 | 18924 160 | 19488 161 | 18781 162 | 19340 163 | 19190 164 | 19383 165 | 19094 166 | 18835 167 | 19487 168 | 19230 169 | 18791 170 | 18882 171 | 18937 172 | 18928 173 | 18755 174 | 18802 175 | 19516 176 | 18795 177 | 18786 178 | 19273 179 | 19349 180 | 19398 181 | 19626 182 | 19130 183 | 19351 184 | 19489 185 | 19446 186 | 18959 187 | 19025 188 | 18792 189 | 18878 190 | 19304 191 | 19629 192 | 19061 193 | 18785 194 | 19194 195 | 19179 196 | 19210 197 | 19417 198 | 19583 199 | 19415 200 | 19443 201 | 18739 202 | 19662 203 | 18904 204 | 18910 205 | 18901 206 | 18960 207 | 18722 208 | 18827 209 | 19290 210 | 18842 211 | 19389 212 | 19344 213 | 18961 214 | 19098 215 | 19147 216 | 19334 217 | 19358 218 | 18829 219 | 18984 220 | 18931 221 | 18742 222 | 19320 223 | 19111 224 | 19196 225 | 18887 226 | 18991 227 | 19469 228 | 18990 229 | 18876 230 | 19261 231 | 19270 232 | 19522 233 | 19088 234 | 19284 235 | 19646 236 | 19493 237 | 19225 238 | 19615 239 | 19449 240 | 19043 241 | 19674 242 | 19391 243 | 18918 244 | 19155 245 | 19110 246 | 18815 247 | 19131 248 | 18834 249 | 19715 250 | 19603 251 | 19688 252 | 19133 253 | 19053 254 | 19166 255 | 19066 256 | 18893 257 | 18757 258 | 19582 259 | 19282 260 | 19257 261 | 18869 262 | 19467 263 | 18954 264 | 19371 265 | 19151 266 | 19462 267 | 19598 268 | 19653 269 | 19187 270 | 19624 271 | 19564 272 | 19534 273 | 19581 274 | 19478 275 | 18985 276 | 18746 277 | 19342 278 | 18777 279 | 19696 280 | 18824 281 | 19138 282 | 18728 283 | 19643 284 | 19199 285 | 18731 286 | 19168 287 | 18948 288 | 19216 289 | 19697 290 | 19347 291 | 18808 292 | 18725 293 | 19134 294 | 18847 295 | 18828 296 | 18996 297 | 19106 298 | 19485 299 | 18917 300 | 18911 301 | 18776 302 | 19203 303 | 19158 304 | 18895 305 | 19165 306 | 19382 307 | 18780 308 | 18836 309 | 19373 310 | 19659 311 | 18947 312 | 19375 313 | 19299 314 | 18761 315 | 19366 316 | 18754 317 | 19248 318 | 19416 319 | 19658 320 | 19638 321 | 19034 322 | 19281 323 | 18844 324 | 18922 325 | 19491 326 | 19272 327 | 19341 328 | 19068 329 | 19332 330 | 19559 331 | 19293 332 | 18804 333 | 18933 334 | 18935 335 | 19405 336 | 18936 337 | 18945 338 | 18943 339 | 18818 340 | 18797 341 | 19570 342 | 19464 343 | 19428 344 | 19093 345 | 19433 346 | 18986 347 | 19161 348 | 19255 349 | 19157 350 | 19046 351 | 19292 352 | 19434 353 | 19298 354 | 18724 355 | 19410 356 | 19694 357 | 19214 358 | 19640 359 | 19189 360 | 18963 361 | 19218 362 | 19585 363 | 19041 364 | 19550 365 | 19123 366 | 19620 367 | 19376 368 | 19561 369 | 18944 370 | 19706 371 | 19056 372 | 19283 373 | 18741 374 | 19319 375 | 19144 376 | 19542 377 | 18821 378 | 19404 379 | 19080 380 | 19303 381 | 18793 382 | 19306 383 | 19678 384 | 19435 385 | 19519 386 | 19566 387 | 19278 388 | 18946 389 | 19536 390 | 19020 391 | 19057 392 | 19198 393 | 19333 394 | 19649 395 | 19699 396 | 19399 397 | 19654 398 | 19136 399 | 19465 400 | 19321 401 | 19577 402 | 18907 403 | 19665 404 | 19386 405 | 19596 406 | 19247 407 | 19473 408 | 19568 409 | 19355 410 | 18925 411 | 19586 412 | 18982 413 | 19616 414 | 19495 415 | 19612 416 | 19023 417 | 19438 418 | 18817 419 | 19692 420 | 19295 421 | 19414 422 | 19676 423 | 19472 424 | 19107 425 | 19062 426 | 19035 427 | 18883 428 | 19409 429 | 19052 430 | 19606 431 | 19091 432 | 19651 433 | 19475 434 | 19413 435 | 18796 436 | 19369 437 | 19639 438 | 19701 439 | 19461 440 | 19645 441 | 19251 442 | 19063 443 | 19679 444 | 19545 445 | 19081 446 | 19363 447 | 18995 448 | 19549 449 | 18790 450 | 18855 451 | 18833 452 | 18899 453 | 19395 454 | 18717 455 | 19647 456 | 18768 457 | 19103 458 | 19245 459 | 18819 460 | 18779 461 | 19656 462 | 19076 463 | 18745 464 | 18971 465 | 19197 466 | 19711 467 | 19074 468 | 19128 469 | 19466 470 | 19139 471 | 19309 472 | 19324 473 | 18814 474 | 19092 475 | 19627 476 | 19060 477 | 18806 478 | 18929 479 | 18737 480 | 18942 481 | 18906 482 | 18858 483 | 19456 484 | 19253 485 | 19716 486 | 19104 487 | 19667 488 | 19574 489 | 18903 490 | 19237 491 | 18864 492 | 19556 493 | 19364 494 | 18952 495 | 19008 496 | 19323 497 | 19700 498 | 19170 499 | 19267 500 | 19345 501 | 19238 502 | 18909 503 | 18892 504 | 19109 505 | 19704 506 | 18902 507 | 19275 508 | 19680 509 | 18723 510 | 19242 511 | 19112 512 | 19169 513 | 18956 514 | 19343 515 | 19650 516 | 19541 517 | 19698 518 | 19521 519 | 19087 520 | 18976 521 | 19038 522 | 18775 523 | 18968 524 | 19671 525 | 19412 526 | 19407 527 | 19573 528 | 19027 529 | 18813 530 | 19357 531 | 19460 532 | 19673 533 | 19481 534 | 19036 535 | 19614 536 | 18787 537 | 19195 538 | 18732 539 | 18884 540 | 19613 541 | 19657 542 | 19575 543 | 19226 544 | 19589 545 | 19234 546 | 19617 547 | 19707 548 | 19484 549 | 18740 550 | 19424 551 | 18784 552 | 19419 553 | 19159 554 | 18865 555 | 19105 556 | 19315 557 | 19480 558 | 19664 559 | 19378 560 | 18803 561 | 19605 562 | 18870 563 | 19042 564 | 19426 565 | 18848 566 | 19223 567 | 19509 568 | 19532 569 | 18752 570 | 19691 571 | 18718 572 | 19209 573 | 19362 574 | 19090 575 | 19492 576 | 19567 577 | 19687 578 | 19018 579 | 18830 580 | 19530 581 | 19554 582 | 19119 583 | 19442 584 | 19558 585 | 19527 586 | 19427 587 | 19291 588 | 19543 589 | 19422 590 | 19142 591 | 18897 592 | 18950 593 | 19425 594 | 19002 595 | 19588 596 | 18978 597 | 19551 598 | 18930 599 | 18736 600 | 19101 601 | 19215 602 | 19150 603 | 19263 604 | 18949 605 | 18974 606 | 18759 607 | 19335 608 | 19200 609 | 19129 610 | 19328 611 | 19437 612 | 18988 613 | 19429 614 | 19368 615 | 19406 616 | 19049 617 | 18811 618 | 19296 619 | 19256 620 | 19385 621 | 19602 622 | 18770 623 | 19337 624 | 19580 625 | 19476 626 | 19045 627 | 19132 628 | 19089 629 | 19120 630 | 19265 631 | 19483 632 | 18767 633 | 19227 634 | 18934 635 | 19069 636 | 18820 637 | 19006 638 | 19459 639 | 18927 640 | 19037 641 | 19280 642 | 19441 643 | 18823 644 | 19015 645 | 19114 646 | 19618 647 | 18957 648 | 19176 649 | 18853 650 | 19648 651 | 19201 652 | 19444 653 | 19279 654 | 18751 655 | 19302 656 | 19505 657 | 18733 658 | 19601 659 | 19533 660 | 18863 661 | 19708 662 | 19387 663 | 19346 664 | 19152 665 | 19206 666 | 18851 667 | 19338 668 | 19681 669 | 19380 670 | 19055 671 | 18766 672 | 19085 673 | 19591 674 | 19547 675 | 18958 676 | 19146 677 | 18840 678 | 19051 679 | 19021 680 | 19207 681 | 19235 682 | 19086 683 | 18979 684 | 19300 685 | 18939 686 | 19100 687 | 19619 688 | 19287 689 | 18980 690 | 19277 691 | 19326 692 | 19108 693 | 18920 694 | 19625 695 | 19374 696 | 19078 697 | 18734 698 | 19634 699 | 19339 700 | 18877 701 | 19423 702 | 19652 703 | 19683 704 | 19044 705 | 18983 706 | 19330 707 | 19529 708 | 19714 709 | 19468 710 | 19075 711 | 19540 712 | 18839 713 | 19022 714 | 19286 715 | 19537 716 | 19175 717 | 19463 718 | 19167 719 | 19705 720 | 19562 721 | 19244 722 | 19486 723 | 19611 724 | 18801 725 | 19178 726 | 19590 727 | 18846 728 | 19450 729 | 19205 730 | 19381 731 | 18941 732 | 19670 733 | 19185 734 | 19504 735 | 19633 736 | 18997 737 | 19113 738 | 19397 739 | 19636 740 | 19709 741 | 19289 742 | 19264 743 | 19353 744 | 19584 745 | 19126 746 | 18938 747 | 19669 748 | 18964 749 | 19276 750 | 18774 751 | 19173 752 | 19231 753 | 18973 754 | 18769 755 | 19064 756 | 19040 757 | 19668 758 | 18738 759 | 19082 760 | 19655 761 | 19236 762 | 19352 763 | 19609 764 | 19628 765 | 18951 766 | 19384 767 | 19122 768 | 18875 769 | 18992 770 | 18753 771 | 19379 772 | 19254 773 | 19301 774 | 19506 775 | 19135 776 | 19010 777 | 19682 778 | 19400 779 | 19579 780 | 19316 781 | 19553 782 | 19208 783 | 19635 784 | 19644 785 | 18891 786 | 19024 787 | 18989 788 | 19250 789 | 18850 790 | 19317 791 | 18915 792 | 19607 793 | 18799 794 | 18881 795 | 19479 796 | 19031 797 | 19365 798 | 19164 799 | 18744 800 | 18760 801 | 19502 802 | 19058 803 | 19517 804 | 18735 805 | 19448 806 | 19243 807 | 19453 808 | 19285 809 | 18857 810 | 19439 811 | 19016 812 | 18975 813 | 19503 814 | 18998 815 | 18981 816 | 19186 817 | 18994 818 | 19240 819 | 19631 820 | 19070 821 | 19174 822 | 18900 823 | 19065 824 | 19220 825 | 19229 826 | 18880 827 | 19308 828 | 19372 829 | 19496 830 | 18771 831 | 19325 832 | 19538 833 | 19033 834 | 18874 835 | 19077 836 | 19211 837 | 18764 838 | 19458 839 | 19571 840 | 19121 841 | 19019 842 | 19059 843 | 19497 844 | 18969 845 | 19666 846 | 19297 847 | 19219 848 | 19622 849 | 19184 850 | 18977 851 | 19702 852 | 19539 853 | 19329 854 | 19095 855 | 19675 856 | 18972 857 | 19514 858 | 19703 859 | 19188 860 | 18866 861 | 18812 862 | 19314 863 | 18822 864 | 18845 865 | 19494 866 | 19411 867 | 18916 868 | 19686 869 | 18967 870 | 19294 871 | 19143 872 | 19204 873 | 18805 874 | 19689 875 | 19233 876 | 18758 877 | 18748 878 | 19011 879 | 19685 880 | 19336 881 | 19608 882 | 19454 883 | 19124 884 | 18868 885 | 18807 886 | 19544 887 | 19621 888 | 19228 889 | 19154 890 | 19141 891 | 19145 892 | 19153 893 | 18860 894 | 19163 895 | 19393 896 | 19268 897 | 19160 898 | 19305 899 | 19259 900 | 19471 901 | 19524 902 | 18783 903 | 19396 904 | 18894 905 | 19430 906 | 19690 907 | 19348 908 | 19597 909 | 19592 910 | 19677 911 | 18889 912 | 19331 913 | 18773 914 | 19137 915 | 19009 916 | 18932 917 | 19599 918 | 18816 919 | 19054 920 | 19067 921 | 19477 922 | 19191 923 | 18921 924 | 18940 925 | 19578 926 | 19183 927 | 19004 928 | 19072 929 | 19710 930 | 19005 931 | 19610 932 | 18955 933 | 19457 934 | 19148 935 | 18859 936 | 18993 937 | 19642 938 | 19047 939 | 19418 940 | 19535 941 | 19600 942 | 19312 943 | 19039 944 | 19028 945 | 18879 946 | 19003 947 | 19026 948 | 19013 949 | 19149 950 | 19177 951 | 19217 952 | 18987 953 | 19354 954 | 19525 955 | 19202 956 | 19084 957 | 19032 958 | 18749 959 | 18867 960 | 19048 961 | 18999 962 | 19260 963 | 19630 964 | 18727 965 | 19356 966 | 19083 967 | 18926 968 | 18789 969 | 19370 970 | 18861 971 | 19311 972 | 19557 973 | 19531 974 | 19436 975 | 19140 976 | 19310 977 | 19501 978 | 18721 979 | 19604 980 | 19713 981 | 19262 982 | 19563 983 | 19507 984 | 19440 985 | 19572 986 | 19513 987 | 19515 988 | 19518 989 | 19421 990 | 19470 991 | 19499 992 | 19663 993 | 19508 994 | 18871 995 | 19528 996 | 19500 997 | 19307 998 | 19288 999 | 19594 1000 | 19271 1001 | -------------------------------------------------------------------------------- /data/ind.pubmed.tx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/data/ind.pubmed.tx -------------------------------------------------------------------------------- /data/ind.pubmed.ty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/data/ind.pubmed.ty -------------------------------------------------------------------------------- /data/ind.pubmed.x: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/data/ind.pubmed.x -------------------------------------------------------------------------------- /data/ind.pubmed.y: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/data/ind.pubmed.y -------------------------------------------------------------------------------- /full-supervised.py: -------------------------------------------------------------------------------- 1 | from __future__ import division 2 | from __future__ import print_function 3 | import time 4 | import random 5 | import argparse 6 | import numpy as np 7 | import torch 8 | import torch.nn.functional as F 9 | import torch.optim as optim 10 | from process import * 11 | from utils import * 12 | from model import * 13 | import uuid 14 | 15 | # Training settings 16 | parser = argparse.ArgumentParser() 17 | parser.add_argument('--seed', type=int, default=42, help='Random seed.') 18 | parser.add_argument('--epochs', type=int, default=1500, help='Number of epochs to train.') 19 | parser.add_argument('--lr', type=float, default=0.01, help='learning rate.') 20 | parser.add_argument('--weight_decay', type=float, default=0.01, help='weight decay (L2 loss on parameters).') 21 | parser.add_argument('--layer', type=int, default=64, help='Number of layers.') 22 | parser.add_argument('--hidden', type=int, default=64, help='hidden dimensions.') 23 | parser.add_argument('--dropout', type=float, default=0.5, help='Dropout rate (1 - keep probability).') 24 | parser.add_argument('--patience', type=int, default=100, help='Patience') 25 | parser.add_argument('--data', default='cora', help='dateset') 26 | parser.add_argument('--dev', type=int, default=0, help='device id') 27 | parser.add_argument('--alpha', type=float, default=0.5, help='alpha_l') 28 | parser.add_argument('--lamda', type=float, default=0.5, help='lamda.') 29 | parser.add_argument('--variant', action='store_true', default=False, help='GCN* model.') 30 | 31 | args = parser.parse_args() 32 | random.seed(args.seed) 33 | np.random.seed(args.seed) 34 | torch.manual_seed(args.seed) 35 | torch.cuda.manual_seed(args.seed) 36 | 37 | cudaid = "cuda:"+str(args.dev) 38 | device = torch.device(cudaid) 39 | checkpt_file = 'pretrained/'+uuid.uuid4().hex+'.pt' 40 | print(cudaid,checkpt_file) 41 | 42 | def train_step(model,optimizer,features,labels,adj,idx_train): 43 | model.train() 44 | optimizer.zero_grad() 45 | output = model(features,adj) 46 | acc_train = accuracy(output[idx_train], labels[idx_train].to(device)) 47 | loss_train = F.nll_loss(output[idx_train], labels[idx_train].to(device)) 48 | loss_train.backward() 49 | optimizer.step() 50 | return loss_train.item(),acc_train.item() 51 | 52 | 53 | def validate_step(model,features,labels,adj,idx_val): 54 | model.eval() 55 | with torch.no_grad(): 56 | output = model(features,adj) 57 | loss_val = F.nll_loss(output[idx_val], labels[idx_val].to(device)) 58 | acc_val = accuracy(output[idx_val], labels[idx_val].to(device)) 59 | return loss_val.item(),acc_val.item() 60 | 61 | def test_step(model,features,labels,adj,idx_test): 62 | model.load_state_dict(torch.load(checkpt_file)) 63 | model.eval() 64 | with torch.no_grad(): 65 | output = model(features, adj) 66 | loss_test = F.nll_loss(output[idx_test], labels[idx_test].to(device)) 67 | acc_test = accuracy(output[idx_test], labels[idx_test].to(device)) 68 | return loss_test.item(),acc_test.item() 69 | 70 | 71 | def train(datastr,splitstr): 72 | adj, features, labels, idx_train, idx_val, idx_test, num_features, num_labels = full_load_data(datastr,splitstr) 73 | features = features.to(device) 74 | adj = adj.to(device) 75 | model = GCNII(nfeat=num_features, 76 | nlayers=args.layer, 77 | nhidden=args.hidden, 78 | nclass=num_labels, 79 | dropout=args.dropout, 80 | lamda = args.lamda, 81 | alpha=args.alpha, 82 | variant=args.variant).to(device) 83 | optimizer = optim.Adam(model.parameters(), lr=args.lr, 84 | weight_decay=args.weight_decay) 85 | 86 | bad_counter = 0 87 | best = 999999999 88 | for epoch in range(args.epochs): 89 | loss_tra,acc_tra = train_step(model,optimizer,features,labels,adj,idx_train) 90 | loss_val,acc_val = validate_step(model,features,labels,adj,idx_val) 91 | if(epoch+1)%1 == 0: 92 | print('Epoch:{:04d}'.format(epoch+1), 93 | 'train', 94 | 'loss:{:.3f}'.format(loss_tra), 95 | 'acc:{:.2f}'.format(acc_tra*100), 96 | '| val', 97 | 'loss:{:.3f}'.format(loss_val), 98 | 'acc:{:.2f}'.format(acc_val*100)) 99 | if loss_val < best: 100 | best = loss_val 101 | torch.save(model.state_dict(), checkpt_file) 102 | bad_counter = 0 103 | else: 104 | bad_counter += 1 105 | 106 | if bad_counter == args.patience: 107 | break 108 | acc = test_step(model,features,labels,adj,idx_test)[1] 109 | 110 | return acc*100 111 | 112 | t_total = time.time() 113 | acc_list = [] 114 | for i in range(10): 115 | datastr = args.data 116 | splitstr = 'splits/'+args.data+'_split_0.6_0.2_'+str(i)+'.npz' 117 | acc_list.append(train(datastr,splitstr)) 118 | print(i,": {:.2f}".format(acc_list[-1])) 119 | print("Train cost: {:.4f}s".format(time.time() - t_total)) 120 | print("Test acc.:{:.2f}".format(np.mean(acc_list))) -------------------------------------------------------------------------------- /full.sh: -------------------------------------------------------------------------------- 1 | python -u full-supervised.py --data cora --layer 64 --alpha 0.2 --weight_decay 1e-4 2 | python -u full-supervised.py --data cora --layer 64 --alpha 0.2 --weight_decay 1e-4 --variant 3 | python -u full-supervised.py --data citeseer --layer 64 --weight_decay 5e-6 4 | python -u full-supervised.py --data citeseer --layer 64 --weight_decay 5e-6 --variant 5 | python -u full-supervised.py --data pubmed --layer 64 --alpha 0.1 --weight_decay 5e-6 6 | python -u full-supervised.py --data pubmed --layer 64 --alpha 0.1 --weight_decay 5e-6 --variant 7 | python -u full-supervised.py --data chameleon --layer 8 --lamda 1.5 --alpha 0.2 --weight_decay 5e-4 8 | python -u full-supervised.py --data chameleon --layer 8 --lamda 1.5 --alpha 0.2 --weight_decay 5e-4 --variant 9 | python -u full-supervised.py --data cornell --layer 16 --lamda 1 --weight_decay 1e-3 10 | python -u full-supervised.py --data cornell --layer 16 --lamda 1 --weight_decay 1e-3 --variant 11 | python -u full-supervised.py --data texas --layer 32 --lamda 1.5 --weight_decay 1e-4 12 | python -u full-supervised.py --data texas --layer 32 --lamda 1.5 --weight_decay 1e-4 --variant 13 | python -u full-supervised.py --data wisconsin --layer 16 --lamda 1 --weight_decay 5e-4 14 | python -u full-supervised.py --data wisconsin --layer 16 --lamda 1 --weight_decay 5e-4 --variant -------------------------------------------------------------------------------- /model.py: -------------------------------------------------------------------------------- 1 | import torch.nn as nn 2 | import torch 3 | import math 4 | import numpy as np 5 | import torch.nn.functional as F 6 | from torch.nn.parameter import Parameter 7 | 8 | class GraphConvolution(nn.Module): 9 | 10 | def __init__(self, in_features, out_features, residual=False, variant=False): 11 | super(GraphConvolution, self).__init__() 12 | self.variant = variant 13 | if self.variant: 14 | self.in_features = 2*in_features 15 | else: 16 | self.in_features = in_features 17 | 18 | self.out_features = out_features 19 | self.residual = residual 20 | self.weight = Parameter(torch.FloatTensor(self.in_features,self.out_features)) 21 | self.reset_parameters() 22 | 23 | def reset_parameters(self): 24 | stdv = 1. / math.sqrt(self.out_features) 25 | self.weight.data.uniform_(-stdv, stdv) 26 | 27 | def forward(self, input, adj , h0 , lamda, alpha, l): 28 | theta = math.log(lamda/l+1) 29 | hi = torch.spmm(adj, input) 30 | if self.variant: 31 | support = torch.cat([hi,h0],1) 32 | r = (1-alpha)*hi+alpha*h0 33 | else: 34 | support = (1-alpha)*hi+alpha*h0 35 | r = support 36 | output = theta*torch.mm(support, self.weight)+(1-theta)*r 37 | if self.residual: 38 | output = output+input 39 | return output 40 | 41 | class GCNII(nn.Module): 42 | def __init__(self, nfeat, nlayers,nhidden, nclass, dropout, lamda, alpha, variant): 43 | super(GCNII, self).__init__() 44 | self.convs = nn.ModuleList() 45 | for _ in range(nlayers): 46 | self.convs.append(GraphConvolution(nhidden, nhidden,variant=variant)) 47 | self.fcs = nn.ModuleList() 48 | self.fcs.append(nn.Linear(nfeat, nhidden)) 49 | self.fcs.append(nn.Linear(nhidden, nclass)) 50 | self.params1 = list(self.convs.parameters()) 51 | self.params2 = list(self.fcs.parameters()) 52 | self.act_fn = nn.ReLU() 53 | self.dropout = dropout 54 | self.alpha = alpha 55 | self.lamda = lamda 56 | 57 | def forward(self, x, adj): 58 | _layers = [] 59 | x = F.dropout(x, self.dropout, training=self.training) 60 | layer_inner = self.act_fn(self.fcs[0](x)) 61 | _layers.append(layer_inner) 62 | for i,con in enumerate(self.convs): 63 | layer_inner = F.dropout(layer_inner, self.dropout, training=self.training) 64 | layer_inner = self.act_fn(con(layer_inner,adj,_layers[0],self.lamda,self.alpha,i+1)) 65 | layer_inner = F.dropout(layer_inner, self.dropout, training=self.training) 66 | layer_inner = self.fcs[-1](layer_inner) 67 | return F.log_softmax(layer_inner, dim=1) 68 | 69 | class GCNIIppi(nn.Module): 70 | def __init__(self, nfeat, nlayers,nhidden, nclass, dropout, lamda, alpha,variant): 71 | super(GCNIIppi, self).__init__() 72 | self.convs = nn.ModuleList() 73 | for _ in range(nlayers): 74 | self.convs.append(GraphConvolution(nhidden, nhidden,variant=variant,residual=True)) 75 | self.fcs = nn.ModuleList() 76 | self.fcs.append(nn.Linear(nfeat, nhidden)) 77 | self.fcs.append(nn.Linear(nhidden, nclass)) 78 | self.act_fn = nn.ReLU() 79 | self.sig = nn.Sigmoid() 80 | self.dropout = dropout 81 | self.alpha = alpha 82 | self.lamda = lamda 83 | 84 | def forward(self, x, adj): 85 | _layers = [] 86 | x = F.dropout(x, self.dropout, training=self.training) 87 | layer_inner = self.act_fn(self.fcs[0](x)) 88 | _layers.append(layer_inner) 89 | for i,con in enumerate(self.convs): 90 | layer_inner = F.dropout(layer_inner, self.dropout, training=self.training) 91 | layer_inner = self.act_fn(con(layer_inner,adj,_layers[0],self.lamda,self.alpha,i+1)) 92 | layer_inner = F.dropout(layer_inner, self.dropout, training=self.training) 93 | layer_inner = self.sig(self.fcs[-1](layer_inner)) 94 | return layer_inner 95 | 96 | 97 | if __name__ == '__main__': 98 | pass 99 | 100 | 101 | 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /new_data/cornell/out1_graph_edges.txt: -------------------------------------------------------------------------------- 1 | node_id node_id 2 | 118 155 3 | 108 159 4 | 182 57 5 | 7 121 6 | 7 110 7 | 169 57 8 | 169 39 9 | 148 99 10 | 148 42 11 | 148 154 12 | 148 167 13 | 148 178 14 | 148 112 15 | 148 82 16 | 148 56 17 | 148 140 18 | 148 1 19 | 15 82 20 | 15 140 21 | 99 82 22 | 99 1 23 | 54 72 24 | 102 123 25 | 102 16 26 | 124 85 27 | 124 180 28 | 42 169 29 | 42 36 30 | 42 58 31 | 42 109 32 | 42 136 33 | 42 151 34 | 42 103 35 | 42 3 36 | 42 22 37 | 42 75 38 | 42 97 39 | 42 9 40 | 42 166 41 | 42 171 42 | 42 115 43 | 42 130 44 | 42 11 45 | 42 150 46 | 42 59 47 | 42 70 48 | 42 64 49 | 42 30 50 | 42 175 51 | 42 24 52 | 42 52 53 | 42 165 54 | 42 167 55 | 42 181 56 | 42 40 57 | 42 178 58 | 42 112 59 | 42 81 60 | 42 73 61 | 42 14 62 | 42 179 63 | 42 50 64 | 42 62 65 | 42 138 66 | 42 5 67 | 42 27 68 | 42 72 69 | 42 66 70 | 42 45 71 | 42 68 72 | 42 61 73 | 42 16 74 | 42 18 75 | 42 83 76 | 42 33 77 | 42 60 78 | 42 133 79 | 42 49 80 | 42 85 81 | 42 56 82 | 42 29 83 | 42 116 84 | 42 67 85 | 42 98 86 | 42 95 87 | 42 21 88 | 42 155 89 | 42 48 90 | 42 86 91 | 42 26 92 | 42 157 93 | 42 6 94 | 42 8 95 | 42 158 96 | 42 122 97 | 42 63 98 | 42 12 99 | 42 71 100 | 42 156 101 | 42 2 102 | 42 141 103 | 42 137 104 | 42 161 105 | 42 143 106 | 42 144 107 | 42 128 108 | 42 23 109 | 42 87 110 | 42 46 111 | 42 159 112 | 42 145 113 | 42 113 114 | 42 0 115 | 42 139 116 | 42 19 117 | 42 76 118 | 42 80 119 | 42 96 120 | 42 168 121 | 107 55 122 | 107 152 123 | 107 40 124 | 107 25 125 | 107 43 126 | 69 146 127 | 69 43 128 | 109 40 129 | 4 55 130 | 4 152 131 | 4 40 132 | 4 25 133 | 4 72 134 | 4 8 135 | 4 156 136 | 41 91 137 | 41 135 138 | 78 55 139 | 78 152 140 | 78 91 141 | 78 25 142 | 78 95 143 | 78 146 144 | 176 72 145 | 162 135 146 | 74 10 147 | 51 52 148 | 51 10 149 | 151 43 150 | 31 24 151 | 31 34 152 | 31 123 153 | 31 18 154 | 31 49 155 | 31 127 156 | 31 125 157 | 31 139 158 | 105 77 159 | 170 127 160 | 103 134 161 | 53 116 162 | 173 45 163 | 129 49 164 | 129 110 165 | 174 34 166 | 174 18 167 | 174 139 168 | 106 114 169 | 106 18 170 | 106 37 171 | 106 156 172 | 106 43 173 | 3 163 174 | 22 52 175 | 75 141 176 | 11 6 177 | 77 124 178 | 77 177 179 | 77 66 180 | 77 144 181 | 93 178 182 | 93 33 183 | 30 111 184 | 30 25 185 | 177 25 186 | 55 25 187 | 24 111 188 | 152 25 189 | 167 60 190 | 153 131 191 | 153 104 192 | 82 1 193 | 81 155 194 | 100 122 195 | 100 63 196 | 138 131 197 | 138 94 198 | 138 104 199 | 117 139 200 | 5 37 201 | 72 25 202 | 66 31 203 | 66 89 204 | 45 41 205 | 45 173 206 | 45 178 207 | 61 37 208 | 123 111 209 | 33 178 210 | 60 167 211 | 32 37 212 | 29 29 213 | 116 178 214 | 116 91 215 | 155 118 216 | 155 108 217 | 155 81 218 | 157 160 219 | 160 157 220 | 132 6 221 | 6 145 222 | 65 8 223 | 122 63 224 | 37 106 225 | 37 5 226 | 37 61 227 | 71 124 228 | 71 154 229 | 71 133 230 | 71 85 231 | 71 180 232 | 71 35 233 | 71 120 234 | 38 164 235 | 38 113 236 | 141 169 237 | 143 6 238 | 143 145 239 | 144 52 240 | 88 23 241 | 119 23 242 | 23 88 243 | 10 124 244 | 10 52 245 | 10 138 246 | 10 131 247 | 10 104 248 | 84 159 249 | 159 108 250 | 159 84 251 | 145 6 252 | 17 76 253 | 131 138 254 | 131 10 255 | 131 94 256 | 131 104 257 | 149 167 258 | 149 61 259 | 149 60 260 | 120 101 261 | 1 90 262 | 79 147 263 | 147 178 264 | 147 28 265 | 147 126 266 | 147 33 267 | 94 174 268 | 94 138 269 | 104 138 270 | 104 10 271 | 104 94 272 | 142 52 273 | 142 138 274 | 142 180 275 | 142 10 276 | 142 131 277 | 172 44 278 | 172 144 279 | 13 155 280 | 13 13 281 | 47 47 282 | 47 89 283 | 47 20 284 | 89 111 285 | 89 92 286 | 89 121 287 | 89 49 288 | 89 156 289 | 89 110 290 | 89 125 291 | 89 19 292 | 89 20 293 | 20 111 294 | 20 121 295 | 20 49 296 | 20 156 297 | 20 110 298 | 20 125 299 | 20 89 300 | -------------------------------------------------------------------------------- /new_data/texas/out1_graph_edges.txt: -------------------------------------------------------------------------------- 1 | node_id node_id 2 | 56 84 3 | 56 39 4 | 56 9 5 | 56 77 6 | 56 89 7 | 56 61 8 | 56 125 9 | 56 94 10 | 56 64 11 | 56 52 12 | 56 27 13 | 56 112 14 | 56 21 15 | 56 154 16 | 56 31 17 | 56 109 18 | 56 57 19 | 56 59 20 | 56 22 21 | 56 90 22 | 56 68 23 | 56 91 24 | 56 63 25 | 56 85 26 | 56 116 27 | 56 32 28 | 56 143 29 | 56 181 30 | 56 54 31 | 56 69 32 | 56 3 33 | 56 139 34 | 56 104 35 | 56 128 36 | 56 137 37 | 56 172 38 | 56 93 39 | 56 179 40 | 56 132 41 | 56 134 42 | 56 178 43 | 56 144 44 | 56 74 45 | 56 46 46 | 56 11 47 | 56 80 48 | 56 124 49 | 56 135 50 | 56 97 51 | 56 98 52 | 56 79 53 | 56 23 54 | 56 118 55 | 56 167 56 | 56 131 57 | 56 153 58 | 56 33 59 | 56 149 60 | 56 161 61 | 56 127 62 | 56 34 63 | 56 136 64 | 56 169 65 | 56 150 66 | 56 62 67 | 56 26 68 | 56 82 69 | 56 12 70 | 56 47 71 | 56 166 72 | 56 171 73 | 56 6 74 | 56 17 75 | 56 53 76 | 56 117 77 | 56 87 78 | 56 146 79 | 56 49 80 | 56 159 81 | 56 119 82 | 56 170 83 | 56 38 84 | 56 55 85 | 56 30 86 | 56 165 87 | 56 103 88 | 56 155 89 | 56 110 90 | 56 16 91 | 56 44 92 | 56 75 93 | 56 41 94 | 56 29 95 | 56 35 96 | 56 65 97 | 56 19 98 | 56 142 99 | 56 129 100 | 56 37 101 | 56 24 102 | 56 43 103 | 56 5 104 | 56 81 105 | 56 147 106 | 84 31 107 | 84 23 108 | 84 153 109 | 84 127 110 | 84 34 111 | 84 62 112 | 84 47 113 | 84 147 114 | 39 140 115 | 106 9 116 | 89 151 117 | 61 84 118 | 114 49 119 | 83 39 120 | 83 140 121 | 83 37 122 | 125 54 123 | 64 82 124 | 10 108 125 | 182 29 126 | 140 39 127 | 140 83 128 | 140 90 129 | 45 45 130 | 45 108 131 | 108 45 132 | 108 11 133 | 108 72 134 | 73 73 135 | 73 158 136 | 73 66 137 | 158 73 138 | 107 108 139 | 126 18 140 | 126 16 141 | 126 29 142 | 57 22 143 | 57 67 144 | 57 170 145 | 57 165 146 | 57 110 147 | 57 15 148 | 57 65 149 | 59 159 150 | 59 16 151 | 120 140 152 | 120 156 153 | 156 156 154 | 99 94 155 | 99 132 156 | 99 79 157 | 90 140 158 | 90 90 159 | 63 58 160 | 175 175 161 | 85 16 162 | 111 85 163 | 0 58 164 | 0 121 165 | 141 116 166 | 141 48 167 | 116 76 168 | 54 125 169 | 139 18 170 | 18 126 171 | 172 113 172 | 1 80 173 | 148 148 174 | 148 146 175 | 148 159 176 | 134 134 177 | 144 82 178 | 105 144 179 | 180 84 180 | 180 180 181 | 180 47 182 | 180 66 183 | 60 21 184 | 60 16 185 | 36 21 186 | 36 60 187 | 74 22 188 | 74 48 189 | 46 95 190 | 4 164 191 | 4 66 192 | 4 146 193 | 164 146 194 | 11 94 195 | 11 108 196 | 80 66 197 | 176 80 198 | 28 80 199 | 28 146 200 | 122 167 201 | 163 163 202 | 163 58 203 | 79 82 204 | 23 127 205 | 23 147 206 | 151 89 207 | 151 66 208 | 151 152 209 | 133 64 210 | 133 178 211 | 133 82 212 | 133 16 213 | 173 84 214 | 173 96 215 | 173 175 216 | 173 131 217 | 173 55 218 | 173 145 219 | 173 8 220 | 131 84 221 | 131 138 222 | 131 168 223 | 131 100 224 | 131 66 225 | 168 131 226 | 100 131 227 | 51 116 228 | 161 116 229 | 2 8 230 | 127 84 231 | 127 31 232 | 127 23 233 | 127 153 234 | 127 62 235 | 127 171 236 | 127 55 237 | 127 129 238 | 34 84 239 | 34 34 240 | 34 66 241 | 42 93 242 | 42 34 243 | 7 14 244 | 7 34 245 | 78 34 246 | 78 146 247 | 50 68 248 | 50 34 249 | 50 150 250 | 58 163 251 | 58 119 252 | 58 13 253 | 58 102 254 | 58 88 255 | 67 67 256 | 177 84 257 | 177 156 258 | 177 167 259 | 82 64 260 | 82 144 261 | 82 79 262 | 82 133 263 | 47 84 264 | 47 180 265 | 95 157 266 | 95 46 267 | 95 95 268 | 95 66 269 | 95 76 270 | 66 86 271 | 72 108 272 | 171 84 273 | 171 66 274 | 171 113 275 | 171 6 276 | 171 129 277 | 17 29 278 | 86 86 279 | 53 71 280 | 117 146 281 | 87 116 282 | 159 59 283 | 159 150 284 | 159 44 285 | 119 58 286 | 55 116 287 | 30 146 288 | 30 159 289 | 25 84 290 | 25 167 291 | 145 168 292 | 160 116 293 | 40 24 294 | 13 58 295 | 13 13 296 | 123 16 297 | 44 159 298 | 70 147 299 | 15 22 300 | 15 165 301 | 15 16 302 | 15 15 303 | 15 65 304 | 92 15 305 | 20 115 306 | 20 16 307 | 20 15 308 | 20 5 309 | 174 15 310 | 75 116 311 | 41 84 312 | 41 104 313 | 41 118 314 | 41 66 315 | 162 66 316 | 162 29 317 | 101 5 318 | 29 97 319 | 29 17 320 | 29 162 321 | 102 58 322 | 102 66 323 | 102 102 324 | 88 102 325 | 130 24 326 | 81 58 327 | -------------------------------------------------------------------------------- /new_data/wisconsin/out1_graph_edges.txt: -------------------------------------------------------------------------------- 1 | node_id node_id 2 | 63 78 3 | 63 92 4 | 27 63 5 | 27 111 6 | 110 12 7 | 98 63 8 | 98 27 9 | 98 244 10 | 98 147 11 | 98 86 12 | 98 163 13 | 98 132 14 | 98 175 15 | 98 19 16 | 98 17 17 | 98 190 18 | 98 102 19 | 98 114 20 | 98 170 21 | 98 243 22 | 98 6 23 | 98 57 24 | 98 67 25 | 98 211 26 | 98 29 27 | 98 33 28 | 98 144 29 | 98 109 30 | 98 96 31 | 98 204 32 | 98 52 33 | 98 59 34 | 98 60 35 | 98 4 36 | 98 131 37 | 98 174 38 | 98 113 39 | 98 82 40 | 98 25 41 | 98 54 42 | 98 138 43 | 98 213 44 | 98 41 45 | 98 177 46 | 98 171 47 | 98 172 48 | 98 125 49 | 98 8 50 | 98 123 51 | 98 145 52 | 98 111 53 | 98 139 54 | 98 137 55 | 98 76 56 | 98 45 57 | 98 238 58 | 98 15 59 | 98 153 60 | 98 32 61 | 98 235 62 | 98 230 63 | 98 237 64 | 98 192 65 | 98 168 66 | 98 173 67 | 98 28 68 | 98 104 69 | 98 124 70 | 98 135 71 | 98 2 72 | 98 68 73 | 98 205 74 | 98 169 75 | 98 229 76 | 98 88 77 | 98 16 78 | 98 157 79 | 98 1 80 | 98 227 81 | 98 154 82 | 98 10 83 | 98 184 84 | 98 22 85 | 98 75 86 | 98 220 87 | 98 216 88 | 98 12 89 | 98 80 90 | 98 146 91 | 98 95 92 | 98 209 93 | 98 94 94 | 98 133 95 | 98 187 96 | 98 55 97 | 98 129 98 | 98 78 99 | 98 189 100 | 98 93 101 | 98 92 102 | 98 182 103 | 98 14 104 | 98 11 105 | 98 47 106 | 98 193 107 | 98 126 108 | 98 37 109 | 98 40 110 | 98 99 111 | 98 130 112 | 98 18 113 | 98 155 114 | 98 35 115 | 98 203 116 | 98 134 117 | 98 56 118 | 98 69 119 | 98 23 120 | 98 167 121 | 98 202 122 | 98 105 123 | 98 183 124 | 98 44 125 | 98 77 126 | 98 13 127 | 98 58 128 | 98 218 129 | 64 57 130 | 64 234 131 | 64 12 132 | 212 75 133 | 231 185 134 | 231 143 135 | 231 75 136 | 198 231 137 | 198 147 138 | 186 147 139 | 186 67 140 | 186 131 141 | 186 160 142 | 186 238 143 | 186 15 144 | 244 138 145 | 244 187 146 | 147 198 147 | 147 67 148 | 147 160 149 | 147 238 150 | 147 151 151 | 147 184 152 | 86 204 153 | 86 52 154 | 103 29 155 | 103 41 156 | 103 51 157 | 163 93 158 | 175 36 159 | 188 128 160 | 188 178 161 | 188 173 162 | 128 188 163 | 128 207 164 | 128 178 165 | 128 173 166 | 207 208 167 | 207 178 168 | 207 173 169 | 208 178 170 | 208 173 171 | 190 204 172 | 190 52 173 | 176 53 174 | 102 85 175 | 102 31 176 | 48 221 177 | 48 211 178 | 114 204 179 | 114 52 180 | 170 243 181 | 170 6 182 | 170 54 183 | 170 35 184 | 243 170 185 | 6 170 186 | 57 204 187 | 57 52 188 | 211 97 189 | 211 115 190 | 211 5 191 | 29 41 192 | 29 126 193 | 233 142 194 | 144 144 195 | 144 12 196 | 108 144 197 | 118 198 198 | 118 37 199 | 96 217 200 | 96 112 201 | 20 170 202 | 20 243 203 | 20 149 204 | 20 35 205 | 204 190 206 | 204 57 207 | 204 97 208 | 204 115 209 | 204 49 210 | 204 66 211 | 204 5 212 | 97 211 213 | 97 45 214 | 97 168 215 | 0 20 216 | 0 28 217 | 0 104 218 | 0 99 219 | 0 200 220 | 7 0 221 | 7 242 222 | 242 170 223 | 242 6 224 | 242 233 225 | 242 109 226 | 242 7 227 | 242 150 228 | 242 194 229 | 242 215 230 | 242 171 231 | 242 38 232 | 242 149 233 | 242 24 234 | 242 249 235 | 242 28 236 | 242 205 237 | 242 148 238 | 242 21 239 | 242 74 240 | 242 167 241 | 242 202 242 | 217 96 243 | 217 217 244 | 112 112 245 | 4 195 246 | 158 229 247 | 199 84 248 | 199 8 249 | 199 145 250 | 199 32 251 | 53 33 252 | 53 216 253 | 53 195 254 | 89 211 255 | 89 216 256 | 89 195 257 | 89 202 258 | 152 57 259 | 152 211 260 | 152 216 261 | 152 12 262 | 152 105 263 | 34 132 264 | 34 104 265 | 91 171 266 | 91 123 267 | 91 145 268 | 178 41 269 | 178 173 270 | 178 122 271 | 178 180 272 | 241 29 273 | 241 41 274 | 241 51 275 | 113 25 276 | 82 25 277 | 25 113 278 | 25 82 279 | 228 25 280 | 156 152 281 | 156 143 282 | 156 172 283 | 156 225 284 | 156 183 285 | 160 67 286 | 160 61 287 | 160 232 288 | 116 20 289 | 87 54 290 | 87 229 291 | 127 54 292 | 54 170 293 | 54 2 294 | 54 159 295 | 54 119 296 | 54 46 297 | 54 165 298 | 54 129 299 | 150 194 300 | 194 150 301 | 138 100 302 | 106 93 303 | 41 29 304 | 41 178 305 | 245 32 306 | 245 168 307 | 245 104 308 | 240 104 309 | 51 241 310 | 51 39 311 | 70 204 312 | 70 52 313 | 39 51 314 | 215 171 315 | 171 215 316 | 171 171 317 | 172 156 318 | 38 145 319 | 145 38 320 | 224 137 321 | 83 20 322 | 83 90 323 | 90 83 324 | 45 97 325 | 45 115 326 | 45 5 327 | 71 204 328 | 71 52 329 | 141 97 330 | 141 115 331 | 141 5 332 | 153 153 333 | 196 32 334 | 32 97 335 | 32 115 336 | 32 5 337 | 225 156 338 | 49 204 339 | 49 52 340 | 162 51 341 | 192 73 342 | 192 112 343 | 192 34 344 | 192 41 345 | 192 125 346 | 192 192 347 | 192 173 348 | 192 140 349 | 192 122 350 | 192 31 351 | 81 97 352 | 81 115 353 | 81 5 354 | 223 89 355 | 223 202 356 | 168 97 357 | 168 115 358 | 168 5 359 | 201 207 360 | 201 8 361 | 26 201 362 | 173 65 363 | 173 26 364 | 173 226 365 | 173 182 366 | 173 122 367 | 149 62 368 | 24 62 369 | 164 37 370 | 166 191 371 | 249 117 372 | 117 249 373 | 117 117 374 | 28 28 375 | 28 104 376 | 2 54 377 | 68 126 378 | 205 169 379 | 169 205 380 | 169 169 381 | 79 132 382 | 79 29 383 | 79 213 384 | 79 68 385 | 79 79 386 | 79 193 387 | 79 126 388 | 79 69 389 | 148 229 390 | 229 148 391 | 236 97 392 | 236 115 393 | 236 5 394 | 197 84 395 | 197 232 396 | 197 209 397 | 197 37 398 | 197 13 399 | 151 37 400 | 121 42 401 | 121 161 402 | 121 120 403 | 50 230 404 | 50 135 405 | 50 85 406 | 50 72 407 | 50 44 408 | 50 31 409 | 120 121 410 | 120 161 411 | 120 157 412 | 120 120 413 | 154 209 414 | 184 156 415 | 184 75 416 | 21 22 417 | 22 21 418 | 22 22 419 | 210 225 420 | 210 183 421 | 179 158 422 | 75 199 423 | 75 156 424 | 75 172 425 | 75 153 426 | 75 184 427 | 75 183 428 | 75 77 429 | 12 12 430 | 232 209 431 | 66 3 432 | 3 204 433 | 3 52 434 | 146 136 435 | 222 20 436 | 5 32 437 | 101 97 438 | 101 115 439 | 101 5 440 | 140 140 441 | 226 41 442 | 119 129 443 | 46 54 444 | 46 119 445 | 46 129 446 | 165 159 447 | 165 129 448 | 129 54 449 | 129 159 450 | 129 119 451 | 129 46 452 | 129 165 453 | 78 87 454 | 189 171 455 | 189 93 456 | 92 163 457 | 92 170 458 | 92 161 459 | 92 93 460 | 11 87 461 | 11 127 462 | 47 11 463 | 126 29 464 | 126 68 465 | 126 69 466 | 214 37 467 | 37 191 468 | 37 214 469 | 37 37 470 | 122 178 471 | 122 41 472 | 130 139 473 | 130 18 474 | 248 132 475 | 181 155 476 | 155 204 477 | 155 52 478 | 155 181 479 | 246 97 480 | 246 115 481 | 246 5 482 | 35 20 483 | 250 35 484 | 200 247 485 | 180 178 486 | 30 204 487 | 30 52 488 | 74 203 489 | 203 74 490 | 203 203 491 | 69 29 492 | 69 41 493 | 69 126 494 | 167 202 495 | 202 167 496 | 43 217 497 | 183 156 498 | 44 178 499 | 44 241 500 | 44 41 501 | 44 9 502 | 44 173 503 | 44 140 504 | 44 182 505 | 44 122 506 | 44 31 507 | 107 217 508 | 107 124 509 | 107 10 510 | 107 183 511 | 239 167 512 | 206 33 513 | 206 171 514 | 206 201 515 | 58 12 516 | 219 63 517 | -------------------------------------------------------------------------------- /ppi.py: -------------------------------------------------------------------------------- 1 | from __future__ import division 2 | from __future__ import print_function 3 | import time 4 | import random 5 | import argparse 6 | import numpy as np 7 | import torch 8 | import torch.nn.functional as F 9 | import torch.optim as optim 10 | import torch.utils.data as Data 11 | from utils import * 12 | from model import * 13 | import torch.nn as nn 14 | from sklearn.metrics import f1_score 15 | import uuid 16 | 17 | # Training settings 18 | parser = argparse.ArgumentParser() 19 | parser.add_argument('--seed', type=int, default=42, help='Random seed.') 20 | parser.add_argument('--epochs', type=int, default=8000, help='Number of epochs to train.') 21 | parser.add_argument('--lr', type=float, default=0.001, help='Initial learning rate.') 22 | parser.add_argument('--wd', type=float, default=0, help='Weight decay (L2 loss on parameters).') 23 | parser.add_argument('--layer', type=int, default=9, help='Number of hidden layers.') 24 | parser.add_argument('--hidden', type=int, default=2048, help='Number of hidden layers.') 25 | parser.add_argument('--dropout', type=float, default=0.2, help='Dropout rate (1 - keep probability).') 26 | parser.add_argument('--patience', type=int, default=2000, help='Patience') 27 | parser.add_argument('--data', default='ppi', help='dateset') 28 | parser.add_argument('--dev', type=int, default=0, help='device id') 29 | parser.add_argument('--alpha', type=float, default=0.5, help='alpha_l') 30 | parser.add_argument('--lamda', type=float, default=1, help='lamda.') 31 | parser.add_argument('--variant', action='store_true', default=False, help='GCN* model.') 32 | parser.add_argument('--test', action='store_true', default=False, help='evaluation on test set.') 33 | args = parser.parse_args() 34 | random.seed(args.seed) 35 | np.random.seed(args.seed) 36 | torch.manual_seed(args.seed) 37 | torch.cuda.manual_seed(args.seed) 38 | 39 | cudaid = "cuda:"+str(args.dev) 40 | device = torch.device(cudaid) 41 | 42 | # Load data 43 | train_adj,val_adj,test_adj,train_feat,val_feat,test_feat,train_labels,val_labels, test_labels,train_nodes, val_nodes, test_nodes = load_ppi() 44 | 45 | checkpt_file = 'pretrained/'+uuid.uuid4().hex+'.pt' 46 | print(cudaid,checkpt_file) 47 | 48 | model = GCNIIppi(nfeat=train_feat[0].shape[1], 49 | nlayers=args.layer, 50 | nhidden=args.hidden, 51 | nclass=train_labels[0].shape[1], 52 | dropout=args.dropout, 53 | lamda = args.lamda, 54 | alpha=args.alpha, 55 | variant=args.variant).to(device) 56 | 57 | optimizer = optim.Adam(model.parameters(), lr=args.lr, 58 | weight_decay=args.wd) 59 | 60 | 61 | loss_fcn = torch.nn.BCELoss() 62 | # adapted from DGL 63 | def evaluate(feats, model, idx ,subgraph, labels, loss_fcn): 64 | model.eval() 65 | with torch.no_grad(): 66 | output = model(feats,subgraph) 67 | loss_data = loss_fcn(output[:idx], labels[:idx].float()) 68 | predict = np.where(output[:idx].data.cpu().numpy() > 0.5, 1, 0) 69 | score = f1_score(labels[:idx].data.cpu().numpy(),predict, average='micro') 70 | return score, loss_data.item() 71 | 72 | 73 | idx = torch.LongTensor(range(20)) 74 | loader = Data.DataLoader(dataset=idx,batch_size=1,shuffle=True,num_workers=0) 75 | 76 | def train(): 77 | model.train() 78 | loss_tra = 0 79 | acc_tra = 0 80 | for step,batch in enumerate(loader): 81 | batch_adj = train_adj[batch[0]].to(device) 82 | batch_feature = train_feat[batch[0]].to(device) 83 | batch_label = train_labels[batch[0]].to(device) 84 | optimizer.zero_grad() 85 | output = model(batch_feature,batch_adj) 86 | loss_train = loss_fcn(output[:train_nodes[batch]], batch_label[:train_nodes[batch]]) 87 | loss_train.backward() 88 | optimizer.step() 89 | loss_tra+=loss_train.item() 90 | loss_tra/=20 91 | acc_tra/=20 92 | return loss_tra,acc_tra 93 | 94 | def validation(): 95 | loss_val = 0 96 | acc_val = 0 97 | for batch in range(2): 98 | batch_adj = val_adj[batch].to(device) 99 | batch_feature = val_feat[batch].to(device) 100 | batch_label = val_labels[batch].to(device) 101 | score, val_loss = evaluate(batch_feature, model, val_nodes[batch] ,batch_adj, batch_label, loss_fcn) 102 | loss_val+=val_loss 103 | acc_val += score 104 | loss_val/=2 105 | acc_val/=2 106 | return loss_val,acc_val 107 | 108 | def test(): 109 | model.load_state_dict(torch.load(checkpt_file)) 110 | loss_test = 0 111 | acc_test = 0 112 | for batch in range(2): 113 | batch_adj = test_adj[batch].to(device) 114 | batch_feature = test_feat[batch].to(device) 115 | batch_label = test_labels[batch].to(device) 116 | score,loss =evaluate(batch_feature, model,test_nodes[batch], batch_adj, batch_label, loss_fcn) 117 | loss_test += loss 118 | acc_test += score 119 | acc_test/=2 120 | loss_test/=2 121 | return loss_test,acc_test 122 | 123 | t_total = time.time() 124 | bad_counter = 0 125 | acc = 0 126 | best_epoch = 0 127 | for epoch in range(args.epochs): 128 | loss_tra,acc_tra = train() 129 | loss_val,acc_val = validation() 130 | 131 | if(epoch+1)%1 == 0: 132 | print('Epoch:{:04d}'.format(epoch+1), 133 | 'train', 134 | 'loss:{:.3f}'.format(loss_tra), 135 | '| val', 136 | 'loss:{:.3f}'.format(loss_val), 137 | 'f1:{:.3f}'.format(acc_val*100)) 138 | 139 | if acc_val > acc: 140 | acc = acc_val 141 | best_epoch = epoch 142 | torch.save(model.state_dict(), checkpt_file) 143 | bad_counter = 0 144 | else: 145 | bad_counter += 1 146 | 147 | if bad_counter == args.patience: 148 | break 149 | 150 | if args.test: 151 | acc = test()[1] 152 | 153 | print("Train cost: {:.4f}s".format(time.time() - t_total)) 154 | print('Load {}th epoch'.format(best_epoch)) 155 | print("Test" if args.test else "Val","f1.:{:.2f}".format(acc*100)) 156 | 157 | 158 | 159 | 160 | 161 | -------------------------------------------------------------------------------- /ppi.sh: -------------------------------------------------------------------------------- 1 | python -u ppi.py --test 2 | python -u ppi.py --variant --test -------------------------------------------------------------------------------- /pretrained/README.md: -------------------------------------------------------------------------------- 1 | Pretrained model 2 | -------------------------------------------------------------------------------- /process.py: -------------------------------------------------------------------------------- 1 | import os 2 | import re 3 | import networkx as nx 4 | import numpy as np 5 | import scipy.sparse as sp 6 | import torch as th 7 | from sklearn.model_selection import ShuffleSplit 8 | from utils import sys_normalized_adjacency,sparse_mx_to_torch_sparse_tensor 9 | import pickle as pkl 10 | import sys 11 | import networkx as nx 12 | import numpy as np 13 | import scipy.sparse as sp 14 | 15 | #adapted from geom-gcn 16 | 17 | def parse_index_file(filename): 18 | """Parse index file.""" 19 | index = [] 20 | for line in open(filename): 21 | index.append(int(line.strip())) 22 | return index 23 | 24 | 25 | def sample_mask(idx, l): 26 | """Create mask.""" 27 | mask = np.zeros(l) 28 | mask[idx] = 1 29 | return np.array(mask, dtype=np.bool) 30 | 31 | 32 | def full_load_citation(dataset_str): 33 | names = ['x', 'y', 'tx', 'ty', 'allx', 'ally', 'graph'] 34 | objects = [] 35 | for i in range(len(names)): 36 | with open("data/ind.{}.{}".format(dataset_str, names[i]), 'rb') as f: 37 | if sys.version_info > (3, 0): 38 | objects.append(pkl.load(f, encoding='latin1')) 39 | else: 40 | objects.append(pkl.load(f)) 41 | 42 | x, y, tx, ty, allx, ally, graph = tuple(objects) 43 | test_idx_reorder = parse_index_file("data/ind.{}.test.index".format(dataset_str)) 44 | test_idx_range = np.sort(test_idx_reorder) 45 | 46 | if dataset_str == 'citeseer': 47 | # Fix citeseer dataset (there are some isolated nodes in the graph) 48 | # Find isolated nodes, add them as zero-vecs into the right position 49 | test_idx_range_full = range(min(test_idx_reorder), max(test_idx_reorder)+1) 50 | tx_extended = sp.lil_matrix((len(test_idx_range_full), x.shape[1])) 51 | tx_extended[test_idx_range-min(test_idx_range), :] = tx 52 | tx = tx_extended 53 | ty_extended = np.zeros((len(test_idx_range_full), y.shape[1])) 54 | ty_extended[test_idx_range-min(test_idx_range), :] = ty 55 | ty = ty_extended 56 | 57 | features = sp.vstack((allx, tx)).tolil() 58 | features[test_idx_reorder, :] = features[test_idx_range, :] 59 | adj = nx.adjacency_matrix(nx.from_dict_of_lists(graph)) 60 | 61 | labels = np.vstack((ally, ty)) 62 | labels[test_idx_reorder, :] = labels[test_idx_range, :] 63 | 64 | idx_test = test_idx_range.tolist() 65 | idx_train = range(len(y)) 66 | idx_val = range(len(y), len(y)+500) 67 | 68 | train_mask = sample_mask(idx_train, labels.shape[0]) 69 | val_mask = sample_mask(idx_val, labels.shape[0]) 70 | test_mask = sample_mask(idx_test, labels.shape[0]) 71 | 72 | y_train = np.zeros(labels.shape) 73 | y_val = np.zeros(labels.shape) 74 | y_test = np.zeros(labels.shape) 75 | y_train[train_mask, :] = labels[train_mask, :] 76 | y_val[val_mask, :] = labels[val_mask, :] 77 | y_test[test_mask, :] = labels[test_mask, :] 78 | 79 | return adj, features, labels, train_mask, val_mask, test_mask 80 | 81 | 82 | def preprocess_features(features): 83 | """Row-normalize feature matrix and convert to tuple representation""" 84 | rowsum = np.array(features.sum(1)) 85 | rowsum = (rowsum==0)*1+rowsum 86 | r_inv = np.power(rowsum, -1).flatten() 87 | r_inv[np.isinf(r_inv)] = 0. 88 | r_mat_inv = sp.diags(r_inv) 89 | features = r_mat_inv.dot(features) 90 | return features 91 | 92 | def full_load_data(dataset_name, splits_file_path=None): 93 | if dataset_name in {'cora', 'citeseer', 'pubmed'}: 94 | adj, features, labels, _, _, _ = full_load_citation(dataset_name) 95 | labels = np.argmax(labels, axis=-1) 96 | features = features.todense() 97 | G = nx.DiGraph(adj) 98 | else: 99 | graph_adjacency_list_file_path = os.path.join('new_data', dataset_name, 'out1_graph_edges.txt') 100 | graph_node_features_and_labels_file_path = os.path.join('new_data', dataset_name, 101 | 'out1_node_feature_label.txt') 102 | 103 | G = nx.DiGraph() 104 | graph_node_features_dict = {} 105 | graph_labels_dict = {} 106 | 107 | 108 | with open(graph_node_features_and_labels_file_path) as graph_node_features_and_labels_file: 109 | graph_node_features_and_labels_file.readline() 110 | for line in graph_node_features_and_labels_file: 111 | line = line.rstrip().split('\t') 112 | assert (len(line) == 3) 113 | assert (int(line[0]) not in graph_node_features_dict and int(line[0]) not in graph_labels_dict) 114 | graph_node_features_dict[int(line[0])] = np.array(line[1].split(','), dtype=np.uint8) 115 | graph_labels_dict[int(line[0])] = int(line[2]) 116 | 117 | with open(graph_adjacency_list_file_path) as graph_adjacency_list_file: 118 | graph_adjacency_list_file.readline() 119 | for line in graph_adjacency_list_file: 120 | line = line.rstrip().split('\t') 121 | assert (len(line) == 2) 122 | if int(line[0]) not in G: 123 | G.add_node(int(line[0]), features=graph_node_features_dict[int(line[0])], 124 | label=graph_labels_dict[int(line[0])]) 125 | if int(line[1]) not in G: 126 | G.add_node(int(line[1]), features=graph_node_features_dict[int(line[1])], 127 | label=graph_labels_dict[int(line[1])]) 128 | G.add_edge(int(line[0]), int(line[1])) 129 | 130 | adj = nx.adjacency_matrix(G, sorted(G.nodes())) 131 | features = np.array( 132 | [features for _, features in sorted(G.nodes(data='features'), key=lambda x: x[0])]) 133 | labels = np.array( 134 | [label for _, label in sorted(G.nodes(data='label'), key=lambda x: x[0])]) 135 | features = preprocess_features(features) 136 | 137 | g = adj 138 | 139 | with np.load(splits_file_path) as splits_file: 140 | train_mask = splits_file['train_mask'] 141 | val_mask = splits_file['val_mask'] 142 | test_mask = splits_file['test_mask'] 143 | 144 | num_features = features.shape[1] 145 | num_labels = len(np.unique(labels)) 146 | assert (np.array_equal(np.unique(labels), np.arange(len(np.unique(labels))))) 147 | 148 | features = th.FloatTensor(features) 149 | labels = th.LongTensor(labels) 150 | train_mask = th.BoolTensor(train_mask) 151 | val_mask = th.BoolTensor(val_mask) 152 | test_mask = th.BoolTensor(test_mask) 153 | 154 | g = sys_normalized_adjacency(g) 155 | g = sparse_mx_to_torch_sparse_tensor(g) 156 | 157 | return g, features, labels, train_mask, val_mask, test_mask, num_features, num_labels 158 | -------------------------------------------------------------------------------- /semi.sh: -------------------------------------------------------------------------------- 1 | python -u train.py --data cora --layer 64 --test 2 | python -u train.py --data cora --layer 64 --variant --test 3 | python -u train.py --data citeseer --layer 32 --hidden 256 --lamda 0.6 --dropout 0.7 --test 4 | python -u train.py --data citeseer --layer 32 --hidden 256 --lamda 0.6 --dropout 0.7 --variant --test 5 | python -u train.py --data pubmed --layer 16 --hidden 256 --lamda 0.4 --dropout 0.5 --wd1 5e-4 --test 6 | python -u train.py --data pubmed --layer 16 --hidden 256 --lamda 0.4 --dropout 0.5 --wd1 5e-4 --variant --test -------------------------------------------------------------------------------- /splits/chameleon_split_0.6_0.2_0.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/chameleon_split_0.6_0.2_0.npz -------------------------------------------------------------------------------- /splits/chameleon_split_0.6_0.2_1.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/chameleon_split_0.6_0.2_1.npz -------------------------------------------------------------------------------- /splits/chameleon_split_0.6_0.2_2.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/chameleon_split_0.6_0.2_2.npz -------------------------------------------------------------------------------- /splits/chameleon_split_0.6_0.2_3.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/chameleon_split_0.6_0.2_3.npz -------------------------------------------------------------------------------- /splits/chameleon_split_0.6_0.2_4.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/chameleon_split_0.6_0.2_4.npz -------------------------------------------------------------------------------- /splits/chameleon_split_0.6_0.2_5.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/chameleon_split_0.6_0.2_5.npz -------------------------------------------------------------------------------- /splits/chameleon_split_0.6_0.2_6.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/chameleon_split_0.6_0.2_6.npz -------------------------------------------------------------------------------- /splits/chameleon_split_0.6_0.2_7.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/chameleon_split_0.6_0.2_7.npz -------------------------------------------------------------------------------- /splits/chameleon_split_0.6_0.2_8.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/chameleon_split_0.6_0.2_8.npz -------------------------------------------------------------------------------- /splits/chameleon_split_0.6_0.2_9.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/chameleon_split_0.6_0.2_9.npz -------------------------------------------------------------------------------- /splits/citeseer_split_0.6_0.2_0.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/citeseer_split_0.6_0.2_0.npz -------------------------------------------------------------------------------- /splits/citeseer_split_0.6_0.2_1.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/citeseer_split_0.6_0.2_1.npz -------------------------------------------------------------------------------- /splits/citeseer_split_0.6_0.2_2.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/citeseer_split_0.6_0.2_2.npz -------------------------------------------------------------------------------- /splits/citeseer_split_0.6_0.2_3.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/citeseer_split_0.6_0.2_3.npz -------------------------------------------------------------------------------- /splits/citeseer_split_0.6_0.2_4.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/citeseer_split_0.6_0.2_4.npz -------------------------------------------------------------------------------- /splits/citeseer_split_0.6_0.2_5.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/citeseer_split_0.6_0.2_5.npz -------------------------------------------------------------------------------- /splits/citeseer_split_0.6_0.2_6.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/citeseer_split_0.6_0.2_6.npz -------------------------------------------------------------------------------- /splits/citeseer_split_0.6_0.2_7.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/citeseer_split_0.6_0.2_7.npz -------------------------------------------------------------------------------- /splits/citeseer_split_0.6_0.2_8.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/citeseer_split_0.6_0.2_8.npz -------------------------------------------------------------------------------- /splits/citeseer_split_0.6_0.2_9.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/citeseer_split_0.6_0.2_9.npz -------------------------------------------------------------------------------- /splits/cora_split_0.6_0.2_0.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/cora_split_0.6_0.2_0.npz -------------------------------------------------------------------------------- /splits/cora_split_0.6_0.2_1.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/cora_split_0.6_0.2_1.npz -------------------------------------------------------------------------------- /splits/cora_split_0.6_0.2_2.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/cora_split_0.6_0.2_2.npz -------------------------------------------------------------------------------- /splits/cora_split_0.6_0.2_3.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/cora_split_0.6_0.2_3.npz -------------------------------------------------------------------------------- /splits/cora_split_0.6_0.2_4.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/cora_split_0.6_0.2_4.npz -------------------------------------------------------------------------------- /splits/cora_split_0.6_0.2_5.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/cora_split_0.6_0.2_5.npz -------------------------------------------------------------------------------- /splits/cora_split_0.6_0.2_6.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/cora_split_0.6_0.2_6.npz -------------------------------------------------------------------------------- /splits/cora_split_0.6_0.2_7.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/cora_split_0.6_0.2_7.npz -------------------------------------------------------------------------------- /splits/cora_split_0.6_0.2_8.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/cora_split_0.6_0.2_8.npz -------------------------------------------------------------------------------- /splits/cora_split_0.6_0.2_9.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/cora_split_0.6_0.2_9.npz -------------------------------------------------------------------------------- /splits/cornell_split_0.6_0.2_0.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/cornell_split_0.6_0.2_0.npz -------------------------------------------------------------------------------- /splits/cornell_split_0.6_0.2_1.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/cornell_split_0.6_0.2_1.npz -------------------------------------------------------------------------------- /splits/cornell_split_0.6_0.2_2.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/cornell_split_0.6_0.2_2.npz -------------------------------------------------------------------------------- /splits/cornell_split_0.6_0.2_3.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/cornell_split_0.6_0.2_3.npz -------------------------------------------------------------------------------- /splits/cornell_split_0.6_0.2_4.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/cornell_split_0.6_0.2_4.npz -------------------------------------------------------------------------------- /splits/cornell_split_0.6_0.2_5.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/cornell_split_0.6_0.2_5.npz -------------------------------------------------------------------------------- /splits/cornell_split_0.6_0.2_6.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/cornell_split_0.6_0.2_6.npz -------------------------------------------------------------------------------- /splits/cornell_split_0.6_0.2_7.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/cornell_split_0.6_0.2_7.npz -------------------------------------------------------------------------------- /splits/cornell_split_0.6_0.2_8.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/cornell_split_0.6_0.2_8.npz -------------------------------------------------------------------------------- /splits/cornell_split_0.6_0.2_9.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/cornell_split_0.6_0.2_9.npz -------------------------------------------------------------------------------- /splits/pubmed_split_0.6_0.2_0.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/pubmed_split_0.6_0.2_0.npz -------------------------------------------------------------------------------- /splits/pubmed_split_0.6_0.2_1.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/pubmed_split_0.6_0.2_1.npz -------------------------------------------------------------------------------- /splits/pubmed_split_0.6_0.2_2.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/pubmed_split_0.6_0.2_2.npz -------------------------------------------------------------------------------- /splits/pubmed_split_0.6_0.2_3.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/pubmed_split_0.6_0.2_3.npz -------------------------------------------------------------------------------- /splits/pubmed_split_0.6_0.2_4.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/pubmed_split_0.6_0.2_4.npz -------------------------------------------------------------------------------- /splits/pubmed_split_0.6_0.2_5.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/pubmed_split_0.6_0.2_5.npz -------------------------------------------------------------------------------- /splits/pubmed_split_0.6_0.2_6.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/pubmed_split_0.6_0.2_6.npz -------------------------------------------------------------------------------- /splits/pubmed_split_0.6_0.2_7.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/pubmed_split_0.6_0.2_7.npz -------------------------------------------------------------------------------- /splits/pubmed_split_0.6_0.2_8.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/pubmed_split_0.6_0.2_8.npz -------------------------------------------------------------------------------- /splits/pubmed_split_0.6_0.2_9.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/pubmed_split_0.6_0.2_9.npz -------------------------------------------------------------------------------- /splits/texas_split_0.6_0.2_0.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/texas_split_0.6_0.2_0.npz -------------------------------------------------------------------------------- /splits/texas_split_0.6_0.2_1.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/texas_split_0.6_0.2_1.npz -------------------------------------------------------------------------------- /splits/texas_split_0.6_0.2_2.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/texas_split_0.6_0.2_2.npz -------------------------------------------------------------------------------- /splits/texas_split_0.6_0.2_3.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/texas_split_0.6_0.2_3.npz -------------------------------------------------------------------------------- /splits/texas_split_0.6_0.2_4.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/texas_split_0.6_0.2_4.npz -------------------------------------------------------------------------------- /splits/texas_split_0.6_0.2_5.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/texas_split_0.6_0.2_5.npz -------------------------------------------------------------------------------- /splits/texas_split_0.6_0.2_6.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/texas_split_0.6_0.2_6.npz -------------------------------------------------------------------------------- /splits/texas_split_0.6_0.2_7.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/texas_split_0.6_0.2_7.npz -------------------------------------------------------------------------------- /splits/texas_split_0.6_0.2_8.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/texas_split_0.6_0.2_8.npz -------------------------------------------------------------------------------- /splits/texas_split_0.6_0.2_9.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/texas_split_0.6_0.2_9.npz -------------------------------------------------------------------------------- /splits/wisconsin_split_0.6_0.2_0.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/wisconsin_split_0.6_0.2_0.npz -------------------------------------------------------------------------------- /splits/wisconsin_split_0.6_0.2_1.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/wisconsin_split_0.6_0.2_1.npz -------------------------------------------------------------------------------- /splits/wisconsin_split_0.6_0.2_2.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/wisconsin_split_0.6_0.2_2.npz -------------------------------------------------------------------------------- /splits/wisconsin_split_0.6_0.2_3.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/wisconsin_split_0.6_0.2_3.npz -------------------------------------------------------------------------------- /splits/wisconsin_split_0.6_0.2_4.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/wisconsin_split_0.6_0.2_4.npz -------------------------------------------------------------------------------- /splits/wisconsin_split_0.6_0.2_5.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/wisconsin_split_0.6_0.2_5.npz -------------------------------------------------------------------------------- /splits/wisconsin_split_0.6_0.2_6.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/wisconsin_split_0.6_0.2_6.npz -------------------------------------------------------------------------------- /splits/wisconsin_split_0.6_0.2_7.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/wisconsin_split_0.6_0.2_7.npz -------------------------------------------------------------------------------- /splits/wisconsin_split_0.6_0.2_8.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/wisconsin_split_0.6_0.2_8.npz -------------------------------------------------------------------------------- /splits/wisconsin_split_0.6_0.2_9.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chennnM/GCNII/ca91f5686c4cd09cc1c6f98431a5d5b7e36acc92/splits/wisconsin_split_0.6_0.2_9.npz -------------------------------------------------------------------------------- /train.py: -------------------------------------------------------------------------------- 1 | from __future__ import division 2 | from __future__ import print_function 3 | import time 4 | import random 5 | import argparse 6 | import numpy as np 7 | import torch 8 | import torch.nn.functional as F 9 | import torch.optim as optim 10 | from utils import * 11 | from model import * 12 | import uuid 13 | 14 | # Training settings 15 | parser = argparse.ArgumentParser() 16 | parser.add_argument('--seed', type=int, default=42, help='Random seed.') 17 | parser.add_argument('--epochs', type=int, default=1500, help='Number of epochs to train.') 18 | parser.add_argument('--lr', type=float, default=0.01, help='learning rate.') 19 | parser.add_argument('--wd1', type=float, default=0.01, help='weight decay (L2 loss on parameters).') 20 | parser.add_argument('--wd2', type=float, default=5e-4, help='weight decay (L2 loss on parameters).') 21 | parser.add_argument('--layer', type=int, default=64, help='Number of layers.') 22 | parser.add_argument('--hidden', type=int, default=64, help='hidden dimensions.') 23 | parser.add_argument('--dropout', type=float, default=0.6, help='Dropout rate (1 - keep probability).') 24 | parser.add_argument('--patience', type=int, default=100, help='Patience') 25 | parser.add_argument('--data', default='cora', help='dateset') 26 | parser.add_argument('--dev', type=int, default=0, help='device id') 27 | parser.add_argument('--alpha', type=float, default=0.1, help='alpha_l') 28 | parser.add_argument('--lamda', type=float, default=0.5, help='lamda.') 29 | parser.add_argument('--variant', action='store_true', default=False, help='GCN* model.') 30 | parser.add_argument('--test', action='store_true', default=False, help='evaluation on test set.') 31 | args = parser.parse_args() 32 | random.seed(args.seed) 33 | np.random.seed(args.seed) 34 | torch.manual_seed(args.seed) 35 | torch.cuda.manual_seed(args.seed) 36 | 37 | # Load data 38 | adj, features, labels,idx_train,idx_val,idx_test = load_citation(args.data) 39 | cudaid = "cuda:"+str(args.dev) 40 | device = torch.device(cudaid) 41 | features = features.to(device) 42 | adj = adj.to(device) 43 | checkpt_file = 'pretrained/'+uuid.uuid4().hex+'.pt' 44 | print(cudaid,checkpt_file) 45 | 46 | model = GCNII(nfeat=features.shape[1], 47 | nlayers=args.layer, 48 | nhidden=args.hidden, 49 | nclass=int(labels.max()) + 1, 50 | dropout=args.dropout, 51 | lamda = args.lamda, 52 | alpha=args.alpha, 53 | variant=args.variant).to(device) 54 | 55 | optimizer = optim.Adam([ 56 | {'params':model.params1,'weight_decay':args.wd1}, 57 | {'params':model.params2,'weight_decay':args.wd2}, 58 | ],lr=args.lr) 59 | 60 | def train(): 61 | model.train() 62 | optimizer.zero_grad() 63 | output = model(features,adj) 64 | acc_train = accuracy(output[idx_train], labels[idx_train].to(device)) 65 | loss_train = F.nll_loss(output[idx_train], labels[idx_train].to(device)) 66 | loss_train.backward() 67 | optimizer.step() 68 | return loss_train.item(),acc_train.item() 69 | 70 | 71 | def validate(): 72 | model.eval() 73 | with torch.no_grad(): 74 | output = model(features,adj) 75 | loss_val = F.nll_loss(output[idx_val], labels[idx_val].to(device)) 76 | acc_val = accuracy(output[idx_val], labels[idx_val].to(device)) 77 | return loss_val.item(),acc_val.item() 78 | 79 | def test(): 80 | model.load_state_dict(torch.load(checkpt_file)) 81 | model.eval() 82 | with torch.no_grad(): 83 | output = model(features, adj) 84 | loss_test = F.nll_loss(output[idx_test], labels[idx_test].to(device)) 85 | acc_test = accuracy(output[idx_test], labels[idx_test].to(device)) 86 | return loss_test.item(),acc_test.item() 87 | 88 | t_total = time.time() 89 | bad_counter = 0 90 | best = 999999999 91 | best_epoch = 0 92 | acc = 0 93 | for epoch in range(args.epochs): 94 | loss_tra,acc_tra = train() 95 | loss_val,acc_val = validate() 96 | if(epoch+1)%1 == 0: 97 | print('Epoch:{:04d}'.format(epoch+1), 98 | 'train', 99 | 'loss:{:.3f}'.format(loss_tra), 100 | 'acc:{:.2f}'.format(acc_tra*100), 101 | '| val', 102 | 'loss:{:.3f}'.format(loss_val), 103 | 'acc:{:.2f}'.format(acc_val*100)) 104 | if loss_val < best: 105 | best = loss_val 106 | best_epoch = epoch 107 | acc = acc_val 108 | torch.save(model.state_dict(), checkpt_file) 109 | bad_counter = 0 110 | else: 111 | bad_counter += 1 112 | 113 | if bad_counter == args.patience: 114 | break 115 | 116 | if args.test: 117 | acc = test()[1] 118 | 119 | print("Train cost: {:.4f}s".format(time.time() - t_total)) 120 | print('Load {}th epoch'.format(best_epoch)) 121 | print("Test" if args.test else "Val","acc.:{:.1f}".format(acc*100)) 122 | 123 | 124 | 125 | 126 | 127 | 128 | -------------------------------------------------------------------------------- /utils.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import scipy.sparse as sp 3 | import torch 4 | import torch.nn.functional as F 5 | import sys 6 | import pickle as pkl 7 | import networkx as nx 8 | import json 9 | from networkx.readwrite import json_graph 10 | import pdb 11 | sys.setrecursionlimit(99999) 12 | 13 | def accuracy(output, labels): 14 | preds = output.max(1)[1].type_as(labels) 15 | correct = preds.eq(labels).double() 16 | correct = correct.sum() 17 | return correct / len(labels) 18 | 19 | def normalize(mx): 20 | """Row-normalize sparse matrix""" 21 | rowsum = np.array(mx.sum(1)) 22 | rowsum = (rowsum==0)*1+rowsum 23 | r_inv = np.power(rowsum, -1).flatten() 24 | r_inv[np.isinf(r_inv)] = 0. 25 | r_mat_inv = sp.diags(r_inv) 26 | mx = r_mat_inv.dot(mx) 27 | return mx 28 | 29 | def sys_normalized_adjacency(adj): 30 | adj = sp.coo_matrix(adj) 31 | adj = adj + sp.eye(adj.shape[0]) 32 | row_sum = np.array(adj.sum(1)) 33 | row_sum=(row_sum==0)*1+row_sum 34 | d_inv_sqrt = np.power(row_sum, -0.5).flatten() 35 | d_inv_sqrt[np.isinf(d_inv_sqrt)] = 0. 36 | d_mat_inv_sqrt = sp.diags(d_inv_sqrt) 37 | return d_mat_inv_sqrt.dot(adj).dot(d_mat_inv_sqrt).tocoo() 38 | 39 | def sparse_mx_to_torch_sparse_tensor(sparse_mx): 40 | """Convert a scipy sparse matrix to a torch sparse tensor.""" 41 | sparse_mx = sparse_mx.tocoo().astype(np.float32) 42 | indices = torch.from_numpy( 43 | np.vstack((sparse_mx.row, sparse_mx.col)).astype(np.int64)) 44 | values = torch.from_numpy(sparse_mx.data) 45 | shape = torch.Size(sparse_mx.shape) 46 | return torch.sparse.FloatTensor(indices, values, shape) 47 | 48 | def parse_index_file(filename): 49 | """Parse index file.""" 50 | index = [] 51 | for line in open(filename): 52 | index.append(int(line.strip())) 53 | return index 54 | 55 | # adapted from tkipf/gcn 56 | def load_citation(dataset_str="cora"): 57 | """ 58 | Load Citation Networks Datasets. 59 | """ 60 | names = ['x', 'y', 'tx', 'ty', 'allx', 'ally', 'graph'] 61 | objects = [] 62 | for i in range(len(names)): 63 | with open("data/ind.{}.{}".format(dataset_str.lower(), names[i]), 'rb') as f: 64 | if sys.version_info > (3, 0): 65 | objects.append(pkl.load(f, encoding='latin1')) 66 | else: 67 | objects.append(pkl.load(f)) 68 | 69 | x, y, tx, ty, allx, ally, graph = tuple(objects) 70 | test_idx_reorder = parse_index_file("data/ind.{}.test.index".format(dataset_str)) 71 | test_idx_range = np.sort(test_idx_reorder) 72 | 73 | if dataset_str == 'citeseer': 74 | # Fix citeseer dataset (there are some isolated nodes in the graph) 75 | # Find isolated nodes, add them as zero-vecs into the right position 76 | test_idx_range_full = range(min(test_idx_reorder), max(test_idx_reorder)+1) 77 | tx_extended = sp.lil_matrix((len(test_idx_range_full), x.shape[1])) 78 | tx_extended[test_idx_range-min(test_idx_range), :] = tx 79 | tx = tx_extended 80 | ty_extended = np.zeros((len(test_idx_range_full), y.shape[1])) 81 | ty_extended[test_idx_range-min(test_idx_range), :] = ty 82 | ty = ty_extended 83 | 84 | features = sp.vstack((allx, tx)).tolil() 85 | features[test_idx_reorder, :] = features[test_idx_range, :] 86 | adj = nx.adjacency_matrix(nx.from_dict_of_lists(graph)) 87 | adj = adj + adj.T.multiply(adj.T > adj) - adj.multiply(adj.T > adj) 88 | labels = np.vstack((ally, ty)) 89 | labels[test_idx_reorder, :] = labels[test_idx_range, :] 90 | 91 | idx_test = test_idx_range.tolist() 92 | idx_train = range(len(y)) 93 | idx_val = range(len(y), len(y)+500) 94 | 95 | features = normalize(features) 96 | # porting to pytorch 97 | features = torch.FloatTensor(np.array(features.todense())).float() 98 | labels = torch.LongTensor(labels) 99 | labels = torch.max(labels, dim=1)[1] 100 | # adj = sparse_mx_to_torch_sparse_tensor(adj).float() 101 | idx_train = torch.LongTensor(idx_train) 102 | idx_val = torch.LongTensor(idx_val) 103 | idx_test = torch.LongTensor(idx_test) 104 | adj = sys_normalized_adjacency(adj) 105 | adj = sparse_mx_to_torch_sparse_tensor(adj) 106 | return adj, features, labels, idx_train, idx_val, idx_test 107 | 108 | 109 | # adapted from PetarV/GAT 110 | def run_dfs(adj, msk, u, ind, nb_nodes): 111 | if msk[u] == -1: 112 | msk[u] = ind 113 | #for v in range(nb_nodes): 114 | for v in adj[u,:].nonzero()[1]: 115 | #if adj[u,v]== 1: 116 | run_dfs(adj, msk, v, ind, nb_nodes) 117 | 118 | def dfs_split(adj): 119 | # Assume adj is of shape [nb_nodes, nb_nodes] 120 | nb_nodes = adj.shape[0] 121 | ret = np.full(nb_nodes, -1, dtype=np.int32) 122 | 123 | graph_id = 0 124 | 125 | for i in range(nb_nodes): 126 | if ret[i] == -1: 127 | run_dfs(adj, ret, i, graph_id, nb_nodes) 128 | graph_id += 1 129 | 130 | return ret 131 | 132 | def test(adj, mapping): 133 | nb_nodes = adj.shape[0] 134 | for i in range(nb_nodes): 135 | #for j in range(nb_nodes): 136 | for j in adj[i, :].nonzero()[1]: 137 | if mapping[i] != mapping[j]: 138 | # if adj[i,j] == 1: 139 | return False 140 | return True 141 | 142 | def find_split(adj, mapping, ds_label): 143 | nb_nodes = adj.shape[0] 144 | dict_splits={} 145 | for i in range(nb_nodes): 146 | #for j in range(nb_nodes): 147 | for j in adj[i, :].nonzero()[1]: 148 | if mapping[i]==0 or mapping[j]==0: 149 | dict_splits[0]=None 150 | elif mapping[i] == mapping[j]: 151 | if ds_label[i]['val'] == ds_label[j]['val'] and ds_label[i]['test'] == ds_label[j]['test']: 152 | 153 | if mapping[i] not in dict_splits.keys(): 154 | if ds_label[i]['val']: 155 | dict_splits[mapping[i]] = 'val' 156 | 157 | elif ds_label[i]['test']: 158 | dict_splits[mapping[i]]='test' 159 | 160 | else: 161 | dict_splits[mapping[i]] = 'train' 162 | 163 | else: 164 | if ds_label[i]['test']: 165 | ind_label='test' 166 | elif ds_label[i]['val']: 167 | ind_label='val' 168 | else: 169 | ind_label='train' 170 | if dict_splits[mapping[i]]!= ind_label: 171 | print ('inconsistent labels within a graph exiting!!!') 172 | return None 173 | else: 174 | print ('label of both nodes different, exiting!!') 175 | return None 176 | return dict_splits 177 | 178 | def load_ppi(): 179 | 180 | print ('Loading G...') 181 | with open('ppi/ppi-G.json') as jsonfile: 182 | g_data = json.load(jsonfile) 183 | # print (len(g_data)) 184 | G = json_graph.node_link_graph(g_data) 185 | 186 | #Extracting adjacency matrix 187 | adj=nx.adjacency_matrix(G) 188 | 189 | prev_key='' 190 | for key, value in g_data.items(): 191 | if prev_key!=key: 192 | # print (key) 193 | prev_key=key 194 | 195 | # print ('Loading id_map...') 196 | with open('ppi/ppi-id_map.json') as jsonfile: 197 | id_map = json.load(jsonfile) 198 | # print (len(id_map)) 199 | 200 | id_map = {int(k):int(v) for k,v in id_map.items()} 201 | for key, value in id_map.items(): 202 | id_map[key]=[value] 203 | # print (len(id_map)) 204 | 205 | print ('Loading features...') 206 | features_=np.load('ppi/ppi-feats.npy') 207 | # print (features_.shape) 208 | 209 | #standarizing features 210 | from sklearn.preprocessing import StandardScaler 211 | 212 | train_ids = np.array([id_map[n] for n in G.nodes() if not G.node[n]['val'] and not G.node[n]['test']]) 213 | train_feats = features_[train_ids[:,0]] 214 | scaler = StandardScaler() 215 | scaler.fit(train_feats) 216 | features_ = scaler.transform(features_) 217 | 218 | features = sp.csr_matrix(features_).tolil() 219 | 220 | 221 | print ('Loading class_map...') 222 | class_map = {} 223 | with open('ppi/ppi-class_map.json') as jsonfile: 224 | class_map = json.load(jsonfile) 225 | # print (len(class_map)) 226 | 227 | #pdb.set_trace() 228 | #Split graph into sub-graphs 229 | # print ('Splitting graph...') 230 | splits=dfs_split(adj) 231 | 232 | #Rearrange sub-graph index and append sub-graphs with 1 or 2 nodes to bigger sub-graphs 233 | # print ('Re-arranging sub-graph IDs...') 234 | list_splits=splits.tolist() 235 | group_inc=1 236 | 237 | for i in range(np.max(list_splits)+1): 238 | if list_splits.count(i)>=3: 239 | splits[np.array(list_splits) == i] =group_inc 240 | group_inc+=1 241 | else: 242 | #splits[np.array(list_splits) == i] = 0 243 | ind_nodes=np.argwhere(np.array(list_splits) == i) 244 | ind_nodes=ind_nodes[:,0].tolist() 245 | split=None 246 | 247 | for ind_node in ind_nodes: 248 | if g_data['nodes'][ind_node]['val']: 249 | if split is None or split=='val': 250 | splits[np.array(list_splits) == i] = 21 251 | split='val' 252 | else: 253 | raise ValueError('new node is VAL but previously was {}'.format(split)) 254 | elif g_data['nodes'][ind_node]['test']: 255 | if split is None or split=='test': 256 | splits[np.array(list_splits) == i] = 23 257 | split='test' 258 | else: 259 | raise ValueError('new node is TEST but previously was {}'.format(split)) 260 | else: 261 | if split is None or split == 'train': 262 | splits[np.array(list_splits) == i] = 1 263 | split='train' 264 | else: 265 | pdb.set_trace() 266 | raise ValueError('new node is TRAIN but previously was {}'.format(split)) 267 | 268 | #counting number of nodes per sub-graph 269 | list_splits=splits.tolist() 270 | nodes_per_graph=[] 271 | for i in range(1,np.max(list_splits) + 1): 272 | nodes_per_graph.append(list_splits.count(i)) 273 | 274 | #Splitting adj matrix into sub-graphs 275 | subgraph_nodes=np.max(nodes_per_graph) 276 | adj_sub=np.empty((len(nodes_per_graph), subgraph_nodes, subgraph_nodes)) 277 | feat_sub = np.empty((len(nodes_per_graph), subgraph_nodes, features.shape[1])) 278 | labels_sub = np.empty((len(nodes_per_graph), subgraph_nodes, 121)) 279 | 280 | for i in range(1, np.max(list_splits) + 1): 281 | #Creating same size sub-graphs 282 | indexes = np.where(splits == i)[0] 283 | subgraph_=adj[indexes,:][:,indexes] 284 | 285 | if subgraph_.shape[0] adj) - adj.multiply(adj.T > adj) 369 | tmp = sys_normalized_adjacency(adj) 370 | train_adj_list.append(sparse_mx_to_torch_sparse_tensor(tmp)) 371 | for i in range(val_adj.shape[0]): 372 | adj = sp.coo_matrix(val_adj[i]) 373 | adj = adj + adj.T.multiply(adj.T > adj) - adj.multiply(adj.T > adj) 374 | tmp = sys_normalized_adjacency(adj) 375 | val_adj_list.append(sparse_mx_to_torch_sparse_tensor(tmp)) 376 | adj = sp.coo_matrix(test_adj[i]) 377 | adj = adj + adj.T.multiply(adj.T > adj) - adj.multiply(adj.T > adj) 378 | tmp = sys_normalized_adjacency(adj) 379 | test_adj_list.append(sparse_mx_to_torch_sparse_tensor(tmp)) 380 | 381 | train_feat = torch.FloatTensor(train_feat) 382 | val_feat = torch.FloatTensor(val_feat) 383 | test_feat = torch.FloatTensor(test_feat) 384 | 385 | train_labels = torch.FloatTensor(train_labels) 386 | val_labels = torch.FloatTensor(val_labels) 387 | test_labels = torch.FloatTensor(test_labels) 388 | 389 | tr_msk = torch.LongTensor(tr_msk) 390 | vl_msk = torch.LongTensor(vl_msk) 391 | ts_msk = torch.LongTensor(ts_msk) 392 | 393 | return train_adj_list,val_adj_list,test_adj_list,train_feat,val_feat,test_feat,train_labels,val_labels, test_labels, train_nodes, val_nodes, test_nodes 394 | 395 | --------------------------------------------------------------------------------