torch_geometric.nn.aggr.PowerMeanAggregation

class PowerMeanAggregation(p: float = 1.0, learn: bool = False, channels: int = 1)[source]

Bases: Aggregation

基于幂项的幂均值聚合操作符,如“DeeperGCN: All You Need to Train Deeper GCNs”论文中所述。

\[\mathrm{powermean}(\mathcal{X}|p) = \left(\frac{1}{|\mathcal{X}|} \sum_{\mathbf{x}_i\in\mathcal{X}}\mathbf{x}_i^{p}\right)^{1/p},\]

其中 \(p\) 控制在聚合一组特征 \(\mathcal{X}\) 时 powermean 的幂次。

Parameters:
  • p (float, 可选) – 用于幂均值聚合的初始幂值。 (默认: 1.0)

  • 学习 (bool, 可选) – 如果设置为 True,将动态学习用于幂均值聚合的 p 值。 (默认: False)

  • channels (int, optional) – 从 \(p\) 学习的通道数。 如果设置为大于 1 的值,\(p\) 将针对每个输入特征通道进行学习。 这要求输入到前向计算的形状是兼容的。(默认值:1

reset_parameters()[source]

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

forward(x: Tensor, index: Optional[Tensor] = None, ptr: Optional[Tensor] = None, dim_size: Optional[int] = None, dim: int = -2) Tensor[source]

前向传播。

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

  • index (torch.Tensor, optional) – The indices of elements for applying the aggregation. One of index or ptr must be defined. (default: None)

  • ptr (torch.Tensor, optional) – If given, computes the aggregation based on sorted inputs in CSR representation. One of index or ptr must be defined. (default: None)

  • dim_size (int, optional) – The size of the output tensor at dimension dim after aggregation. (default: None)

  • dim (int, optional) – The dimension in which to aggregate. (default: -2)

  • max_num_elements – (int, optional): The maximum number of elements within a single aggregation group. (default: None)

Return type:

Tensor