repo
stringlengths
1
99
file
stringlengths
13
215
code
stringlengths
12
59.2M
file_length
int64
12
59.2M
avg_line_length
float64
3.82
1.48M
max_line_length
int64
12
2.51M
extension_type
stringclasses
1 value
HGB
HGB-master/LP/benchmark/methods/MAGNN/utils/pytorchtools.py
import numpy as np import torch class EarlyStopping: """Early stops the training if validation loss doesn't improve after a given patience.""" def __init__(self, patience, verbose=False, delta=0, save_path='checkpoint.pt'): """ Args: patience (int): How long to wait after last time...
1,824
36.244898
111
py
HGB
HGB-master/LP/benchmark/methods/MAGNN/utils/tools.py
import torch import dgl import numpy as np from sklearn.model_selection import train_test_split from sklearn.metrics import f1_score, normalized_mutual_info_score, adjusted_rand_score from sklearn.cluster import KMeans from sklearn.svm import LinearSVC def idx_to_one_hot(idx_arr): one_hot = np.zeros((idx_arr.shap...
11,415
46.173554
174
py
HGB
HGB-master/LP/benchmark/methods/MAGNN/model/MAGNN_lp.py
import torch import torch.nn as nn import numpy as np from model.base_MAGNN import MAGNN_ctr_ntype_specific # for link prediction task class MAGNN_lp_layer(nn.Module): def __init__(self, num_metapaths_list, num_edge_type, etypes_lists, in_dim, ...
5,609
41.824427
115
py
HGB
HGB-master/LP/benchmark/methods/MAGNN/model/MAGNN_nc_mb.py
import torch import torch.nn as nn import numpy as np from model.base_MAGNN import MAGNN_ctr_ntype_specific # support for mini-batched forward # only support one layer for one ctr_ntype class MAGNN_nc_mb_layer(nn.Module): def __init__(self, num_metapaths, num_edge_type, ...
4,483
38.333333
119
py
HGB
HGB-master/LP/benchmark/methods/MAGNN/model/MAGNN_nc.py
import torch import torch.nn as nn import torch.nn.functional as F import numpy as np from model.base_MAGNN import MAGNN_ctr_ntype_specific fc_switch = False # multi-layer support class MAGNN_nc_layer(nn.Module): def __init__(self, num_metapaths_list, num_edge_type, ...
5,888
41.985401
148
py
HGB
HGB-master/LP/benchmark/methods/MAGNN/model/base_MAGNN.py
import torch import torch.nn as nn import torch.nn.functional as F import dgl.function as fn from dgl.nn.pytorch import edge_softmax class MAGNN_metapath_specific(nn.Module): def __init__(self, etypes, out_dim, num_heads, rnn_type='gru', ...
11,914
46.66
168
py
HGB
HGB-master/LP/benchmark/methods/RGCN/utils.py
import numpy as np import torch import scipy as sp class EarlyStopping: """Early stops the training if validation loss doesn't improve after a given patience.""" def __init__(self, patience, verbose=False, delta=0, save_path='checkpoint.pt'): """ Args: patience (int): How long to ...
3,127
29.368932
111
py
HGB
HGB-master/LP/benchmark/methods/RGCN/model.py
import torch as th import torch.nn as nn from dgl.nn.pytorch import GraphConv, GATConv import torch.nn.functional as F class BaseRGCN(nn.Module): def __init__(self, in_dims, h_dim, out_dim, num_rels, num_bases, num_hidden_layers=1, dropout=0, use_self_loop=False): super(B...
4,676
32.170213
79
py
HGB
HGB-master/LP/benchmark/methods/RGCN/link_predict.py
import dgl from model import BaseRGCN from utils import load_data from utils import EarlyStopping import utils import numpy as np import torch.nn.functional as F import torch.nn as nn import torch from collections import defaultdict import argparse import time import sys from dgl.nn.pytorch import RelGraphConv import p...
16,667
42.293506
125
py
HGB
HGB-master/LP/benchmark/methods/HetGNN/main.py
import torch import torch.optim as optim torch.set_num_threads(2) from args import read_args from torch.autograd import Variable import numpy as np import random import pickle import os import data_generator import tools import sys os.environ['CUDA_VISIBLE_DEVICES'] = '9' sys.path.append(f'../../') from scripts.data_l...
5,558
38.147887
113
py
HGB
HGB-master/LP/benchmark/methods/HetGNN/data_generator.py
import six.moves.cPickle as pickle import numpy as np import string import re import random import math from collections import Counter from itertools import * import sys import os import json from collections import defaultdict import torch as th class input_data(object): def __init__(self, args, dl): sel...
13,882
48.405694
117
py
HGB
HGB-master/LP/benchmark/methods/HetGNN/tools.py
import torch import torch.nn as nn import torch.nn.functional as F from torch.autograd import Variable from args import read_args import numpy as np import string import re import math import sys args = read_args() class HetAgg(nn.Module): def __init__(self, args, feature_list, neigh_list_train, train_id_list, d...
8,675
44.1875
139
py
HGB
HGB-master/LP/benchmark/methods/GNN/utils.py
from sklearn.metrics import (auc, f1_score, precision_recall_curve, roc_auc_score) import scipy.sparse as sp import argparse from torch.utils.data import Dataset import torch as th import numpy as np import random import sys from collections import defaultdict sys.path.append('../../') from scripts.data_loader import ...
6,631
37.55814
106
py
HGB
HGB-master/LP/benchmark/methods/GNN/GNN.py
import torch as th from torch import nn from torch_geometric.nn import GCNConv, GATConv import torch.nn.functional as F class DisMult(th.nn.Module): def __init__(self, rel_num, dim): super(DisMult, self).__init__() self.dim = dim self.weights = nn.Parameter(th.FloatTensor(size=(rel_num, dim,...
3,747
35.038462
108
py
HGB
HGB-master/LP/benchmark/methods/GNN/homoGNN.py
import torch as th import numpy as np from torch.utils.data import DataLoader from torch import nn import os os.environ['CUDA_VISIBLE_DEVICES'] = '5' import pickle import sys from collections import defaultdict from utils import * from GNN import GCN, GAT sys.path.append('../../') from scripts.data_loader import data_...
7,316
43.345455
115
py
HGB
HGB-master/LP/benchmark/methods/MAGNN_ini/run_DBLP.py
import time import argparse import torch import torch.nn.functional as F import numpy as np from utils.pytorchtools import EarlyStopping from utils.data import load_DBLP_data from utils.tools import index_generator, evaluate_results_nc, parse_minibatch from model import MAGNN_nc_mb # Params out_dim = 4 dropout_rate ...
10,569
50.813725
139
py
HGB
HGB-master/LP/benchmark/methods/MAGNN_ini/run_IMDB.py
import time import argparse import torch.nn.functional as F import torch.sparse import numpy as np import dgl from utils.pytorchtools import EarlyStopping from utils.data import load_IMDB_data from utils.tools import evaluate_results_nc from model import MAGNN_nc # Params out_dim = 3 dropout_rate = 0.5 lr = 0.005 we...
8,734
47.259669
133
py
HGB
HGB-master/LP/benchmark/methods/MAGNN_ini/run_LastFM.py
import time import argparse import torch import torch.nn.functional as F import numpy as np from sklearn.metrics import roc_auc_score, average_precision_score from utils.pytorchtools import EarlyStopping from utils.data import load_LastFM_data from utils.tools import index_generator, parse_minibatch_LastFM from model...
13,354
57.318777
198
py
HGB
HGB-master/LP/benchmark/methods/MAGNN_ini/test_LastFM.py
import time import argparse import torch import torch.nn.functional as F import numpy as np from sklearn.metrics import roc_auc_score, average_precision_score from utils.pytorchtools import EarlyStopping from utils.data import load_LastFM_data from utils.tools import index_generator, parse_minibatch_LastFM from model...
8,476
46.357542
198
py
HGB
HGB-master/LP/benchmark/methods/MAGNN_ini/utils/pytorchtools.py
import numpy as np import torch class EarlyStopping: """Early stops the training if validation loss doesn't improve after a given patience.""" def __init__(self, patience, verbose=False, delta=0, save_path='checkpoint.pt'): """ Args: patience (int): How long to wait after last time...
1,824
36.244898
111
py
HGB
HGB-master/LP/benchmark/methods/MAGNN_ini/utils/tools.py
import torch import dgl import numpy as np from sklearn.model_selection import train_test_split from sklearn.metrics import f1_score, normalized_mutual_info_score, adjusted_rand_score from sklearn.cluster import KMeans from sklearn.svm import LinearSVC def idx_to_one_hot(idx_arr): one_hot = np.zeros((idx_arr.shap...
11,415
46.173554
174
py
HGB
HGB-master/LP/benchmark/methods/MAGNN_ini/model/MAGNN_lp.py
import torch import torch.nn as nn import numpy as np from model.base_MAGNN import MAGNN_ctr_ntype_specific # for link prediction task class MAGNN_lp_layer(nn.Module): def __init__(self, num_metapaths_list, num_edge_type, etypes_lists, in_dim, ...
5,609
41.824427
115
py
HGB
HGB-master/LP/benchmark/methods/MAGNN_ini/model/MAGNN_nc_mb.py
import torch import torch.nn as nn import numpy as np from model.base_MAGNN import MAGNN_ctr_ntype_specific # support for mini-batched forward # only support one layer for one ctr_ntype class MAGNN_nc_mb_layer(nn.Module): def __init__(self, num_metapaths, num_edge_type, ...
4,483
38.333333
119
py
HGB
HGB-master/LP/benchmark/methods/MAGNN_ini/model/MAGNN_nc.py
import torch import torch.nn as nn import torch.nn.functional as F import numpy as np from model.base_MAGNN import MAGNN_ctr_ntype_specific fc_switch = False # multi-layer support class MAGNN_nc_layer(nn.Module): def __init__(self, num_metapaths_list, num_edge_type, ...
5,888
41.985401
148
py
HGB
HGB-master/LP/benchmark/methods/MAGNN_ini/model/base_MAGNN.py
import torch import torch.nn as nn import torch.nn.functional as F import dgl.function as fn from dgl.nn.pytorch import edge_softmax class MAGNN_metapath_specific(nn.Module): def __init__(self, etypes, out_dim, num_heads, rnn_type='gru', ...
11,914
46.66
168
py
HGB
HGB-master/LP/benchmark/methods/HGT/model.py
import dgl import math import torch import torch.nn as nn import torch.nn.functional as F class DistMult(nn.Module): def __init__(self, num_rel, dim): super(DistMult, self).__init__() self.W = nn.Parameter(torch.FloatTensor(size=(num_rel, dim, dim))) nn.init.xavier_normal_(self.W, gain=1.4...
6,631
43.213333
117
py
HGB
HGB-master/LP/benchmark/methods/HGT/link_predict.py
import scipy.io import urllib.request import dgl import math import numpy as np from model import * import torch from data_loader import data_loader from utils.data import load_data from utils.pytorchtools import EarlyStopping import argparse import time from collections import defaultdict ap = argparse.ArgumentParser...
12,942
43.477663
226
py
HGB
HGB-master/LP/benchmark/methods/HGT/utils/pytorchtools.py
import numpy as np import torch class EarlyStopping: """Early stops the training if validation loss doesn't improve after a given patience.""" def __init__(self, patience, verbose=False, delta=0, save_path='checkpoint.pt'): """ Args: patience (int): How long to wait after last time...
1,824
36.244898
111
py
HGB
HGB-master/LP/benchmark/methods/HGT/utils/tools.py
import torch import dgl import numpy as np from sklearn.model_selection import train_test_split from sklearn.metrics import f1_score, normalized_mutual_info_score, adjusted_rand_score from sklearn.cluster import KMeans from sklearn.svm import LinearSVC def idx_to_one_hot(idx_arr): one_hot = np.zeros((idx_arr.shap...
11,404
46.128099
174
py
HGB
HGB-master/LP/benchmark/methods/GATNE/main_pytorch.py
import math import numpy as np import torch import torch.nn as nn import torch.nn.functional as F from numpy import random from torch.nn.parameter import Parameter import os import pickle from utils import * import sys os.environ['CUDA_VISIBLE_DEVICES'] = '2' sys.path.append('../../') from scripts.data_loader import ...
13,587
38.61516
116
py
HGB
HGB-master/LP/GATNE/src/homGNN.py
import sys import random import torch as th import numpy as np from torch.utils.data import Dataset, DataLoader from torch import nn from torch_geometric.nn import GCNConv, SAGEConv, TopKPooling, GATConv import torch.nn.functional as F from sklearn.metrics import (auc, f1_score, precision_recall_curve, ...
14,515
36.802083
119
py
HGB
HGB-master/LP/GATNE/src/main_pytorch.py
import math import numpy as np import torch import torch.nn as nn import torch.nn.functional as F from numpy import random from torch.nn.parameter import Parameter from utils import * import os os.environ['CUDA_VISIBEL_DEVICES']='9' def get_batches(pairs, neighbors, batch_size): n_batches = (len(pairs) + (batch_...
11,238
36.588629
169
py
HGB
HGB-master/NC/GTN/main.py
import torch import numpy as np import torch.nn as nn import torch.nn.functional as F from model import GTN import pdb import pickle import argparse from utils import f1_score if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--dataset', type=str, help='...
6,053
47.047619
134
py
HGB
HGB-master/NC/GTN/main_sparse.py
import torch import numpy as np import torch.nn as nn import torch.nn.functional as F from model_sparse import GTN from matplotlib import pyplot as plt import pdb from torch_geometric.utils import dense_to_sparse, f1_score, accuracy from torch_geometric.data import Data import torch_sparse import pickle #from mem impor...
6,694
44.544218
125
py
HGB
HGB-master/NC/GTN/utils.py
from __future__ import division import torch def accuracy(pred, target): r"""Computes the accuracy of correct predictions. Args: pred (Tensor): The predictions. target (Tensor): The targets. :rtype: int """ return (pred == target).sum().item() / target.numel() def true_positi...
3,565
22.460526
66
py
HGB
HGB-master/NC/GTN/model.py
import torch import numpy as np import torch.nn as nn import torch.nn.functional as F import math from matplotlib import pyplot as plt import pdb class GTN(nn.Module): def __init__(self, num_edge, num_channels, w_in, w_out, num_class,num_layers,norm): super(GTN, self).__init__() self.num_edge...
4,825
33.471429
118
py
HGB
HGB-master/NC/GTN/GNN.py
import torch.nn as nn import dgl from dgl.nn.pytorch import GraphConv import dgl.function as fn from dgl.nn.pytorch import edge_softmax, GATConv class GAT(nn.Module): def __init__(self, g, num_layers, in_dim, num_hidden, num_cl...
2,550
31.291139
84
py
HGB
HGB-master/NC/GTN/main_gnn.py
import torch import numpy as np import torch.nn as nn import torch.nn.functional as F #from model import GTN import pdb import pickle import argparse from utils import f1_score import dgl from GNN import GCN, GAT if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--dataset', ty...
6,794
45.862069
144
py
HGB
HGB-master/NC/GTN/model_sparse.py
import torch import numpy as np import torch.nn as nn import torch.nn.functional as F import math from matplotlib import pyplot as plt import pdb from torch_geometric.utils import dense_to_sparse, f1_score from gcn import GCNConv from torch_scatter import scatter_add import torch_sparse import torch_sparse_old from tor...
6,068
39.192053
133
py
HGB
HGB-master/NC/GTN/gcn.py
import torch from torch.nn import Parameter from torch_scatter import scatter_add from torch_geometric.nn import MessagePassing from torch_geometric.utils import remove_self_loops, add_self_loops from inits import glorot, zeros import pdb class GCNConv(MessagePassing): r"""The graph convolutional operator from th...
4,197
35.504348
79
py
HGB
HGB-master/NC/GTN/messagepassing.py
import inspect import torch from torch_geometric.utils import scatter_ special_args = [ 'edge_index', 'edge_index_i', 'edge_index_j', 'size', 'size_i', 'size_j' ] __size_error_msg__ = ('All tensors which should get mapped to the same source ' 'or target nodes must be of same size in dimensio...
5,593
40.746269
79
py
HGB
HGB-master/NC/MAGNN/run_DBLP_gnn.py
import time import argparse import torch import torch.nn as nn import torch.nn.functional as F import numpy as np from utils.pytorchtools import EarlyStopping from utils.data import load_DBLP_data from utils.tools import index_generator, evaluate_results_nc, parse_minibatch #from model import MAGNN_nc_mb from sklear...
12,373
47.14786
217
py
HGB
HGB-master/NC/MAGNN/run_DBLP.py
import time import argparse import torch import torch.nn.functional as F import numpy as np from utils.pytorchtools import EarlyStopping from utils.data import load_DBLP_data from utils.tools import index_generator, evaluate_results_nc, parse_minibatch from model import MAGNN_nc_mb # Params out_dim = 4 dropout_rate ...
10,569
50.813725
139
py
HGB
HGB-master/NC/MAGNN/GNN.py
import torch import torch.nn as nn import dgl from dgl.nn.pytorch import GraphConv import dgl.function as fn from dgl.nn.pytorch import edge_softmax, GATConv class GAT(nn.Module): def __init__(self, g, num_layers, in_dim, num_hidden, ...
3,626
34.213592
115
py
HGB
HGB-master/NC/MAGNN/run_IMDB.py
import time import argparse import torch.nn.functional as F import torch.sparse import numpy as np import dgl from utils.pytorchtools import EarlyStopping from utils.data import load_IMDB_data from utils.tools import evaluate_results_nc from model import MAGNN_nc # Params out_dim = 3 dropout_rate = 0.5 lr = 0.005 we...
8,734
47.259669
133
py
HGB
HGB-master/NC/MAGNN/run_LastFM.py
import time import argparse import torch import torch.nn.functional as F import numpy as np from sklearn.metrics import roc_auc_score, average_precision_score from utils.pytorchtools import EarlyStopping from utils.data import load_LastFM_data from utils.tools import index_generator, parse_minibatch_LastFM from model...
13,301
57.087336
145
py
HGB
HGB-master/NC/MAGNN/utils/pytorchtools.py
import numpy as np import torch class EarlyStopping: """Early stops the training if validation loss doesn't improve after a given patience.""" def __init__(self, patience, verbose=False, delta=0, save_path='checkpoint.pt'): """ Args: patience (int): How long to wait after last time...
1,824
36.244898
111
py
HGB
HGB-master/NC/MAGNN/utils/tools.py
import torch import dgl import numpy as np from sklearn.model_selection import train_test_split from sklearn.metrics import f1_score, normalized_mutual_info_score, adjusted_rand_score from sklearn.cluster import KMeans from sklearn.svm import LinearSVC def idx_to_one_hot(idx_arr): one_hot = np.zeros((idx_arr.shap...
11,415
46.173554
174
py
HGB
HGB-master/NC/MAGNN/model/MAGNN_lp.py
import torch import torch.nn as nn import numpy as np from model.base_MAGNN import MAGNN_ctr_ntype_specific # for link prediction task class MAGNN_lp_layer(nn.Module): def __init__(self, num_metapaths_list, num_edge_type, etypes_lists, in_dim, ...
5,609
41.824427
115
py
HGB
HGB-master/NC/MAGNN/model/MAGNN_nc_mb.py
import torch import torch.nn as nn import numpy as np from model.base_MAGNN import MAGNN_ctr_ntype_specific # support for mini-batched forward # only support one layer for one ctr_ntype class MAGNN_nc_mb_layer(nn.Module): def __init__(self, num_metapaths, num_edge_type, ...
4,483
38.333333
119
py
HGB
HGB-master/NC/MAGNN/model/MAGNN_nc.py
import torch import torch.nn as nn import torch.nn.functional as F import numpy as np from model.base_MAGNN import MAGNN_ctr_ntype_specific fc_switch = False # multi-layer support class MAGNN_nc_layer(nn.Module): def __init__(self, num_metapaths_list, num_edge_type, ...
5,888
41.985401
148
py
HGB
HGB-master/NC/MAGNN/model/base_MAGNN.py
import torch import torch.nn as nn import torch.nn.functional as F import dgl.function as fn from dgl.nn.pytorch import edge_softmax class MAGNN_metapath_specific(nn.Module): def __init__(self, etypes, out_dim, num_heads, rnn_type='gru', ...
11,914
46.66
168
py
HGB
HGB-master/NC/RGCN/model.py
import torch as th import torch.nn as nn from dgl.nn.pytorch import GraphConv, GATConv import torch.nn.functional as F import numpy as np class GAT(nn.Module): def __init__(self, in_dim, num_hidden, num_classes, num_layers, activ...
6,321
32.273684
109
py
HGB
HGB-master/NC/RGCN/entity_classify.py
""" Modeling Relational Data with Graph Convolutional Networks Paper: https://arxiv.org/abs/1703.06103 Code: https://github.com/tkipf/relational-gcn Difference compared to tkipf/relation-gcn * l2norm applied to all weights * remove nodes that won't be touched """ import argparse import numpy as np import time import ...
9,677
36.657588
116
py
HGB
HGB-master/NC/HetGNN/code/tools.py
import torch import torch.nn as nn import torch.nn.functional as F from torch.autograd import Variable from args import read_args import numpy as np import string import re import math args = read_args() class HetAgg(nn.Module): def __init__(self, args, feature_list, a_neigh_list_train, p_neigh_list_train, v_neigh_l...
13,023
37.877612
114
py
HGB
HGB-master/NC/HetGNN/code/HetGNN.py
import torch import torch.optim as optim import data_generator import tools from args import read_args from torch.autograd import Variable import numpy as np import random torch.set_num_threads(2) import os os.environ['CUDA_VISIBLE_DEVICES']='0' class model_class(object): def __init__(self, args): super(model_clas...
4,105
30.343511
108
py
HGB
HGB-master/NC/HetGNN/code/homoGNN.py
import numpy as np import torch as th import torch.nn as nn from torch_geometric.nn import GCNConv, SAGEConv, TopKPooling, GATConv import torch.nn.functional as F import re import random import csv import argparse import datetime from sklearn.metrics import f1_score from itertools import * from scipy.sparse import coo_...
14,996
38.465789
116
py
HGB
HGB-master/NC/benchmark/methods/baseline/GNN.py
import torch import torch.nn as nn import dgl from dgl.nn.pytorch import GraphConv import dgl.function as fn from dgl.nn.pytorch import edge_softmax, GATConv from conv import myGATConv class myGAT(nn.Module): def __init__(self, g, edge_dim, num_etypes, ...
8,528
38.486111
169
py
HGB
HGB-master/NC/benchmark/methods/baseline/run.py
import sys sys.path.append('../../') import time import argparse import torch import torch.nn.functional as F import numpy as np from utils.pytorchtools import EarlyStopping from utils.data import load_data from GNN import GCN, GAT, RGAT import dgl def sp_to_spt(mat): coo = mat.tocoo() values = coo.data ...
7,070
41.089286
158
py
HGB
HGB-master/NC/benchmark/methods/baseline/conv.py
"""Torch modules for graph attention networks(GAT).""" # pylint: disable= no-member, arguments-differ, invalid-name import torch as th from torch import nn from dgl import function as fn from dgl.nn.pytorch import edge_softmax from dgl._ffi.base import DGLError from dgl.nn.pytorch.utils import Identity from dgl.utils ...
6,486
44.363636
92
py
HGB
HGB-master/NC/benchmark/methods/baseline/run_multi.py
import sys sys.path.append('../../') import time import argparse import os import torch import torch.nn as nn import torch.nn.functional as F import numpy as np from utils.pytorchtools import EarlyStopping from utils.data import load_data #from utils.tools import index_generator, evaluate_results_nc, parse_minibatch f...
7,689
41.252747
187
py
HGB
HGB-master/NC/benchmark/methods/baseline/run_new.py
import sys sys.path.append('../../') import time import argparse import os import torch import torch.nn.functional as F import numpy as np from utils.pytorchtools import EarlyStopping from utils.data import load_data #from utils.tools import index_generator, evaluate_results_nc, parse_minibatch from GNN import myGAT i...
7,947
41.731183
189
py
HGB
HGB-master/NC/benchmark/methods/baseline/utils/pytorchtools.py
import numpy as np import torch class EarlyStopping: """Early stops the training if validation loss doesn't improve after a given patience.""" def __init__(self, patience, verbose=False, delta=0, save_path='checkpoint.pt'): """ Args: patience (int): How long to wait after last time...
1,824
36.244898
111
py
HGB
HGB-master/NC/benchmark/methods/baseline/utils/tools.py
import torch import dgl import numpy as np from sklearn.model_selection import train_test_split from sklearn.metrics import f1_score, normalized_mutual_info_score, adjusted_rand_score from sklearn.cluster import KMeans from sklearn.svm import LinearSVC def idx_to_one_hot(idx_arr): one_hot = np.zeros((idx_arr.shap...
11,404
46.128099
174
py
HGB
HGB-master/NC/benchmark/methods/GTN/main.py
import sys sys.path.append('../../') import torch import numpy as np import torch.nn as nn import torch.nn.functional as F from model import GTN import pdb import pickle import argparse from utils import f1_score from scripts.data_loader import data_loader import scipy.sparse as sp def load_data(args): dataset, fu...
8,779
43.120603
134
py
HGB
HGB-master/NC/benchmark/methods/GTN/main_sparse.py
import torch import numpy as np import torch.nn as nn import torch.nn.functional as F from model_sparse import GTN from matplotlib import pyplot as plt import pdb from torch_geometric.utils import dense_to_sparse, f1_score, accuracy from torch_geometric.data import Data import torch_sparse import pickle #from mem impor...
6,694
44.544218
125
py
HGB
HGB-master/NC/benchmark/methods/GTN/utils.py
from __future__ import division import torch def accuracy(pred, target): r"""Computes the accuracy of correct predictions. Args: pred (Tensor): The predictions. target (Tensor): The targets. :rtype: int """ return (pred == target).sum().item() / target.numel() def true_positi...
3,565
22.460526
66
py
HGB
HGB-master/NC/benchmark/methods/GTN/model.py
import torch import numpy as np import torch.nn as nn import torch.nn.functional as F import math from matplotlib import pyplot as plt import pdb class GTN(nn.Module): def __init__(self, num_edge, num_channels, w_ins, w_out, num_class,num_layers,norm): super(GTN, self).__init__() self.num_edg...
5,021
33.634483
118
py
HGB
HGB-master/NC/benchmark/methods/GTN/model_sparse.py
import torch import numpy as np import torch.nn as nn import torch.nn.functional as F import math from matplotlib import pyplot as plt import pdb from torch_geometric.utils import dense_to_sparse, f1_score from gcn import GCNConv from torch_scatter import scatter_add import torch_sparse import torch_sparse_old from tor...
6,068
39.192053
133
py
HGB
HGB-master/NC/benchmark/methods/GTN/gcn.py
import torch from torch.nn import Parameter from torch_scatter import scatter_add from torch_geometric.nn import MessagePassing from torch_geometric.utils import remove_self_loops, add_self_loops from inits import glorot, zeros import pdb class GCNConv(MessagePassing): r"""The graph convolutional operator from th...
4,197
35.504348
79
py
HGB
HGB-master/NC/benchmark/methods/GTN/messagepassing.py
import inspect import torch from torch_geometric.utils import scatter_ special_args = [ 'edge_index', 'edge_index_i', 'edge_index_j', 'size', 'size_i', 'size_j' ] __size_error_msg__ = ('All tensors which should get mapped to the same source ' 'or target nodes must be of same size in dimensio...
5,593
40.746269
79
py
HGB
HGB-master/NC/benchmark/methods/GTN/main_multi.py
import sys sys.path.append('../../') import torch import numpy as np import torch.nn as nn import torch.nn.functional as F from model import GTN import pdb import pickle import argparse from utils import f1_score from scripts.data_loader import data_loader import scipy.sparse as sp def load_data(args): dataset, fu...
9,130
43.325243
127
py
HGB
HGB-master/NC/benchmark/methods/MAGNN/run_DBLP.py
import sys sys.path.append('../../') import time import argparse import torch import torch.nn.functional as F import numpy as np from utils.pytorchtools import EarlyStopping from utils.data import load_DBLP_data from utils.tools import index_generator, evaluate_results_nc, parse_minibatch from model import MAGNN_nc_m...
11,478
50.245536
139
py
HGB
HGB-master/NC/benchmark/methods/MAGNN/run_IMDB.py
import time import argparse import torch.nn.functional as F import torch.sparse import numpy as np import dgl from utils.pytorchtools import EarlyStopping from utils.data import load_IMDB_data from utils.tools import evaluate_results_nc from model import MAGNN_nc # Params out_dim = 3 dropout_rate = 0.5 lr = 0.005 we...
8,734
47.259669
133
py
HGB
HGB-master/NC/benchmark/methods/MAGNN/run_ACM.py
import sys sys.path.append('../../') import time import argparse import torch import torch.nn.functional as F import numpy as np from utils.pytorchtools import EarlyStopping from utils.data import load_ACM_data from utils.tools import index_generator, evaluate_results_nc, parse_minibatch from model import MAGNN_nc_mb...
11,505
50.366071
139
py
HGB
HGB-master/NC/benchmark/methods/MAGNN/run_LastFM.py
import time import argparse import torch import torch.nn.functional as F import numpy as np from sklearn.metrics import roc_auc_score, average_precision_score from utils.pytorchtools import EarlyStopping from utils.data import load_LastFM_data from utils.tools import index_generator, parse_minibatch_LastFM from model...
13,301
57.087336
145
py
HGB
HGB-master/NC/benchmark/methods/MAGNN/run_Freebase.py
import sys sys.path.append('../../') import time import argparse import torch import torch.nn.functional as F import numpy as np from utils.pytorchtools import EarlyStopping from utils.data import load_Freebase_data from utils.tools import index_generator, evaluate_results_nc, parse_minibatch from model import MAGNN_...
11,818
49.943966
139
py
HGB
HGB-master/NC/benchmark/methods/MAGNN/run_IMDB_new.py
import sys sys.path.append('../../') import time import argparse import torch.nn.functional as F import torch.sparse import numpy as np import dgl from utils.pytorchtools import EarlyStopping from utils.data import load_IMDB_data_new from utils.tools import evaluate_results_nc from model import MAGNN_nc import torch ...
9,039
46.830688
133
py
HGB
HGB-master/NC/benchmark/methods/MAGNN/utils/pytorchtools.py
import numpy as np import torch class EarlyStopping: """Early stops the training if validation loss doesn't improve after a given patience.""" def __init__(self, patience, verbose=False, delta=0, save_path='checkpoint.pt'): """ Args: patience (int): How long to wait after last time...
1,824
36.244898
111
py
HGB
HGB-master/NC/benchmark/methods/MAGNN/utils/tools.py
import torch import dgl import numpy as np from sklearn.model_selection import train_test_split from sklearn.metrics import f1_score, normalized_mutual_info_score, adjusted_rand_score from sklearn.cluster import KMeans from sklearn.svm import LinearSVC def idx_to_one_hot(idx_arr): one_hot = np.zeros((idx_arr.shap...
11,415
46.173554
174
py
HGB
HGB-master/NC/benchmark/methods/MAGNN/model/MAGNN_lp.py
import torch import torch.nn as nn import numpy as np from model.base_MAGNN import MAGNN_ctr_ntype_specific # for link prediction task class MAGNN_lp_layer(nn.Module): def __init__(self, num_metapaths_list, num_edge_type, etypes_lists, in_dim, ...
5,609
41.824427
115
py
HGB
HGB-master/NC/benchmark/methods/MAGNN/model/MAGNN_nc_mb.py
import torch import torch.nn as nn import numpy as np from model.base_MAGNN import MAGNN_ctr_ntype_specific # support for mini-batched forward # only support one layer for one ctr_ntype class MAGNN_nc_mb_layer(nn.Module): def __init__(self, num_metapaths, num_edge_type, ...
4,483
38.333333
119
py
HGB
HGB-master/NC/benchmark/methods/MAGNN/model/MAGNN_nc.py
import torch import torch.nn as nn import torch.nn.functional as F import numpy as np from model.base_MAGNN import MAGNN_ctr_ntype_specific fc_switch = False # multi-layer support class MAGNN_nc_layer(nn.Module): def __init__(self, num_metapaths_list, num_edge_type, ...
5,888
41.985401
148
py
HGB
HGB-master/NC/benchmark/methods/MAGNN/model/base_MAGNN.py
import torch import torch.nn as nn import torch.nn.functional as F import dgl.function as fn from dgl.nn.pytorch import edge_softmax class MAGNN_metapath_specific(nn.Module): def __init__(self, etypes, out_dim, num_heads, rnn_type='gru', ...
11,914
46.66
168
py
HGB
HGB-master/NC/benchmark/methods/RGCN/model.py
import torch as th import torch.nn as nn from dgl.nn.pytorch import GraphConv, GATConv import torch.nn.functional as F class BaseRGCN(nn.Module): def __init__(self, in_dims, h_dim, out_dim, num_rels, num_bases, num_hidden_layers=1, dropout=0, use_self_loop=False, use_cuda=False):...
4,725
32.28169
79
py
HGB
HGB-master/NC/benchmark/methods/RGCN/entity_classify.py
""" Modeling Relational Data with Graph Convolutional Networks Paper: https://arxiv.org/abs/1703.06103 Code: https://github.com/tkipf/relational-gcn Difference compared to tkipf/relation-gcn * l2norm applied to all weights * remove nodes that won't be touched """ from numpy.lib.function_base import append from model i...
13,282
36.416901
161
py
HGB
HGB-master/NC/benchmark/methods/HetGNN/code/DBLP/main.py
import torch import torch.optim as optim torch.set_num_threads(2) from args import read_args from torch.autograd import Variable import numpy as np import random import pickle import os os.environ['CUDA_VISIBLE_DEVICES'] = '0' import data_generator import tools import sys sys.path.append('../../') from scripts.data_l...
4,839
37.72
116
py
HGB
HGB-master/NC/benchmark/methods/HetGNN/code/DBLP/tools.py
import torch import torch.nn as nn import torch.nn.functional as F from torch.autograd import Variable from args import read_args import numpy as np import string import re import math import sys args = read_args() class HetAgg(nn.Module): def __init__(self, args, feature_list, a_neigh_list_train, p_neigh_list_t...
16,705
48.426036
120
py
HGB
HGB-master/NC/benchmark/methods/HetGNN/code/ACM/main.py
import torch import torch.optim as optim torch.set_num_threads(2) from args import read_args from torch.autograd import Variable import numpy as np import random import pickle import os import data_generator import tools import sys os.environ['CUDA_VISIBLE_DEVICES'] = '6' sys.path.append(f'../../') from scripts.data_...
4,850
36.898438
113
py
HGB
HGB-master/NC/benchmark/methods/HetGNN/code/ACM/data_generator.py
import six.moves.cPickle as pickle import numpy as np import string import re import random import math from collections import Counter from itertools import * import sys import os import json from collections import defaultdict import torch as th class input_data(object): def __init__(self, args, dl): sel...
12,625
48.513725
119
py
HGB
HGB-master/NC/benchmark/methods/HetGNN/code/ACM/tools.py
import torch import torch.nn as nn import torch.nn.functional as F from torch.autograd import Variable from args import read_args import numpy as np import string import re import math import sys args = read_args() class HetAgg(nn.Module): def __init__(self, args, feature_list, neigh_list_train, train_id_list, d...
8,585
44.428571
139
py
HGB
HGB-master/NC/benchmark/methods/HetGNN/code/IMDB/main.py
import torch import torch.optim as optim torch.set_num_threads(2) from args import read_args from torch.autograd import Variable import numpy as np import random import pickle import os import data_generator import tools import sys os.environ['CUDA_VISIBLE_DEVICES'] = '7' sys.path.append(f'../../') from scripts.data_...
4,850
36.898438
113
py
HGB
HGB-master/NC/benchmark/methods/HetGNN/code/IMDB/data_generator.py
import six.moves.cPickle as pickle import numpy as np import string import re import random import math from collections import Counter from itertools import * import sys import os import json from collections import defaultdict import torch as th from tqdm import tqdm class input_data(object): def __init__(self, ...
13,863
49.414545
128
py
HGB
HGB-master/NC/benchmark/methods/HetGNN/code/IMDB/tools.py
import torch import torch.nn as nn import torch.nn.functional as F from torch.autograd import Variable from args import read_args import numpy as np import string import re import math import sys from collections import defaultdict args = read_args() class HetAgg(nn.Module): def __init__(self, args, feature_list...
8,660
45.069149
130
py
HGB
HGB-master/NC/benchmark/methods/HAN/main.py
import torch from sklearn.metrics import f1_score import dgl from utils import load_data, EarlyStopping import torch.nn.functional as F from model_hetero import HAN, HAN_freebase def score(logits, labels): _, indices = torch.max(logits, dim=1) prediction = indices.long().cpu().numpy() labels = labels.cpu(...
4,447
36.378151
113
py
HGB
HGB-master/NC/benchmark/methods/HAN/model_hetero.py
"""This model shows an example of using dgl.metapath_reachable_graph on the original heterogeneous graph. Because the original HAN implementation only gives the preprocessed homogeneous graph, this model could not reproduce the result in HAN as they did not provide the preprocessing code, and we constructed another da...
4,565
34.123077
98
py
HGB
HGB-master/NC/benchmark/methods/HAN/model_hetero_multi.py
"""This model shows an example of using dgl.metapath_reachable_graph on the original heterogeneous graph. Because the original HAN implementation only gives the preprocessed homogeneous graph, this model could not reproduce the result in HAN as they did not provide the preprocessing code, and we constructed another da...
4,541
33.938462
98
py
HGB
HGB-master/NC/benchmark/methods/HAN/utils.py
import datetime import dgl import errno import numpy as np import os import pickle import random import torch import copy import torch as th from dgl.data.utils import download, get_download_dir, _get_dgl_url from pprint import pprint from scipy import sparse from scipy import io as sio import sys sys.path.append('....
13,732
34.485788
119
py
HGB
HGB-master/NC/benchmark/methods/HAN/main_multi.py
import torch from sklearn.metrics import f1_score import dgl from utils import load_data, EarlyStopping import torch.nn.functional as F from model_hetero_multi import HAN import numpy as np def evaluate(model, g, features, labels, mask, loss_func, dl): return loss def main(args): g, features, labels, num_cla...
3,362
34.03125
81
py
HGB
HGB-master/NC/benchmark/methods/GNN/GNN.py
import torch import torch.nn as nn import dgl from dgl.nn.pytorch import GraphConv import dgl.function as fn from dgl.nn.pytorch import edge_softmax, GATConv class GAT(nn.Module): def __init__(self, g, in_dims, num_hidden, num_classes, ...
3,208
34.263736
102
py