morphoclass.layers.cheb_conv module¶
Implementation of the ChebConv layer.
-
class
morphoclass.layers.cheb_conv.ChebConv(in_channels, out_channels, K, bias=True, flow='target_to_source', **kwargs)¶ Bases:
torch_geometric.nn.conv.message_passing.MessagePassingChebConv layer based on torch_geometric.nn.conv.ChebConv.
This implementation corrects a few things that were not quite correct in the original implementation:
Initialization set to glorot rather then uniform
The default flow is set to target_to_source. This way the call self.propagate(…) computes M @ x rather than M.T @ x.
The computation of the normalised Laplacian
These points might be implemented in future versions of PyG so that this implementation will become redundant.
- Parameters
in_channels (int) – Size of each input sample.
out_channels (int) – Size of each output sample.
K (int) – Chebyshev filter size, i.e. number of hops \(K\).
bias (bool, default True) – If set to
False, the layer will not learn an additive bias.**kwargs – Additional arguments of torch_geometric.nn.conv.MessagePassing.
-
forward(x, edge_index, edge_weight=None, batch=None, lambda_max=3.0)¶ Compute the forward pass.
- Parameters
x – The batched input node features.
edge_index – The batched input adjacency matrices.
edge_weight – The edge weights.
batch – Not used?
lambda_max (float) – The lambda_max value to use for the normalization of the graph Laplacian.
- Returns
out – The output feature maps.
- Return type
torch.Tensor
-
message(x_j, norm)¶ Perform a message passing step.
- Parameters
x_j – Node features.
norm – The edge weights (?). See documentation of pytorch-geometric for more details.
- Returns
The result of message passing.
- Return type
torch.Tensor
-
static
norm(edge_index, num_nodes, edge_weight, dtype=None, lambda_max=3.0)¶ Given the adjacency matrix calculate the normalised Laplacian.
- Parameters
edge_index – The edge indices of the adjacency matrix.
num_nodes – The number of nodes in the graph, the adjacency matrix is of dimension (num_nodes, num_nodes).
edge_weight – The entries in the adjacency matrix index by edge_index
dtype – The dtype of the adjacency matrix.
lambda_max – The pre-computed maximal eigenvalue of the normalised Laplacian. Note that in the original PyG implementation this was implicitly assumed to have value 2.0.
- Returns
The sparse form of the normalised graph Laplacian.
- Return type
edge_index, norm
-
reset_parameters()¶ Initialize all weights with Glorot and set all biases to zero.