# torch_geometric.nn.conv.HypergraphConv

class HypergraphConv(in_channels, out_channels, use_attention=False, heads=1, concat=True, negative_slope=0.2, dropout=0, bias=True, **kwargs)[source]

Bases: MessagePassing

The hypergraph convolutional operator from the “Hypergraph Convolution and Hypergraph Attention” paper

$\mathbf{X}^{\prime} = \mathbf{D}^{-1} \mathbf{H} \mathbf{W} \mathbf{B}^{-1} \mathbf{H}^{\top} \mathbf{X} \mathbf{\Theta}$

where $$\mathbf{H} \in {\{ 0, 1 \}}^{N \times M}$$ is the incidence matrix, $$\mathbf{W} \in \mathbb{R}^M$$ is the diagonal hyperedge weight matrix, and $$\mathbf{D}$$ and $$\mathbf{B}$$ are the corresponding degree matrices.

For example, in the hypergraph scenario $$\mathcal{G} = (\mathcal{V}, \mathcal{E})$$ with $$\mathcal{V} = \{ 0, 1, 2, 3 \}$$ and $$\mathcal{E} = \{ \{ 0, 1, 2 \}, \{ 1, 2, 3 \} \}$$, the hyperedge_index is represented as:

hyperedge_index = torch.tensor([
[0, 1, 2, 1, 2, 3],
[0, 0, 0, 1, 1, 1],
])

Parameters
• in_channels (int) – Size of each input sample, or -1 to derive the size from the first input(s) to the forward method.

• out_channels (int) – Size of each output sample.

• use_attention (bool, optional) – If set to True, attention will be added to this layer. (default: False)

• heads (int, optional) – Number of multi-head-attentions. (default: 1)

• concat (bool, optional) – If set to False, the multi-head attentions are averaged instead of concatenated. (default: True)

• negative_slope (float, optional) – LeakyReLU angle of the negative slope. (default: 0.2)

• dropout (float, optional) – Dropout probability of the normalized attention coefficients which exposes each node to a stochastically sampled neighborhood during training. (default: 0)

• bias (bool, optional) – If set to False, the layer will not learn an additive bias. (default: True)

• **kwargs (optional) – Additional arguments of torch_geometric.nn.conv.MessagePassing.

Shapes:
• input: node features $$(|\mathcal{V}|, F_{in})$$, hyperedge indices $$(|\mathcal{V}|, |\mathcal{E}|)$$, hyperedge weights $$(|\mathcal{E}|)$$ (optional) hyperedge features $$(|\mathcal{E}|, D)$$ (optional)

• output: node features $$(|\mathcal{V}|, F_{out})$$

forward(x: Tensor, hyperedge_index: Tensor, hyperedge_weight: = None, hyperedge_attr: = None) [source]

Runs the forward pass of the module.

Parameters
• x (torch.Tensor) – Node feature matrix $$\mathbf{X} \in \mathbb{R}^{N \times F}$$.

• hyperedge_index (torch.Tensor) – The hyperedge indices, i.e. the sparse incidence matrix $$\mathbf{H} \in {\{ 0, 1 \}}^{N \times M}$$ mapping from nodes to edges.

• hyperedge_weight (torch.Tensor, optional) – Hyperedge weights $$\mathbf{W} \in \mathbb{R}^M$$. (default: None)

• hyperedge_attr (torch.Tensor, optional) – Hyperedge feature matrix in $$\mathbb{R}^{M \times F}$$. These features only need to get passed in case use_attention=True. (default: None)

reset_parameters()[source]

Resets all learnable parameters of the module.