Skip to content

Dense Layers

The k3_node.layers.dense module implements dense tensor graph operations operating on dense adjacency matrices of shape (batch_size, num_nodes, num_nodes).


Dense Convolutions

DenseGCNConv

k3_node.layers.dense.DenseGCNConv

Bases: Layer

Applies the dense convolutional operator from the "Semi-supervised Classification with Graph Convolutional Networks" <https://arxiv.org/abs/1609.02907>_ paper.

.. math:: \mathbf{X}^{\prime} = \mathbf{\tilde{D}}^{-1/2} \mathbf{\tilde{A}} \mathbf{\tilde{D}}^{-1/2} \mathbf{X} \mathbf{\Theta}

Parameters:

Name Type Description Default
in_channels int

Size of each input sample.

required
out_channels int

Size of each output sample.

required
improved bool

If set to :obj:True, the layer computes :math:\mathbf{\tilde{A}} = \mathbf{A} + 2 \mathbf{I}. (default: :obj:False)

False
bias bool

If set to :obj:False, the layer will not learn an additive bias. (default: :obj:True)

True

DenseGATConv

k3_node.layers.dense.DenseGATConv

Bases: Layer

See :class:torch_geometric.nn.conv.GATConv.

DenseGINConv

k3_node.layers.dense.DenseGINConv

Bases: Layer

Applies the dense Graph Isomorphism Network (GIN) convolutional operator from the "How Powerful are Graph Neural Networks?" <https://arxiv.org/abs/1810.00826>_ paper.

.. math:: \mathbf{X}^{\prime} = \mathrm{MLP} \left( \left( \mathbf{A} + (1 + \epsilon) \cdot \mathbf{I} \right) \cdot \mathbf{X} \right)

Parameters:

Name Type Description Default
nn callable

A neural network layer (e.g. MLP or Dense) mapping feature representations to output representations.

required
eps float

(Initial) :math:\epsilon-value. (default: :obj:0.0)

0.0
train_eps bool

If set to :obj:True, :math:\epsilon will be a trainable parameter. (default: :obj:False)

False

DenseGraphConv

k3_node.layers.dense.DenseGraphConv

Bases: Layer

See :class:torch_geometric.nn.conv.GraphConv.

DenseSAGEConv

k3_node.layers.dense.DenseSAGEConv

Bases: Layer

See :class:torch_geometric.nn.conv.SAGEConv.


Dense Pooling

DMoNPooling

k3_node.layers.dense.DMoNPooling

Bases: Layer

The spectral modularity pooling operator from the "Graph Clustering with Graph Neural Networks" <https://arxiv.org/abs/2006.16904>_ paper.

.. math:: \mathbf{X}^{\prime} &= {\mathrm{softmax}(\mathbf{S})}^{\top} \cdot \mathbf{X}

\mathbf{A}^{\prime} &= {\mathrm{softmax}(\mathbf{S})}^{\top} \cdot
\mathbf{A} \cdot \mathrm{softmax}(\mathbf{S})

Parameters:

Name Type Description Default
channels int or List[int]

Size of each input sample. If given as a list, will construct an MLP based on the given feature sizes.

required
k int

The number of clusters.

required
dropout float

Dropout probability. (default: :obj:0.0)

0.0

call(x, adj, mask=None, training=False)

Forward pass.

Parameters:

Name Type Description Default
x

Node feature tensor [B, N, F] or [N, F].

required
adj

Adjacency tensor [B, N, N] or [N, N].

required
mask Optional[any]

Mask tensor [B, N] indicating valid nodes. (default: None)

None
training bool

Whether layer is in training mode.

False

reset_parameters()

Resets all learnable parameters of the module.

dense_diff_pool

k3_node.layers.dense.dense_diff_pool(x, adj, s, mask=None, normalize=True)

The differentiable pooling operator from the "Hierarchical Graph Representation Learning with Differentiable Pooling" <https://arxiv.org/abs/1806.08804>_ paper.

.. math:: \mathbf{X}^{\prime} &= {\mathrm{softmax}(\mathbf{S})}^{\top} \cdot \mathbf{X}

\mathbf{A}^{\prime} &= {\mathrm{softmax}(\mathbf{S})}^{\top} \cdot
\mathbf{A} \cdot \mathrm{softmax}(\mathbf{S})

Parameters:

Name Type Description Default
x

Node feature tensor [B, N, F] or [N, F].

required
adj

Adjacency tensor [B, N, N] or [N, N].

required
s

Assignment tensor [B, N, C] or [N, C].

required
mask Optional[any]

Mask tensor [B, N] indicating valid nodes. (default: None)

None
normalize bool

If set to False, link prediction loss is not divided by total elements.

True

dense_mincut_pool

k3_node.layers.dense.dense_mincut_pool(x, adj, s, mask=None, temp=1.0)

The MinCut pooling operator from the "Spectral Clustering in Graph Neural Networks for Graph Pooling" <https://arxiv.org/abs/1907.00481>_ paper.

.. math:: \mathbf{X}^{\prime} &= {\mathrm{softmax}(\mathbf{S})}^{\top} \cdot \mathbf{X}

\mathbf{A}^{\prime} &= {\mathrm{softmax}(\mathbf{S})}^{\top} \cdot
\mathbf{A} \cdot \mathrm{softmax}(\mathbf{S})

Parameters:

Name Type Description Default
x

Node feature tensor [B, N, F] or [N, F].

required
adj

Adjacency tensor [B, N, N] or [N, N].

required
s

Assignment tensor [B, N, C] or [N, C].

required
mask Optional[any]

Mask tensor [B, N] indicating valid nodes. (default: None)

None
temp float

Temperature parameter for softmax function. (default: 1.0)

1.0

Dense Linear Layers

Linear

k3_node.layers.dense.Linear

Bases: Layer

Applies a linear transformation to the incoming data:

.. math:: \mathbf{x}^{\prime} = \mathbf{x} \mathbf{W} + \mathbf{b}

Parameters:

Name Type Description Default
in_channels int

Size of each input sample.

required
out_channels int

Size of each output sample.

required
bias bool

If set to :obj:False, the layer will not learn an additive bias. (default: :obj:True)

True
weight_initializer str

The initializer for the weight matrix (:obj:"glorot", :obj:"uniform", :obj:"kaiming_uniform" or :obj:None). (default: :obj:None)

None
bias_initializer str

The initializer for the bias vector (:obj:"zeros" or :obj:None). (default: :obj:None)

None

HeteroLinear

k3_node.layers.dense.HeteroLinear

Bases: Layer

Applies separate linear transformations to the incoming data according to types.

.. math:: \mathbf{x}^{\prime}i = \mathbf{x}_i \mathbf{\Theta} + \mathbf{b}_{\kappa_i}

Parameters:

Name Type Description Default
in_channels int

Size of each input sample.

required
out_channels int

Size of each output sample.

required
num_types int

The number of types.

required
is_sorted bool

If set to :obj:True, assumes that :obj:type_vec is sorted. (default: :obj:False)

False
bias bool

If set to :obj:False, the layer will not learn an additive bias. (default: :obj:True)

True
weight_initializer str

The initializer for the weight matrix (:obj:"glorot", :obj:"uniform", :obj:"kaiming_uniform" or :obj:None). (default: :obj:None)

None
bias_initializer str

The initializer for the bias vector (:obj:"zeros" or :obj:None). (default: :obj:None)

None