[source]

TopKPool

spektral.layers.TopKPool(ratio, return_mask=False, sigmoid_gating=False, kernel_initializer='glorot_uniform', kernel_regularizer=None, activity_regularizer=None, kernel_constraint=None)

A gPool/Top-K layer as presented by Gao & Ji (2017) and Cangea et al..

This layer computes the following operations:

where returns the indices of the top k values of , and is a learnable parameter vector of size . Note that the the gating operation (Cangea et al.) can be replaced with a sigmoid (Gao & Ji). The original paper by Gao & Ji used a tanh as well, but was later updated to use a sigmoid activation.

Due to the lack of sparse-sparse matrix multiplication support, this layer temporarily makes the adjacency matrix dense in order to compute (needed to preserve connectivity after pooling). If memory is not an issue, considerable speedups can be achieved by using dense graphs directly. Converting a graph from dense to sparse and viceversa is a costly operation.

Mode: single, disjoint.

Input

  • node features of shape (n_nodes, n_features);
  • adjacency matrix of shape (n_nodes, n_nodes);
  • (optional) graph IDs of shape (n_nodes, ) (disjoint mode);

Output

  • reduced node features of shape (n_graphs * k, n_features);
  • reduced adjacency matrix of shape (n_graphs * k, n_graphs * k);
  • reduced graph IDs with shape (n_graphs * k, ) (disjoint mode);
  • If return_mask=True, the binary mask used for pooling, with shape (n_graphs * k, ).

Arguments

  • ratio: float between 0 and 1, ratio of nodes to keep in each graph;
  • return_mask: boolean, whether to return the binary mask used for pooling;
  • sigmoid_gating: boolean, use a sigmoid gating activation instead of a tanh;
  • kernel_initializer: initializer for the kernel matrix;
  • kernel_regularizer: regularization applied to the kernel matrix;
  • activity_regularizer: regularization applied to the output;
  • kernel_constraint: constraint applied to the kernel matrix;

[source]

MinCutPool

spektral.layers.MinCutPool(k, h=None, return_mask=True, activation=None, use_bias=True, kernel_initializer='glorot_uniform', bias_initializer='zeros', kernel_regularizer=None, bias_regularizer=None, activity_regularizer=None, kernel_constraint=None, bias_constraint=None)

A minCUT pooling layer as presented by Bianchi et al..

Mode: single, batch.

This layer computes a soft clustering of the input graphs using a MLP, and reduces graphs as follows:

Besides training the MLP, two additional unsupervised loss terms are minimized to ensure that the cluster assignment solves the minCUT optimization problem. The layer can be used without a supervised loss, to compute node clustering simply by minimizing the unsupervised loss.

Input

  • node features of shape (n_nodes, n_features) (with optional batch dimension);
  • adjacency matrix of shape (n_nodes, n_nodes) (with optional batch dimension);

Output

  • reduced node features of shape (k, n_features);
  • reduced adjacency matrix of shape (k, k);
  • reduced graph IDs with shape (k, ) (disjoint mode);
  • If return_mask=True, the soft assignment matrix used for pooling, with shape (n_nodes, k).

Arguments

  • k: number of nodes to keep;
  • h: number of units in the hidden layer;
  • return_mask: boolean, whether to return the cluster assignment matrix,
  • kernel_initializer: initializer for the kernel matrix;
  • bias_initializer: initializer for the bias vector;
  • kernel_regularizer: regularization applied to the kernel matrix;
  • bias_regularizer: regularization applied to the bias vector;
  • activity_regularizer: regularization applied to the output;
  • kernel_constraint: constraint applied to the kernel matrix;
  • bias_constraint: constraint applied to the bias vector.

[source]

DiffPool

spektral.layers.DiffPool(k, channels=None, return_mask=True, activation=None, kernel_initializer='glorot_uniform', kernel_regularizer=None, activity_regularizer=None, kernel_constraint=None)

A DiffPool layer as presented by Ying et al..

Mode: single, batch.

This layer computes a soft clustering of the input graphs using a GNN, and reduces graphs as follows:

Besides training the GNN, two additional unsupervised loss terms are minimized. The layer also applies a GNN to the input features, and returns the updated graph signal (the number of output channels is controlled by the channels parameter). The layer can be used without a supervised loss, to compute node clustering simply by minimizing the unsupervised loss.

Input

  • node features of shape (n_nodes, n_features) (with optional batch dimension);
  • adjacency matrix of shape (n_nodes, n_nodes) (with optional batch dimension);

Output

  • reduced node features of shape (k, channels);
  • reduced adjacency matrix of shape (k, k);
  • reduced graph IDs with shape (k, ) (disjoint mode);
  • If return_mask=True, the soft assignment matrix used for pooling, with shape (n_nodes, k).

Arguments

  • k: number of nodes to keep;
  • channels: number of output channels (if None, the number of output channels is assumed to be the same as the input);
  • return_mask: boolean, whether to return the cluster assignment matrix,
  • kernel_initializer: initializer for the kernel matrix;
  • kernel_regularizer: regularization applied to the kernel matrix;
  • activity_regularizer: regularization applied to the output;
  • kernel_constraint: constraint applied to the kernel matrix;

[source]

SAGPool

spektral.layers.SAGPool(ratio, return_mask=False, sigmoid_gating=False, kernel_initializer='glorot_uniform', kernel_regularizer=None, activity_regularizer=None, kernel_constraint=None)

A self-attention graph pooling layer as presented by Lee et al. (2019) and Knyazev et al. (2019.

This layer computes the following operations:

where returns the indices of the top k values of , and is a learnable parameter vector of size . The gating operation can be replaced with a sigmoid.

Due to the lack of sparse-sparse matrix multiplication support, this layer temporarily makes the adjacency matrix dense in order to compute (needed to preserve connectivity after pooling). If memory is not an issue, considerable speedups can be achieved by using dense graphs directly. Converting a graph from dense to sparse and viceversa is a costly operation.

Mode: single, disjoint.

Input

  • node features of shape (n_nodes, n_features);
  • adjacency matrix of shape (n_nodes, n_nodes);
  • (optional) graph IDs of shape (n_nodes, ) (disjoint mode);

Output

  • reduced node features of shape (n_graphs * k, n_features);
  • reduced adjacency matrix of shape (n_graphs * k, n_graphs * k);
  • reduced graph IDs with shape (n_graphs * k, ) (disjoint mode);
  • If return_mask=True, the binary mask used for pooling, with shape (n_graphs * k, ).

Arguments

  • ratio: float between 0 and 1, ratio of nodes to keep in each graph;
  • return_mask: boolean, whether to return the binary mask used for pooling;
  • sigmoid_gating: boolean, use a sigmoid gating activation instead of a tanh;
  • kernel_initializer: initializer for the kernel matrix;
  • kernel_regularizer: regularization applied to the kernel matrix;
  • activity_regularizer: regularization applied to the output;
  • kernel_constraint: constraint applied to the kernel matrix;

[source]

GlobalSumPool

spektral.layers.GlobalSumPool()

A global sum pooling layer. Pools a graph by computing the sum of its node features.

Mode: single, mixed, batch, disjoint.

Input

  • node features of shape (n_nodes, n_features) (with optional batch dimension);
  • (optional) graph IDs of shape (n_nodes, ) (disjoint mode);

Output

  • tensor like node features, but without node dimension (except for single mode, where the node dimension is preserved and set to 1).

Arguments

None.


[source]

GlobalAvgPool

spektral.layers.GlobalAvgPool()

An average pooling layer. Pools a graph by computing the average of its node features.

Mode: single, mixed, batch, disjoint.

Input

  • node features of shape (n_nodes, n_features) (with optional batch dimension);
  • (optional) graph IDs of shape (n_nodes, ) (disjoint mode);

Output

  • tensor like node features, but without node dimension (except for single mode, where the node dimension is preserved and set to 1).

Arguments

None.


[source]

GlobalMaxPool

spektral.layers.GlobalMaxPool()

A max pooling layer. Pools a graph by computing the maximum of its node features.

Mode: single, mixed, batch, disjoint.

Input

  • node features of shape (n_nodes, n_features) (with optional batch dimension);
  • (optional) graph IDs of shape (n_nodes, ) (disjoint mode);

Output

  • tensor like node features, but without node dimension (except for single mode, where the node dimension is preserved and set to 1).

Arguments

None.


[source]

GlobalAttentionPool

spektral.layers.GlobalAttentionPool(channels=32, kernel_initializer='glorot_uniform', bias_initializer='zeros', kernel_regularizer=None, bias_regularizer=None, activity_regularizer=None, kernel_constraint=None, bias_constraint=None)

A gated attention global pooling layer as presented by Li et al. (2017).

Mode: single, mixed, batch, disjoint.

Input

  • node features of shape (n_nodes, n_features) (with optional batch dimension);
  • (optional) graph IDs of shape (n_nodes, ) (disjoint mode);

Output

  • tensor like node features, but without node dimension (except for single mode, where the node dimension is preserved and set to 1), and last dimension changed to channels.

Arguments

  • channels: integer, number of output channels;
  • bias_initializer: initializer for the bias vector;
  • kernel_regularizer: regularization applied to the kernel matrix;
  • bias_regularizer: regularization applied to the bias vector;
  • activity_regularizer: regularization applied to the output;
  • kernel_constraint: constraint applied to the kernel matrix;
  • bias_constraint: constraint applied to the bias vector.

[source]

GlobalAttnSumPool

spektral.layers.GlobalAttnSumPool(attn_kernel_initializer='glorot_uniform', kernel_regularizer=None, attn_kernel_regularizer=None, attn_kernel_constraint=None)

A node-attention global pooling layer. Pools a graph by learning attention coefficients to sum node features.

Mode: single, mixed, batch, disjoint.

Input

  • node features of shape (n_nodes, n_features) (with optional batch dimension);
  • (optional) graph IDs of shape (n_nodes, ) (disjoint mode);

Output

  • tensor like node features, but without node dimension (except for single mode, where the node dimension is preserved and set to 1).

Arguments

  • attn_kernel_initializer: initializer for the attention kernel matrix;
  • kernel_regularizer: regularization applied to the kernel matrix;
  • attn_kernel_regularizer: regularization applied to the attention kernel matrix;
  • attn_kernel_constraint: constraint applied to the attention kernel matrix;