torch_geometric.nn.norm.PairNorm

class PairNorm(scale: float = 1.0, scale_individually: bool = False, eps: float = 1e-05)[source]

Bases: Module

应用节点特征上的对归一化,如“PairNorm: Tackling Oversmoothing in GNNs”论文中所述。

\[ \begin{align}\begin{aligned}\begin{split}\mathbf{x}_i^c &= \mathbf{x}_i - \frac{1}{n} \sum_{i=1}^n \mathbf{x}_i \\\end{split}\\\mathbf{x}_i^{\prime} &= s \cdot \frac{\mathbf{x}_i^c}{\sqrt{\frac{1}{n} \sum_{i=1}^n {\| \mathbf{x}_i^c \|}^2_2}}\end{aligned}\end{align} \]
Parameters:
  • scale (float, optional) – 归一化的缩放因子 \(s\)。 (默认值, 1.)

  • scale_individually (bool, 可选) – 如果设置为 True,将 计算缩放步骤为 \(\mathbf{x}^{\prime}_i = s \cdot \frac{\mathbf{x}_i^c}{{\| \mathbf{x}_i^c \|}_2}\)。 (默认: False)

  • eps (float, optional) – A value added to the denominator for numerical stability. (default: 1e-5)

forward(x: Tensor, batch: Optional[Tensor] = None, batch_size: Optional[int] = None) Tensor[source]

前向传播。

Parameters:
  • x (torch.Tensor) – The source tensor.

  • batch (torch.Tensor, optional) – The batch vector \(\mathbf{b} \in {\{ 0, \ldots, B-1\}}^N\), which assigns each element to a specific example. (default: None)

  • batch_size (int, optional) – The number of examples \(B\). Automatically calculated if not given. (default: None)

Return type:

Tensor