torch_geometric.nn.aggr.PatchTransformerAggregation

class PatchTransformerAggregation(in_channels: int, out_channels: int, patch_size: int, hidden_channels: int, num_transformer_blocks: int = 1, heads: int = 1, dropout: float = 0.0, aggr: Union[str, List[str]] = 'mean')[source]

Bases: Aggregation

执行补丁变换器聚合,其中要聚合的元素通过跨补丁的多头注意力块进行处理,如“简化时间异质网络以进行连续时间链接预测”论文中所述。

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

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

  • patch_size (int) – 一个补丁中的元素数量。

  • hidden_channels (int) – 每个样本的中间大小。

  • num_transformer_blocks (int, optional) – 变压器块的数量 (默认: 1).

  • heads (int, optional) – Number of multi-head-attentions. (default: 1)

  • dropout (float, optional) – 注意力权重的丢弃概率。 (默认值: 0.0)

  • aggr (strlist[str], 可选) – 聚合模块,例如, "sum", "mean", "min", "max", "var", "std". (默认: "mean")

reset_parameters() None[source]

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

Return type:

None

forward(x: Tensor, index: Tensor, 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