torch_geometric_signed_directed.nn.directed.DiGCL ================================================= .. py:module:: torch_geometric_signed_directed.nn.directed.DiGCL Classes ------- .. autoapisummary:: torch_geometric_signed_directed.nn.directed.DiGCL.DiGCL_Encoder torch_geometric_signed_directed.nn.directed.DiGCL.DiGCL Module Contents --------------- .. py:class:: DiGCL_Encoder(in_channels: int, out_channels: int, activation: str, num_layers: int = 2) Bases: :py:obj:`torch.nn.Module` An 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) .. py:attribute:: conv .. py:attribute:: activation .. py:method:: reset_parameters() .. py:method:: 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). .. py:class:: DiGCL(in_channels: int, activation: str, num_hidden: int, num_proj_hidden: int, tau: float, num_layers: int) Bases: :py:obj:`torch.nn.Module` An 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. .. py:attribute:: encoder .. py:attribute:: tau :type: float .. py:attribute:: fc1 .. py:attribute:: fc2 .. py:method:: reset_parameters() .. py:method:: 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). .. py:method:: 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. .. py:method:: 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. .. py:method:: 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. .. py:method:: 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. .. py:method:: 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.