ot.gnn
图神经网络中用于最优传输的层和函数。
- ot.gnn.FGW_distance_to_templates(G_edges, tplt_adjacencies, G_features, tplt_features, tplt_weights, alpha=0.5, multi_alpha=False, batch=None)[源]
计算图与模板之间的FGW距离。
- Parameters:
G_edges (torch.Tensor, shape (n_edges, 2)) – 图的边索引,采用 Pytorch Geometric 格式。
tplt_adjacencies (列表 由 torch.Tensor组成, 形状 (n_templates, n_template_nodes, n_templates_nodes)) - 模板的邻接矩阵列表。
G_features (torch.Tensor, shape (n_nodes, n_features)) – 图的节点特征。
tplt_features (列表 的 torch.Tensor, 形状 (n_templates, n_template_nodes, n_features)) – 模板的节点特征列表。
weights (torch.Tensor, shape (n_templates, n_template_nodes)) – 模板节点上的权重。
alpha (float, 可选) – 权衡参数 (0 < alpha < 1)。权重特征 (alpha=0) 和结构 (alpha=1)。
multi_alpha (bool, 可选) – 如果为 True,则 alpha 参数是大小为 n_templates 的向量。
batch (torch.Tensor, 可选) – 批向量,用于将每个节点分配到其图中。
- Returns:
distances – 图与模板之间融合的Gromov-Wasserstein距离的向量。
- Return type:
torch.Tensor,形状为 (n_templates) 如果 batch=None,否则形状为 (n_graphs, n_templates)。
- class ot.gnn.TFGWPooling(n_features, n_tplt=2, n_tplt_nodes=2, alpha=None, train_node_weights=True, multi_alpha=False, feature_init_mean=0.0, feature_init_std=1.0)[源]
- Template Fused Gromov-Wasserstein (TFGW) layer. This layer is a pooling layer for graph neural networks.
计算图与一组模板之间的融合Gromov-Wasserstein距离。
\[TFGW_{ \overline{ \mathcal{G} }, \alpha }(C,F,h)=[ FGW_{\alpha}(C,F,h,\overline{C}_k,\overline{F}_k,\overline{h}_k)]_{k=1}^{K}\]其中 :
\(\mathcal{G}=\{(\overline{C}_k,\overline{F}_k,\overline{h}_k) \}_{k \in \{1,...,K \}} \}\) 是由它们的邻接矩阵 \(\overline{C}_k\)、特征矩阵 \(\overline{F}_k\) 和节点权重 \(\overline{h}_k\) 特征化的 \(K\) 个模板的集合。
\(C\), \(F\) 和 \(h\) 分别是图的邻接矩阵、特征矩阵和节点权重。
\(\alpha\) 是Fused Gromov-Wasserstein距离中特征与结构之间的权衡参数。
- Parameters:
n_features (int) – 节点的特征维度。
n_tplt (int) – 图形模板的数量。
n_tplt_nodes (int) – 每个模板中的节点数量。
alpha (float, 可选) – FGW 权衡参数 (0 < alpha < 1)。如果为 None 则 alpha 是可训练的,否则它固定为给定值。权重特征 (alpha=0) 和结构 (alpha=1)。
train_node_weights (bool, optional) – 如果为True,模板节点权重将被学习。否则,它们是均匀的。
multi_alpha (bool, 可选) – 如果为True,alpha参数是大小为n_tplt的向量。
feature_init_mean (float, 可选) – 用于初始化模板特征的随机正态分布的均值。
feature_init_std (float, 可选) – 初始化模板特征的随机正态分布的标准差。
参考文献
- forward(x, edge_index, batch=None)[源]
- Parameters:
x (torch.Tensor) – 节点特征。
edge_index (torch.Tensor) – 边的索引。
batch (torch.Tensor, 可选) – 批向量,用于将每个节点分配到其图中。
- class ot.gnn.TWPooling(n_features, n_tplt=2, n_tplt_nodes=2, train_node_weights=True, feature_init_mean=0.0, feature_init_std=1.0)[源]
- Template Wasserstein (TW) layer, also known as OT-GNN layer. This layer is a pooling layer for graph neural networks.
计算图特征与一组模板之间的瓦瑟斯坦距离。
\[TW_{\overline{\mathcal{G}}}(C,F,h)=[W(F,h,\overline{F}_k,\overline{h}_k)]_{k=1}^{K}\]其中 :
\(\mathcal{G}=\{(\overline{F}_k,\overline{h}_k) \}_{k \in \{1,...,K \}} \}\) 是由特征矩阵 \(\overline{F}_k\) 和节点权重 \(\overline{h}_k\) 表征的 \(K\) 个模板的集合。
\(F\) 和 \(h\) 分别是特征矩阵和图的节点权重。
- Parameters:
参考文献
[54] Bécigneul, G., Ganea, O. E., Chen, B., Barzilay, R., & Jaakkola, T. S. (2020). [最优传输图神经网络]
- forward(x, edge_index=None, batch=None)[源]
- Parameters:
x (torch.Tensor) – 节点特征。
edge_index (torch.Tensor) – 边的索引。
batch (torch.Tensor, 可选) – 批向量,用于将每个节点分配到其图中。
- ot.gnn.wasserstein_distance_to_templates(G_features, tplt_features, tplt_weights, batch=None)[源]
计算图与图模板之间的Wasserstein距离。
- Parameters:
G_features (torch.Tensor, shape (n_nodes, n_features)) – 图的节点特征。
tplt_features (列表 的 torch.Tensor, 形状 (n_templates, n_template_nodes, n_features)) – 模板的节点特征列表。
weights (torch.Tensor, shape (n_templates, n_template_nodes)) – 模板节点上的权重。
batch (torch.Tensor, 可选) – 批向量,用于将每个节点分配到其图中。
- Returns:
distances – 图与模板之间的Wasserstein距离向量。
- Return type:
torch.Tensor,形状为 (n_templates) 如果 batch=None,否则形状为 (n_graphs, n_templates)