torch_geometric.nn.models.SignedGCN

class SignedGCN(in_channels: int, hidden_channels: int, num_layers: int, lamb: float = 5, bias: bool = True)[source]

Bases: Module

The signed graph convolutional network model from the “Signed Graph Convolutional Network” paper. Internally, this module uses the torch_geometric.nn.conv.SignedConv operator.

Parameters:
  • in_channels (int) – Size of each input sample.

  • hidden_channels (int) – Size of each hidden sample.

  • num_layers (int) – Number of layers.

  • lamb (float, optional) – Balances the contributions of the overall objective. (default: 5)

  • bias (bool, optional) – If set to False, all layers will not learn an additive bias. (default: True)

forward(x: Tensor, pos_edge_index: Tensor, neg_edge_index: Tensor) Tensor[source]

Computes node embeddings z based on positive edges pos_edge_index and negative edges neg_edge_index.

Parameters:
Return type:

Tensor

reset_parameters()[source]

Resets all learnable parameters of the module.

split_edges(edge_index: Tensor, test_ratio: float = 0.2) Tuple[Tensor, Tensor][source]

Splits the edges edge_index into train and test edges.

Parameters:
  • edge_index (LongTensor) – The edge indices.

  • test_ratio (float, optional) – The ratio of test edges. (default: 0.2)

Return type:

Tuple[Tensor, Tensor]

create_spectral_features(pos_edge_index: Tensor, neg_edge_index: Tensor, num_nodes: Optional[int] = None) Tensor[source]

Creates in_channels spectral node features based on positive and negative edges.

Parameters:
  • pos_edge_index (LongTensor) – The positive edge indices.

  • neg_edge_index (LongTensor) – The negative edge indices.

  • num_nodes (int, optional) – The number of nodes, i.e. max_val + 1 of pos_edge_index and neg_edge_index. (default: None)

Return type:

Tensor

discriminate(z: Tensor, edge_index: Tensor) Tensor[source]

Given node embeddings z, classifies the link relation between node pairs edge_index to be either positive, negative or non-existent.

Parameters:
Return type:

Tensor

nll_loss(z: Tensor, pos_edge_index: Tensor, neg_edge_index: Tensor) Tensor[source]

Computes the discriminator loss based on node embeddings z, and positive edges pos_edge_index and negative nedges neg_edge_index.

Parameters:
Return type:

Tensor

pos_embedding_loss(z: Tensor, pos_edge_index: Tensor) Tensor[source]

Computes the triplet loss between positive node pairs and sampled non-node pairs.

Parameters:
Return type:

Tensor

neg_embedding_loss(z: Tensor, neg_edge_index: Tensor) Tensor[source]

Computes the triplet loss between negative node pairs and sampled non-node pairs.

Parameters:
Return type:

Tensor

loss(z: Tensor, pos_edge_index: Tensor, neg_edge_index: Tensor) Tensor[source]

Computes the overall objective.

Parameters:
Return type:

Tensor

test(z: Tensor, pos_edge_index: Tensor, neg_edge_index: Tensor) Tuple[float, float][source]

Evaluates node embeddings z on positive and negative test edges by computing AUC and F1 scores.

Parameters:
Return type:

Tuple[float, float]