HMPNN_Layer#

HMPNN (Hypergraph Message Passing Neural Network) Layer introduced in Heydari et Livi 2022.

class topomodelx.nn.hypergraph.hmpnn_layer.HMPNNLayer(in_channels, node_to_hyperedge_messaging_func=None, hyperedge_to_node_messaging_func=None, adjacency_dropout: float = 0.7, aggr_func: Literal['sum', 'mean', 'add'] = 'sum', updating_dropout: float = 0.5, updating_func=None, **kwargs)[source]#

HMPNN Layer [1].

The layer is a hypergraph comprised of nodes and hyperedges that makes their new reprsentation using the input representation and the messages passed between them. In this layer, the message passed from a node to its neighboring hyperedges is only a function of its input representation, but the message from a hyperedge to its neighboring nodes is also a function of the messages recieved from them beforehand. This way, a node could have a more explicit effect on its upper adjacent neighbors i.e. the nodes that it share a hyperedge with.

\[\begin{split}\begin{align*} &πŸŸ₯ \quad m_{{y \rightarrow z}}^{(0 \rightarrow 1)} = M_\mathcal{C} (h_y^{t,(0)}, h_z^{t, (1)})\\ &🟧 \quad m_{z'}^{(0 \rightarrow 1)} = AGG'{y \in \mathcal{B}(z)} m_{y \rightarrow z}^{(0\rightarrow1)}\\ &🟧 \quad m_{z}^{(0 \rightarrow 1)} = AGG_{y \in \mathcal{B}(z)} m_{y \rightarrow z}^{(0 \rightarrow 1)}\\ &πŸŸ₯ \quad m_{z \rightarrow x}^{(1 \rightarrow0)} = M_\mathcal{B}(h_z^{t,(1)}, m_z^{(1)})\\ &🟧 \quad m_x^{(1 \rightarrow0)} = AGG_{z \in \mathcal{C}(x)} m_{z \rightarrow x}^{(1 \rightarrow0)}\\ &🟩 \quad m_x^{(0)} = m_x^{(1 \rightarrow 0)}\\ &🟩 \quad m_z^{(1)} = m_{z'}^{(0 \rightarrow 1)}\\ &🟦 \quad h_x^{t+1, (0)} = U^{(0)}(h_x^{t,(0)}, m_x^{(0)})\\ &🟦 \quad h_z^{t+1,(1)} = U^{(1)}(h_z^{t,(1)}, m_{z}^{(1)}) \end{align*}\end{split}\]
Parameters:
in_channelsint

Dimension of input features.

node_to_hyperedge_messaging_funcNone

Node messaging function as a callable or nn.Module object. If not given, a linear plus sigmoid function is used, according to the paper.

hyperedge_to_node_messaging_funcNone

Hyperedge messaging function as a callable or nn.Module object. It gets hyperedge input features and aggregated messages of nodes as input and returns hyperedge messages. If not given, two inputs are concatenated and a linear layer reducing back to in_channels plus sigmoid is applied, according to the paper.

adjacency_dropoutint, default = 0.7

Adjacency dropout rate.

aggr_funcLiteral[β€œsum”, β€œmean”, β€œadd”], default=”sum”

Message aggregation function.

updating_dropoutint, default = 0.5

Regular dropout rate applied to node and hyperedge features.

updating_funccallable or None, default = None

The final function or nn.Module object to be called on node and hyperedge features to retrieve their new representation. If not given, a linear layer is applied, received message is added and sigmoid is called.

**kwargsoptional

Additional arguments for the layer modules.

References

[1]

Heydari S, Livi L. Message passing neural networks for hypergraphs. ICANN 2022. https://arxiv.org/abs/2203.16995

apply_regular_dropout(x)[source]#

Apply regular dropout according to the paper.

Unmasked features in a vector are scaled by d+k / d in which k is the number of masked features in the vector and d is the total number of features.

Parameters:
xtorch.Tensor

Input features.

Returns:
torch.Tensor

Output features.

forward(x_0, x_1, incidence_1)[source]#

Forward computation.

Parameters:
x_0torch.Tensor, shape = (n_nodes, node_in_channels)

Input features of the nodes.

x_1torch.Tensor, shape = (n_edges, hyperedge_in_channels)

Input features of the hyperedges.

incidence_1torch.sparse.Tensor, shape = (n_nodes, n_edges)

Incidence matrix mapping hyperedges to nodes (B_1).

Returns:
x_0torch.Tensor, shape = (n_nodes, node_in_channels)

Output features of the nodes.

x_1torch.Tensor, shape = (n_edges, hyperedge_in_channels)

Output features of the hyperedges.