torch_geometric_signed_directed.nn.directed.DiGCL
Classes
An implementation of the DiGCL encoder model from the |
|
An implementation of the DiGCL model from the |
Module Contents
- class DiGCL_Encoder(in_channels: int, out_channels: int, activation: str, num_layers: int = 2)
Bases:
torch.nn.ModuleAn implementation of the DiGCL encoder model from the Directed Graph Contrastive Learning paper.
- Parameters:
in_channels (int) – Dimension of input features.
out_channels (int) – Dimension of output representations.
activation (str) – Activation funciton to use.
num_layers (int, Optional) – Number of layers for encoder. (Default: 2)
- conv
- activation
- reset_parameters()
- forward(x: torch.Tensor, edge_index: torch.Tensor, edge_weight: torch.Tensor = None)
Making a forward pass of the DiGCL encoder model.
- Arg types:
x (PyTorch FloatTensor) - Node features.
edge_index (PyTorch LongTensor) - Edge indices.
edge_weight (PyTorch FloatTensor, optional) - Edge weights corresponding to edge indices.
- Return types:
x (PyTorch FloatTensor) - Embeddings for all nodes, with shape (num_nodes, out_channels).
- class DiGCL(in_channels: int, activation: str, num_hidden: int, num_proj_hidden: int, tau: float, num_layers: int)
Bases:
torch.nn.ModuleAn implementation of the DiGCL model from the Directed Graph Contrastive Learning paper.
- Parameters:
in_channels (int) – Dimension of input features.
activation (str) – Activation funciton to use.
num_hidden (int) – Hidden dimension.
num_proj_hidden (int) – Hidden dimension for projection.
tau (float) – Tau value in the loss.
num_layers (int) – Number of layers for encoder.
- encoder
- fc1
- fc2
- reset_parameters()
- forward(x: torch.Tensor, edge_index: torch.Tensor, edge_weight: torch.Tensor = None) torch.Tensor
Making a forward pass of the DiGCL model.
- Arg types:
x (PyTorch FloatTensor) - Node features.
edge_index (PyTorch LongTensor) - Edge indices.
edge_weight (PyTorch FloatTensor, optional) - Edge weights corresponding to edge indices.
- Return types:
x (PyTorch FloatTensor) - Embeddings for all nodes, with shape (num_nodes, out_channels).
- projection(z: torch.Tensor) torch.Tensor
Nonlinear transformation of the input hidden feature.
- Args types::
z (PyTorch FloatTensor) - Node features.
- Return types:
z (PyTorch FloatTensor) - Projected node features.
- sim(z1: torch.Tensor, z2: torch.Tensor)
Normalized similarity calculation.
- Args types::
z1 (PyTorch FloatTensor) - Node features.
z2 (PyTorch FloatTensor) - Node features.
- Return types:
z (PyTorch FloatTensor) - Node-wise similarity.
- semi_loss(z1: torch.Tensor, z2: torch.Tensor)
Semi-supervised loss function.
- Arg types:
z1 (PyTorch FloatTensor) - Node features.
z2 (PyTorch FloatTensor) - Node features.
- Return types:
loss (PyTorch FloatTensor) - Loss.
- batched_semi_loss(z1: torch.Tensor, z2: torch.Tensor, batch_size: int)
Semi-supervised loss function. Space complexity: O(BN) (semi_loss: O(N^2))
- Args types::
z1 (PyTorch FloatTensor) - Node features.
z2 (PyTorch FloatTensor) - Node features.
- Return types:
loss (PyTorch FloatTensor) - Loss.
- loss(z1: torch.Tensor, z2: torch.Tensor, mean: bool = True, batch_size: int = 0)
The DiGCL contrastive loss.
- Arg types:
z1, z2 (PyTorch FloatTensor) - Node hidden representations.
mean (bool, optional) - Whether to return the mean of loss values, default True, otherwise return sum.
batch_size (int, optional) - Batch size, if 0 this means full-batch. Default 0.
- Return types:
ret (PyTorch FloatTensor) - Loss.