torch_geometric.nn.conv.PNAConv

class PNAConv(in_channels: int, out_channels: int, aggregators: List[str], scalers: List[str], deg: Tensor, edge_dim: Optional[int] = None, towers: int = 1, pre_layers: int = 1, post_layers: int = 1, divide_input: bool = False, act: Optional[Union[str, Callable]] = 'relu', act_kwargs: Optional[Dict[str, Any]] = None, train_norm: bool = False, **kwargs)[source]

Bases: MessagePassing

来自“Principal Neighbourhood Aggregation for Graph Nets”论文的主邻域聚合图卷积算子。

\[\mathbf{x}_i^{\prime} = \gamma_{\mathbf{\Theta}} \left( \mathbf{x}_i, \underset{j \in \mathcal{N}(i)}{\bigoplus} h_{\mathbf{\Theta}} \left( \mathbf{x}_i, \mathbf{x}_j \right) \right)\]

使用

\[\begin{split}\bigoplus = \underbrace{\begin{bmatrix} 1 \\ S(\mathbf{D}, \alpha=1) \\ S(\mathbf{D}, \alpha=-1) \end{bmatrix} }_{\text{scalers}} \otimes \underbrace{\begin{bmatrix} \mu \\ \sigma \\ \max \\ \min \end{bmatrix}}_{\text{aggregators}},\end{split}\]

其中 \(\gamma_{\mathbf{\Theta}}\)\(h_{\mathbf{\Theta}}\) 表示多层感知机。

注意

有关使用 PNAConv 的示例,请参见 examples/pna.py

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.

  • aggregators (List[str]) – 聚合函数标识符的集合, 即 "sum", "mean", "min", "max", "var""std"

  • scalers (List[str]) – 一组缩放函数标识符,即 "identity", "amplification", "attenuation", "linear""inverse_linear"

  • deg (torch.Tensor) – 训练集中节点的入度直方图,用于缩放器进行归一化。

  • edge_dim (int, optional) – 边的特征维度(如果有的话)。(默认 None)

  • towers (int, optional) – 塔的数量(默认值:1)。

  • pre_layers (int, optional) – 聚合前的转换层数(默认值:1)。

  • post_layers (int, optional) – 聚合后的转换层数(默认:1)。

  • divide_input (bool, optional) – 输入特征是否应该在塔之间分割(默认:False)。

  • act (strcallable, 可选) – 用于层前后的激活函数。(默认:"relu"

  • act_kwargs (Dict[str, Any], optional) – Arguments passed to the respective activation function defined by act. (default: None)

  • train_norm (bool, optional) – Whether normalization parameters are trainable. (default: False)

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

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

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

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

运行模块的前向传播。

Return type:

Tensor

reset_parameters()[source]

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

static get_degree_histogram(loader: DataLoader) Tensor[source]

返回用于作为PNAConvdeg参数的输入的度直方图。

Return type:

Tensor