Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import torch
import torch.nn as nn
import torch.nn.functional as F
from cogdl.modules.conv import GCNConv
from . import register_model, BaseModel
@register_model("us_gcn")
class UnsupervisedGCN(BaseModel):
@staticmethod
def add_args(parser):
"""Add model-specific arguments to the parser."""
# fmt: off
parser.add_argument("--num-features", type=int)
parser.add_argument("--hidden-size", type=int, default=16)
parser.add_argument("--num-layers", type=int, default=2)
parser.add_argument("--dropout", type=float, default=0.5)
# fmt: on
@classmethod
def build_model_from_args(cls, args):
return cls(
args.num_features,
args.hidden_size,
args.num_layers,
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch_geometric.nn.conv import GCNConv
from cogdl.layers import SELayer
from .. import BaseModel, register_model
@register_model("drgcn")
class DrGCN(BaseModel):
@staticmethod
def add_args(parser):
"""Add model-specific arguments to the parser."""
# fmt: off
parser.add_argument("--num-features", type=int)
parser.add_argument("--num-classes", type=int)
parser.add_argument("--hidden-size", type=int, default=16)
parser.add_argument("--num-layers", type=int, default=2)
parser.add_argument("--dropout", type=float, default=0.5)
# fmt: on
@classmethod
def build_model_from_args(cls, args):
return cls(
args.num_features,
args.num_classes,
import networkx as nx
import numpy as np
import scipy.sparse as sp
from .. import BaseModel, register_model
@register_model("netmf")
class NetMF(BaseModel):
@staticmethod
def add_args(parser):
"""Add model-specific arguments to the parser."""
# fmt: off
parser.add_argument("--window-size", type=int, default=5)
parser.add_argument("--rank", type=int, default=256)
parser.add_argument("--negative", type=int, default=1)
parser.add_argument('--is-large', action='store_true')
# fmt: on
@classmethod
def build_model_from_args(cls, args):
return cls(
args.hidden_size, args.window_size, args.rank, args.negative, args.is_large
)
import numpy as np
import networkx as nx
from sklearn import preprocessing
import time
from tqdm import tqdm
from .. import BaseModel, register_model, alias_draw, alias_setup
@register_model("line")
class LINE(BaseModel):
@staticmethod
def add_args(parser):
"""Add model-specific arguments to the parser."""
# fmt: off
parser.add_argument('--walk-length', type=int, default=80,
help='Length of walk per source. Default is 50.')
parser.add_argument('--walk-num', type=int, default=40,
help='Number of walks per source. Default is 20.')
parser.add_argument('--negative', type=int, default=5,
help='Number of negative node in sampling. Default is 5.')
parser.add_argument('--batch-size', type=int, default=1000,
help='Batch size in SGD training process. Default is 1000.')
parser.add_argument('--alpha', type=float, default=0.025,
help='Initial learning rate of SGD. Default is 0.025.')
parser.add_argument('--order', type=int, default=3,
help='Order of proximity in LINE. Default is 3 for 1+2.')
import numpy as np
import networkx as nx
import scipy.sparse as sp
from sklearn import preprocessing
from .. import BaseModel, register_model
@register_model("grarep")
class GraRep(BaseModel):
@staticmethod
def add_args(parser):
"""Add model-specific arguments to the parser."""
# fmt: off
parser.add_argument('--step', type=int, default=5,
help='Number of matrix step in GraRep. Default is 5.')
# fmt: on
@classmethod
def build_model_from_args(cls, args):
return cls(args.hidden_size, args.step)
def __init__(self, dimension, step):
super(GraRep, self).__init__()
self.dimension = dimension
self.step = step
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch_geometric.nn.conv import GATConv
from .. import BaseModel, register_model
@register_model("pyg_gat")
class GAT(BaseModel):
@staticmethod
def add_args(parser):
"""Add model-specific arguments to the parser."""
# fmt: off
parser.add_argument("--num-features", type=int)
parser.add_argument("--num-classes", type=int)
parser.add_argument("--hidden-size", type=int, default=8)
parser.add_argument("--num-heads", type=int, default=8)
parser.add_argument("--dropout", type=float, default=0.6)
parser.add_argument("--lr", type=float, default=0.005)
# fmt: on
@classmethod
def build_model_from_args(cls, args):
return cls(
args.num_features,
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch_geometric.nn.conv import GATConv
from cogdl.layers import SELayer
from .. import BaseModel, register_model
@register_model("drgat")
class DrGAT(BaseModel):
@staticmethod
def add_args(parser):
"""Add model-specific arguments to the parser."""
# fmt: off
parser.add_argument("--num-features", type=int)
parser.add_argument("--num-classes", type=int)
parser.add_argument("--hidden-size", type=int, default=8)
parser.add_argument("--num-heads", type=int, default=8)
parser.add_argument("--dropout", type=float, default=0.6)
# fmt: on
@classmethod
def build_model_from_args(cls, args):
return cls(
args.num_features,
args.num_classes,
def __init__(self, nfeat, nhid, nclass, dropout, alpha, nheads):
"""Sparse version of GAT."""
BaseModel.__init__(self)
self.dropout = dropout
self.attentions = [
SpGraphAttentionLayer(
nfeat, nhid, dropout=dropout, alpha=alpha, concat=True
)
for _ in range(nheads)
]
for i, attention in enumerate(self.attentions):
self.add_module("attention_{}".format(i), attention)
self.out_att = SpGraphAttentionLayer(
nhid * nheads, nclass, dropout=dropout, alpha=alpha, concat=False
)
else:
# if this layer is last layer,
return h_prime
def __repr__(self):
return (
self.__class__.__name__
+ " ("
+ str(self.in_features)
+ " -> "
+ str(self.out_features)
+ ")"
)
class PetarVGAT(BaseModel):
@staticmethod
def add_args(parser):
"""Add model-specific arguments to the parser."""
# fmt: off
parser.add_argument("--num-features", type=int)
parser.add_argument("--num-classes", type=int)
parser.add_argument("--hidden-size", type=int, default=8)
parser.add_argument("--dropout", type=float, default=0.6)
parser.add_argument("--alpha", type=float, default=0.2)
parser.add_argument("--nheads", type=int, default=8)
# fmt: on
@classmethod
def build_model_from_args(cls, args):
return cls(
args.num_features,
else:
return output
def __repr__(self):
return (
self.__class__.__name__
+ " ("
+ str(self.in_features)
+ " -> "
+ str(self.out_features)
+ ")"
)
@register_model("gcn")
class TKipfGCN(BaseModel):
@staticmethod
def add_args(parser):
"""Add model-specific arguments to the parser."""
# fmt: off
parser.add_argument("--num-features", type=int)
parser.add_argument("--num-classes", type=int)
parser.add_argument("--hidden-size", type=int, default=64)
parser.add_argument("--dropout", type=float, default=0.5)
# fmt: on
@classmethod
def build_model_from_args(cls, args):
return cls(args.num_features, args.hidden_size, args.num_classes, args.dropout)
def __init__(self, nfeat, nhid, nclass, dropout):
super(TKipfGCN, self).__init__()