torch_geometric.nn.conv.HypergraphConv

class HypergraphConv(in_channels: int, out_channels: int, use_attention: bool = False, attention_mode: str = 'node', heads: int = 1, concat: bool = True, negative_slope: float = 0.2, dropout: float = 0, bias: bool = True, **kwargs)[source]

Bases: MessagePassing

来自“超图卷积和超图注意力”论文的超图卷积算子。

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

其中 \(\mathbf{H} \in {\{ 0, 1 \}}^{N \times M}\) 是关联矩阵,\(\mathbf{W} \in \mathbb{R}^M\) 是对角超边权重矩阵,而 \(\mathbf{D}\)\(\mathbf{B}\) 是对应的度矩阵。

例如,在超图场景中 \(\mathcal{G} = (\mathcal{V}, \mathcal{E})\) 其中 \(\mathcal{V} = \{ 0, 1, 2, 3 \}\)\(\mathcal{E} = \{ \{ 0, 1, 2 \}, \{ 1, 2, 3 \} \}\)hyperedge_index 表示为:

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, 可选) – 如果设置为 True,将会在这一层添加注意力机制。(默认值:False

  • attention_mode (str, optional) – 计算注意力的模式。 如果设置为 "node",将计算属于同一超边的所有节点之间的注意力分数。 如果设置为 "edge",将计算包含该节点的所有边之间的注意力分数。 (默认: "node")

  • 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:
  • 输入: 节点特征 \((|\mathcal{V}|, F_{in})\), 超边索引 \((|\mathcal{V}|, |\mathcal{E}|)\), 超边权重 \((|\mathcal{E}|)\) (可选) 超边特征 \((|\mathcal{E}|, D)\) (可选)

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

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

运行模块的前向传播。

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

  • hyperedge_index (torch.Tensor) – 超边索引, 稀疏关联矩阵 \(\mathbf{H} \in {\{ 0, 1 \}}^{N \times M}\) 从 节点映射到边。

  • hyperedge_weight (torch.Tensor, optional) – 超边权重 \(\mathbf{W} \in \mathbb{R}^M\). (默认: None)

  • hyperedge_attr (torch.Tensor, optional) – 超边特征矩阵 在 \(\mathbb{R}^{M \times F}\) 中。 这些特征仅在 use_attention=True 时需要传入。(默认值:None

  • num_edges (int, optional) – 边的数量 \(M\)。 (default: None)

Return type:

Tensor

reset_parameters()[source]

重置模块的所有可学习参数。