morphoclass.layers.bidirectional_block module

Implementation of the BidirectionalBlock layer.

class morphoclass.layers.bidirectional_block.BidirectionalBlock(c_in, c_out, K=5, normalization='sym', lambda_max=3.0, flow='target_to_source')

Bases: torch.nn.modules.module.Module

A parallel pair of ChebConv layers with opposite edge directions.

Parameters
  • c_in (int) – The number of input channels.

  • c_out (int) – The number of output channels.

  • K (int) – The maximal order of the Chebyshev polynomials

  • normalization ({"sym", "rw", None}) – The type of the graph Laplacian normalization. See ChebConv for more details.

  • lambda_max (float) – The value for replacing the highest graph Laplacian eigenvalue with. Eigenvalues of the graph Laplacian can only be reliably used for undirected graphs. This layer, however, makes most sense for directed graphs. In oder to still be able to normalize the graph Laplacian it was decided to use a fix value. Experiments show that this approach is effective.

  • flow ({"target_to_source", "source_to_target"}) – The direction of the message passing flow in the ChebConv layers. This is not exactly the same as transposing the adjacency matrix, probably due to the asymmetric way the normalization of the graph Laplacian works.

forward(x, edge_index, edge_weight=None)

Compute the forward pass.

Parameters
  • x (torch.Tensor) – A batch of node features.

  • edge_index (torch.Tensor) – A batch of adjacency matrices.

  • edge_weight (torch.Tensor) – A batch of edge weights.

Returns

x – The output node features.

Return type

torch.Tensor

training: bool