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 edgespos_edge_index
and negative edgesneg_edge_index
.- Parameters:
x (torch.Tensor) – The input node features.
pos_edge_index (torch.Tensor) – The positive edge indices.
neg_edge_index (torch.Tensor) – The negative edge indices.
- 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
)
- 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.
- discriminate(z: Tensor, edge_index: Tensor) Tensor [source]
Given node embeddings
z
, classifies the link relation between node pairsedge_index
to be either positive, negative or non-existent.- Parameters:
z (torch.Tensor) – The input node features.
edge_index (torch.Tensor) – The edge indices.
- 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 edgespos_edge_index
and negative nedgesneg_edge_index
.- Parameters:
z (torch.Tensor) – The node embeddings.
pos_edge_index (torch.Tensor) – The positive edge indices.
neg_edge_index (torch.Tensor) – The negative edge indices.
- 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:
z (torch.Tensor) – The node embeddings.
pos_edge_index (torch.Tensor) – The positive edge indices.
- 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:
z (torch.Tensor) – The node embeddings.
neg_edge_index (torch.Tensor) – The negative edge indices.
- loss(z: Tensor, pos_edge_index: Tensor, neg_edge_index: Tensor) Tensor [source]
Computes the overall objective.
- Parameters:
z (torch.Tensor) – The node embeddings.
pos_edge_index (torch.Tensor) – The positive edge indices.
neg_edge_index (torch.Tensor) – The negative edge indices.
- 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:
z (torch.Tensor) – The node embeddings.
pos_edge_index (torch.Tensor) – The positive edge indices.
neg_edge_index (torch.Tensor) – The negative edge indices.