pydgc.modules
pydgc.modules.decoder
- class BaseDecoder(dims=None, layer='linear', act='relu', act_last=False, add_self_loops=True)[source]
Bases:
ModuleBase 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.
- 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
Moduleinstance 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:
BaseDecoderMLP 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
Moduleinstance 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:
BaseDecoderGNN 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.
- 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
Moduleinstance 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:
ModuleInner Product Decoder class.
$hat{A} = sigmoid(ZZ^T)$
- Parameters:
None –
- 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
Moduleinstance 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:
ModuleBase 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.
- 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
Moduleinstance 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:
BaseEncoderMLP 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.
- 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
Moduleinstance 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:
BaseEncoderGNN 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.
- 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
Moduleinstance 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:
ModuleGAT 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.
- 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
Moduleinstance 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:
ModuleGraph 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.
- 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
Moduleinstance 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:
ModuleSelf-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.
- 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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- 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