torch_geometric.nn.norm.LayerNorm

class LayerNorm(in_channels: int, eps: float = 1e-05, affine: bool = True, mode: str = 'graph')[source]

Bases: Module

对一批特征中的每个单独示例应用层归一化,如“层归一化”论文中所述。

\[\mathbf{x}^{\prime}_i = \frac{\mathbf{x} - \textrm{E}[\mathbf{x}]}{\sqrt{\textrm{Var}[\mathbf{x}] + \epsilon}} \odot \gamma + \beta\]

均值和标准差是在小批量中的每个对象上分别计算所有节点和所有节点通道的。

Parameters:
  • in_channels (int) – Size of each input sample.

  • eps (float, optional) – 为了数值稳定性而添加到分母的值。(默认: 1e-5)

  • affine (bool, 可选) – 如果设置为 True,此模块具有 可学习的仿射参数 \(\gamma\)\(\beta\)。 (默认: True)

  • mode (str, optinal) – 用于层归一化的归一化模式 ("graph""node")。如果使用 "graph",每个图将被视为一个需要归一化的元素。如果使用 “node”,每个节点将被视为一个需要归一化的元素。(默认值:"graph"

reset_parameters()[source]

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

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