pydgc.modules

pydgc.modules.decoder

class BaseDecoder(dims=None, layer='linear', act='relu', act_last=False, add_self_loops=True)[source]

Bases: Module

Base Decoder class.

Parameters:
  • dims (List[int]) – A list of dimensions from input to output.

  • layer (str) – Type of layers, e.g., ‘linear’, ‘gcn’, ‘gat’, ‘sage’, ‘sg’.

  • act (str) – Activation function, e.g., ‘relu’, ‘’

  • act_last (bool) – Whether to apply activation function to the last layer.

  • add_self_loops (bool) – Whether to add self-loops to the graph.

reset_parameters()[source]
property act_func
forward(*args, **kwargs)[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class MLPDecoder(dims, act='relu', act_last=False)[source]

Bases: BaseDecoder

MLP Decoder class.

Parameters:
  • dims (List[int]) – A list of dimensions from input to output.

  • act (str) – Activation function, e.g., ‘relu’, ‘’

  • act_last (bool) – Whether to apply activation function to the last layer.

forward(x)[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Return type:

List[Tensor]

training: bool
class GNNAttributeDecoder(dims, layer='gcn', act='relu', act_last=False, add_self_loops=True)[source]

Bases: BaseDecoder

GNN Attribute Decoder class.

Parameters:
  • dims (List[int]) – A list of dimensions from input to output.

  • layer (str) – Type of layers, e.g., ‘linear’, ‘gcn’, ‘gat’, ‘sage’, ‘sg’.

  • act (str) – Activation function, e.g., ‘relu’, ‘’

  • act_last (bool) – Whether to apply activation function to the last layer.

  • add_self_loops (bool) – Whether to add self-loops to the graph.

reset_parameters()[source]
forward(x, edge_index)[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Return type:

Tensor

training: bool
class InnerProductDecoder[source]

Bases: Module

Inner Product Decoder class.

$hat{A} = sigmoid(ZZ^T)$

Parameters:

None

reset_parameters()[source]
static forward(embedding)[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Return type:

Tensor

training: bool

pydgc.modules.encoder

class BaseEncoder(dims=None, layer='linear', act='relu', act_last=False, add_self_loops=True)[source]

Bases: Module

Base Encoder class.

Parameters:
  • dims (List[int]) – A list of dimensions from input to output.

  • layer (str) – Type of layers, e.g., ‘linear’, ‘gcn’, ‘gat’, ‘sage’, ‘sg’.

  • act (str) – Activation function, e.g., ‘relu’, ‘’

  • act_last (bool) – Whether to apply activation function to the last layer.

  • add_self_loops (bool) – Whether to add self-loops to the graph.

reset_parameters()[source]
property act_func
forward(*args, **kwargs)[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class MLPEncoder(dims, act='relu', act_last=False)[source]

Bases: BaseEncoder

MLP Encoder class.

Parameters:
  • dims (List[int]) – A list of dimensions from input to output.

  • act (str) – Activation function, e.g., ‘relu’, ‘’

  • act_last (bool) – Whether to apply activation function to the last layer.

reset_parameters()[source]
forward(x)[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class GNNEncoder(dims, layer='gcn', act='relu', act_last=False, add_self_loops=True)[source]

Bases: BaseEncoder

GNN Encoder class.

Parameters:
  • dims (List[int]) – A list of dimensions from input to output.

  • layer (str) – Type of layers, e.g., ‘linear’, ‘gcn’, ‘gat’, ‘sage’, ‘sg’.

  • act (str) – Activation function, e.g., ‘relu’, ‘’

  • act_last (bool) – Whether to apply activation function to the last layer.

  • add_self_loops (bool) – Whether to add self-loops to the graph.

reset_parameters()[source]
forward(x, edge_index)[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class GATMEncoder(dims, alpha=0.2)[source]

Bases: Module

GAT Encoder with M.

$M=(B+B^2+dots+B^t)/t$

Parameters:
  • dims (List[int]) – A list of dimensions from input to output.

  • alpha (float) – LeakyReLU negative slope.

reset_parameters()[source]
forward(x, adj, M)[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class GATMConv(in_features, out_features, alpha=0.2)[source]

Bases: Module

Graph Attention Convolutional Layer with Multi-head Attention.

$M=(B+B^2+dots+B^t)/t$

Parameters:
  • in_features (int) – Number of input features.

  • out_features (int) – Number of output features.

  • alpha (float) – LeakyReLU negative slope.

reset_parameters()[source]
forward(x, adj, M, concat=True)[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool

pydgc.modules.ssc

class SSCLayer(in_channels, out_channels, method='kl_div', v=1.0)[source]

Bases: Module

Self-supervised clustering layer.

Reference: http://proceedings.mlr.press/v48/xieb16.pdf

Parameters:
  • in_channels (int) – Dimension of embeddings.

  • out_channels (int) – Number of clusters.

  • method (str) – Method of loss calculation, e.g., ‘kl_div’, ‘cross_entropy’, ‘mse’.

  • v (float) – Parameter for soft assignment.

reset_parameters()[source]
forward(embedding)[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

get_q(embedding)[source]
static loss(q, method='kl_div')[source]

Calculate loss of self-supervised clustering.

Parameters:
  • q (torch.Tensor) – Soft assignment matrix.

  • method (str) – Method of loss calculation, e.g., ‘kl_div’, ‘cross_entropy’, ‘mse’.

Returns:

Loss value.

Return type:

torch.Tensor

training: bool

pydgc.modules.utils

class LayerRegistry[source]

Bases: object

classmethod list_layers()[source]
classmethod get_layer(name)[source]
register_layer(name, layer_class)[source]

Register decorators/functions for custom layer types.

Parameters:
  • name (str) – Name of the layer, available layer: linear, gcn, gat, sage, sg.

  • layer_class (nn.Module) – Class of the layer.