torch_geometric.nn.norm.HeteroLayerNorm

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

Bases: Module

“Layer Normalization”论文中描述的,对一批异构特征中的每个单独示例应用层归一化。 与LayerNorm相比,HeteroLayerNorm对每种节点或边类型分别应用归一化。

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

  • num_types (int) – 类型的数量。

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

  • affine (bool, optional) – If set to True, this module has learnable affine parameters \(\gamma\) and \(\beta\). (default: True)

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

reset_parameters()[source]

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

forward(x: Tensor, type_vec: Optional[Tensor] = None, type_ptr: Optional[Union[Tensor, List[int]]] = None) Tensor[source]

前向传播。

注意

需要指定type_vectype_ptr。 通常,如果输入张量按类型排序,依赖type_ptr会更高效。

Parameters:
  • x (torch.Tensor) – 输入特征。

  • type_vec (torch.Tensor, optional) – 一个将每个条目映射到类型的向量。(默认值:None

  • type_ptr (torch.TensorList[int]) – 表示类型边界的向量。(默认值: None)

Return type:

Tensor