torch_geometric.nn.aggr.LCMAggregation

class LCMAggregation(in_channels: int, out_channels: int, project: bool = True)[source]

Bases: Aggregation

来自“Learnable Commutative Monoids for Graph Neural Networks”论文的可交换幺半群聚合,其中元素使用具有\(\mathcal{O}(\log |\mathcal{V}|)\)深度的二叉树归约进行聚合。

注意

LCMAggregation 需要排序的索引 index 作为输入。 具体来说,如果你将此聚合作为 MessagePassing 的一部分使用,请确保 edge_index 按目标节点排序,可以通过手动 使用 sort_edge_index() 排序边索引 或调用 torch_geometric.data.Data.sort() 来实现。

警告

LCMAggregation 不是一个排列不变的运算符。

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

  • out_channels (int) – Size of each output sample.

  • 项目 (bool, 可选) – 如果设置为 True,该层将在聚合之前应用线性变换和激活函数。(默认值:True

reset_parameters()[source]

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

forward(x: Tensor, index: Optional[Tensor] = None, ptr: Optional[Tensor] = None, dim_size: Optional[int] = None, dim: int = -2, max_num_elements: Optional[int] = None) 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 (Optional[int], default: None) – (int, optional): The maximum number of elements within a single aggregation group. (default: None)

Return type:

Tensor