torch_geometric.nn.aggr.SoftmaxAggregation
- class SoftmaxAggregation(t: float = 1.0, learn: bool = False, semi_grad: bool = False, channels: int = 1)[source]
Bases:
Aggregation基于温度项的softmax聚合操作符,如“DeeperGCN: All You Need to Train Deeper GCNs”论文中所述。
\[\mathrm{softmax}(\mathcal{X}|t) = \sum_{\mathbf{x}_i\in\mathcal{X}} \frac{\exp(t\cdot\mathbf{x}_i)}{\sum_{\mathbf{x}_j\in\mathcal{X}} \exp(t\cdot\mathbf{x}_j)}\cdot\mathbf{x}_{i},\]其中 \(t\) 控制在一组特征 \(\mathcal{X}\) 上聚合时 softmax 的软度。
- Parameters:
t (float, optional) – 用于softmax聚合的初始逆温度。(默认值:
1.0)学习 (bool, 可选) – 如果设置为
True,将动态学习用于softmax聚合的值t。 (默认:False)semi_grad (bool, 可选) – 如果设置为
True,将在 softmax 计算期间关闭梯度计算。因此,在反向传播期间仅使用半梯度。当t不可学习时,这对于节省内存和加速反向计算非常有用。(默认值:False)channels (int, optional) – 从 \(t\) 学习的通道数。 如果设置为大于
1的值,\(t\) 将按输入特征通道进行学习。 这需要输入到前向计算的形状兼容。(默认值:1)
- 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
indexorptrmust be defined. (default:None)ptr (torch.Tensor, optional) – If given, computes the aggregation based on sorted inputs in CSR representation. One of
indexorptrmust be defined. (default:None)dim_size (int, optional) – The size of the output tensor at dimension
dimafter 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: