grb.model.torch

grb.model.torch.appnp

Torch module for APPNP.

class grb.model.torch.appnp.APPNP(in_features, out_features, hidden_features, layer_norm=False, activation=<function relu>, edge_drop=0.0, alpha=0.01, k=10)[source]

Bases: torch.nn.modules.module.Module

Approximated Personalized Propagation of Neural Predictions (APPNP)

Parameters
  • in_features (int) – Dimension of input features.

  • out_features (int) – Dimension of output features.

  • hidden_features (int or list of int) – Dimension of hidden features. List if multi-layer.

  • layer_norm (bool, optional) – Whether to use layer normalization. Default: False.

  • activation (func of torch.nn.functional, optional) – Activation function. Default: torch.nn.functional.relu.

  • edge_drop (float, optional) – Rate of edge drop.

  • alpha (float, optional) – Hyper-parameter, refer to original paper. Default: 0.01.

  • k (int, optional) – Hyper-parameter, refer to original paper. Default: 10.

forward(x, adj, dropout=0.0)[source]
Parameters
  • x (torch.Tensor) – Tensor of input features.

  • adj (torch.SparseTensor) – Sparse tensor of adjacency matrix.

  • dropout (float, optional) – Rate of dropout. Default: 0.0.

Returns

x – Output of model (logits without activation).

Return type

torch.Tensor

property model_type

Indicate type of implementation.

training: bool
class grb.model.torch.appnp.SparseEdgeDrop(edge_drop)[source]

Bases: torch.nn.modules.module.Module

Sparse implementation of edge drop.

Parameters

edge_drop (float) – Rate of edge drop.

forward(x)[source]

Sparse edge drop

training: bool

grb.model.torch.gcn

Torch module for GCN.

class grb.model.torch.gcn.GCN(in_features, out_features, hidden_features, activation=<function relu>, layer_norm=False, residual=False, dropout=True)[source]

Bases: torch.nn.modules.module.Module

Graph Convolutional Networks (GCN)

Parameters
  • in_features (int) – Dimension of input features.

  • out_features (int) – Dimension of output features.

  • hidden_features (int or list of int) – Dimension of hidden features. List if multi-layer.

  • layer_norm (bool, optional) – Whether to use layer normalization. Default: False.

  • activation (func of torch.nn.functional, optional) – Activation function. Default: torch.nn.functional.relu.

  • residual (bool, optional) – Whether to use residual connection. Default: False.

  • dropout (bool, optional) – Whether to dropout during training. Default: True.

forward(x, adj, dropout=0.0)[source]
Parameters
  • x (torch.Tensor) – Tensor of input features.

  • adj (torch.SparseTensor) – Sparse tensor of adjacency matrix.

  • dropout (float, optional) – Rate of dropout. Default: 0.0.

Returns

x – Output of model (logits without activation).

Return type

torch.Tensor

property model_type

Indicate type of implementation.

reset_parameters()[source]

Reset parameters.

training: bool
class grb.model.torch.gcn.GCNConv(in_features, out_features, activation=None, residual=False, dropout=False)[source]

Bases: torch.nn.modules.module.Module

GCN convolutional layer.

Parameters
  • in_features (int) – Dimension of input features.

  • out_features (int) – Dimension of output features.

  • activation (func of torch.nn.functional, optional) – Activation function. Default: None.

  • residual (bool, optional) – Whether to use residual connection. Default: False.

  • dropout (bool, optional) – Whether to dropout during training. Default: False.

forward(x, adj, dropout=0.0)[source]
Parameters
  • x (torch.Tensor) – Tensor of input features.

  • adj (torch.SparseTensor) – Sparse tensor of adjacency matrix.

  • dropout (float, optional) – Rate of dropout. Default: 0.0.

Returns

x – Output of layer.

Return type

torch.Tensor

reset_parameters()[source]

Reset parameters.

training: bool

grb.model.torch.gin

Torch module for GIN.

class grb.model.torch.gin.GIN(in_features, out_features, hidden_features, activation=<function relu>, layer_norm=False, dropout=True)[source]

Bases: torch.nn.modules.module.Module

Graph Isomorphism Network (GIN)

Parameters
  • in_features (int) – Dimension of input features.

  • out_features (int) – Dimension of output features.

  • hidden_features (int or list of int) – Dimension of hidden features. List if multi-layer.

  • layer_norm (bool, optional) – Whether to use layer normalization. Default: False.

  • activation (func of torch.nn.functional, optional) – Activation function. Default: torch.nn.functional.relu.

  • dropout (bool, optional) – Whether to dropout during training. Default: True.

forward(x, adj, dropout=0.0)[source]
Parameters
  • x (torch.Tensor) – Tensor of input features.

  • adj (torch.SparseTensor) – Sparse tensor of adjacency matrix.

  • dropout (float, optional) – Rate of dropout. Default: 0.0.

Returns

x – Output of model (logits without activation).

Return type

torch.Tensor

property model_type

Indicate type of implementation.

reset_parameters()[source]

Reset parameters.

training: bool
class grb.model.torch.gin.GINConv(in_features, out_features, activation=<function relu>, eps=0.0, batchnorm=True, dropout=False)[source]

Bases: torch.nn.modules.module.Module

GIN convolutional layer.

Parameters
  • in_features (int) – Dimension of input features.

  • out_features (int) – Dimension of output features.

  • activation (func of torch.nn.functional, optional) – Activation function. Default: None.

  • eps (float, optional) – Hyper-parameter, refer to original paper. Default: 0.0.

  • batchnorm (bool, optional) – Whether to apply batch normalization. Default: True.

  • dropout (bool, optional) – Whether to dropout during training. Default: False.

forward(x, adj, dropout=0.0)[source]
Parameters
  • x (torch.Tensor) – Tensor of input features.

  • adj (torch.SparseTensor) – Sparse tensor of adjacency matrix.

  • dropout (float, optional) – Rate of dropout. Default: 0.0.

Returns

x – Output of layer.

Return type

torch.Tensor

reset_parameters()[source]

Reset parameters.

training: bool

grb.model.torch.graphsage

Torch module for GraphSAGE.

class grb.model.torch.graphsage.GraphSAGE(in_features, out_features, hidden_features, activation=<function relu>, layer_norm=False, dropout=True)[source]

Bases: torch.nn.modules.module.Module

Inductive Representation Learning on Large Graphs (GraphSAGE)

Parameters
  • in_features (int) – Dimension of input features.

  • out_features (int) – Dimension of output features.

  • hidden_features (int or list of int) – Dimension of hidden features. List if multi-layer.

  • layer_norm (bool, optional) – Whether to use layer normalization. Default: False.

  • activation (func of torch.nn.functional, optional) – Activation function. Default: torch.nn.functional.relu.

  • dropout (bool, optional) – Whether to dropout during training. Default: True.

forward(x, adj, dropout=0.0)[source]
Parameters
  • x (torch.Tensor) – Tensor of input features.

  • adj (torch.SparseTensor) – Sparse tensor of adjacency matrix.

  • dropout (float, optional) – Rate of dropout. Default: 0.0.

Returns

x – Output of model (logits without activation).

Return type

torch.Tensor

property model_type

Indicate type of implementation.

training: bool
class grb.model.torch.graphsage.SAGEConv(in_features, pool_features, out_features, activation=None, dropout=False)[source]

Bases: torch.nn.modules.module.Module

SAGE convolutional layer.

Parameters
  • in_features (int) – Dimension of input features.

  • pool_features (int) – Dimension of pooling features.

  • out_features (int) – Dimension of output features.

  • activation (func of torch.nn.functional, optional) – Activation function. Default: None.

  • dropout (bool, optional) – Whether to dropout during training. Default: False.

forward(x, adj, dropout=0.0, mu=2.0)[source]
Parameters
  • x (torch.Tensor) – Tensor of input features.

  • adj (torch.SparseTensor) – Sparse tensor of adjacency matrix.

  • dropout (float, optional) – Rate of dropout. Default: 0.0.

  • mu (float, optional) – Hyper-parameter, refer to original paper. Default: 2.0.

Returns

x – Output of layer.

Return type

torch.Tensor

training: bool

grb.model.torch.robustgcn

grb.model.torch.sgcn

Torch module for SGCN.

class grb.model.torch.sgcn.SGCN(in_features, out_features, hidden_features, activation=<built-in method tanh of type object>, layer_norm=False)[source]

Bases: torch.nn.modules.module.Module

Simplifying Graph Convolutional Networks (SGCN)

Parameters
  • in_features (int) – Dimension of input features.

  • out_features (int) – Dimension of output features.

  • hidden_features (int or list of int) – Dimension of hidden features. List if multi-layer.

  • layer_norm (bool, optional) – Whether to use layer normalization. Default: False.

  • activation (func of torch.nn.functional, optional) – Activation function. Default: torch.tanh.

forward(x, adj, dropout=0.0)[source]
Parameters
  • x (torch.Tensor) – Tensor of input features.

  • adj (torch.SparseTensor) – Sparse tensor of adjacency matrix.

  • dropout (float, optional) – Rate of dropout. Default: 0.0.

Returns

x – Output of model (logits without activation).

Return type

torch.Tensor

property model_type

Indicate type of implementation.

training: bool
class grb.model.torch.sgcn.SGConv(in_features, out_features)[source]

Bases: torch.nn.modules.module.Module

SGCN convolutional layer.

Parameters
  • in_features (int) – Dimension of input features.

  • out_features (int) – Dimension of output features.

Returns

x – Output of layer.

Return type

torch.Tensor

forward(x, adj, k=4)[source]
Parameters
  • x (torch.Tensor) – Tensor of input features.

  • adj (torch.SparseTensor) – Sparse tensor of adjacency matrix.

  • k (int, optional) – Hyper-parameter, refer to original paper. Default: 4.

Returns

x – Output of layer.

Return type

torch.Tensor

training: bool

grb.model.torch.tagcn

Torch module for TAGCN.

class grb.model.torch.tagcn.TAGCN(in_features, out_features, hidden_features, k, activation=<function leaky_relu>, layer_norm=False, dropout=True)[source]

Bases: torch.nn.modules.module.Module

Topological Adaptive Graph Convolutional Networks (TAGCN)

Parameters
  • in_features (int) – Dimension of input features.

  • out_features (int) – Dimension of output features.

  • hidden_features (int or list of int) – Dimension of hidden features. List if multi-layer.

  • k (int) – Hyper-parameter, refer to original paper.

  • layer_norm (bool, optional) – Whether to use layer normalization. Default: False.

  • activation (func of torch.nn.functional, optional) – Activation function. Default: torch.nn.functional.leaky_relu.

  • dropout (bool, optional) – Whether to dropout during training. Default: True.

forward(x, adj, dropout=0.0)[source]
Parameters
  • x (torch.Tensor) – Tensor of input features.

  • adj (list of torch.SparseTensor) – List of sparse tensor of adjacency matrix.

  • dropout (float, optional) – Rate of dropout. Default: 0.0.

Returns

x – Output of model (logits without activation).

Return type

torch.Tensor

property model_type

Indicate type of implementation.

reset_parameters()[source]

Reset paramters.

training: bool
class grb.model.torch.tagcn.TAGConv(in_features, out_features, k=2, activation=None, dropout=False, batchnorm=False)[source]

Bases: torch.nn.modules.module.Module

TAGCN convolutional layer.

Parameters
  • in_features (int) – Dimension of input features.

  • out_features (int) – Dimension of output features.

  • k (int, optional) – Hyper-parameter, refer to original paper. Default: 2.

  • activation (func of torch.nn.functional, optional) – Activation function. Default: None.

  • dropout (bool, optional) – Whether to dropout during training. Default: False.

  • batchnorm (bool, optional) – Whether to apply batch normalization. Default: False.

forward(x, adj, dropout=0.0)[source]
Parameters
  • x (torch.Tensor) – Tensor of input features.

  • adj (torch.SparseTensor) – Sparse tensor of adjacency matrix.

  • dropout (float, optional) – Rate of dropout. Default: 0.0.

Returns

x – Output of layer.

Return type

torch.Tensor

reset_parameters()[source]

Reset parameters.

training: bool