torch_geometric.nn.pool.EdgePooling — pytorch_geometric documentation (original) (raw)

class EdgePooling(in_channels: int, edge_score_method: Optional[Callable] = None, dropout: float = 0.0, add_to_edge_score: float = 0.5)[source]

Bases: Module

The edge pooling operator from the “Towards Graph Pooling by Edge Contraction” and“Edge Contraction Pooling for Graph Neural Networks” papers.

In short, a score is computed for each edge. Edges are contracted iteratively according to that score unless one of their nodes has already been part of a contracted edge.

To duplicate the configuration from the “Towards Graph Pooling by Edge Contraction” paper, use either EdgePooling.compute_edge_score_softmax()or EdgePooling.compute_edge_score_tanh(), and setadd_to_edge_score to 0.0.

To duplicate the configuration from the “Edge Contraction Pooling for Graph Neural Networks” paper, set dropout to 0.2.

Parameters:

reset_parameters()[source]

Resets all learnable parameters of the module.

static compute_edge_score_softmax(raw_edge_score: Tensor, edge_index: Tensor, num_nodes: int) → Tensor[source]

Normalizes edge scores via softmax application.

Return type:

Tensor

static compute_edge_score_tanh(raw_edge_score: Tensor, edge_index: Optional[Tensor] = None, num_nodes: Optional[int] = None) → Tensor[source]

Normalizes edge scores via hyperbolic tangent application.

Return type:

Tensor

static compute_edge_score_sigmoid(raw_edge_score: Tensor, edge_index: Optional[Tensor] = None, num_nodes: Optional[int] = None) → Tensor[source]

Normalizes edge scores via sigmoid application.

Return type:

Tensor

forward(x: Tensor, edge_index: Tensor, batch: Tensor) → Tuple[Tensor, Tensor, Tensor, UnpoolInfo][source]

Forward pass.

Parameters:

Return types:

Return type:

Tuple[Tensor, Tensor, Tensor, UnpoolInfo]

unpool(x: Tensor, unpool_info: UnpoolInfo) → Tuple[Tensor, Tensor, Tensor][source]

Unpools a previous edge pooling step.

For unpooling, x should be of same shape as those produced by this layer’s forward() function. Then, it will produce an unpooled x in addition to edge_index and batch.

Parameters:

Return types:

Return type:

Tuple[Tensor, Tensor, Tensor]