torch_geometric.nn.conv.GeneralConv

class GeneralConv(in_channels: Union[int, Tuple[int, int]], out_channels: Optional[int], in_edge_channels: Optional[int] = None, aggr: str = 'add', skip_linear: str = False, directed_msg: bool = True, heads: int = 1, attention: bool = False, attention_type: str = 'additive', l2_normalize: bool = False, bias: bool = True, **kwargs)[source]

Bases: MessagePassing

一个通用的GNN层,改编自“图神经网络的设计空间”论文。

Parameters:
  • in_channels (int or tuple) – Size of each input sample, or -1 to derive the size from the first input(s) to the forward method. A tuple corresponds to the sizes of source and target dimensionalities.

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

  • in_edge_channels (int, optional) – 每个输入边的大小。 (默认: None)

  • aggr (str, optional) – The aggregation scheme to use ("add", "mean", "max"). (default: "mean")

  • skip_linear (bool, optional) – 是否在跳跃连接中应用线性函数。(默认: False)

  • directed_msg (bool, optional) – 如果消息传递是定向的; 否则,消息传递是双向的。(默认值:True

  • heads (int, optional) – 消息传递集合的数量。 如果 heads > 1,GNN 层将输出多个消息的集合。 如果使用了注意力机制 (attention=True),这对应于多头注意力机制。(默认值:1

  • 注意 (bool, 可选) – 是否在消息计算中添加注意力机制。(默认值:False

  • attention_type (str, optional) – 注意力类型: "additive", "dot_product". (默认: "additive")

  • l2_normalize (bool, 可选) – 如果设置为 True, 输出特征 将会被 \(\ell_2\)-归一化, , \(\frac{\mathbf{x}^{\prime}_i} {\| \mathbf{x}^{\prime}_i \|_2}\). (默认: False)

  • 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})\) or \(((|\mathcal{V_s}|, F_{s}), (|\mathcal{V_t}|, F_{t}))\) if bipartite, edge indices \((2, |\mathcal{E}|)\), edge attributes \((|\mathcal{E}|, D)\) (optional)

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

forward(x: Union[Tensor, Tuple[Tensor, Optional[Tensor]]], edge_index: Union[Tensor, SparseTensor], edge_attr: Optional[Tensor] = None, size: Optional[Tuple[int, int]] = None) Tensor[source]

运行模块的前向传播。

Return type:

Tensor

reset_parameters()[source]

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