dgl.geometry
The dgl.geometry
包包含几何操作
用于点云采样的最远点采样
用于 graclus 池化的邻居匹配模块
注意
此包处于实验阶段,其接口在未来版本中可能会发生变化。
最远点采样器
最远点采样是一种贪心算法,它从点云数据中迭代采样。它从一个随机的单个采样点开始。在每次迭代中,它从其余点中采样离已采样点集合最远的点。
- class dgl.geometry.farthest_point_sampler(pos, npoints, start_idx=None)[source]
无需计算所有点对距离的最远点采样器。
在每个批次中,算法从
start_idx
指定的采样索引开始。然后对于每个点,我们维护到已采样点的最小距离。最后,我们选择具有最大此最小距离的点。此过程将重复npoints
- 1 次。- 参数:
- 返回值:
每个批次中采样的索引。
- 返回值类型:
形状为 (B, npoints) 的张量
示例
以下示例使用 PyTorch 后端。
>>> import torch >>> from dgl.geometry import farthest_point_sampler >>> x = torch.rand((2, 10, 3)) >>> point_idx = farthest_point_sampler(x, 2) >>> print(point_idx) tensor([[5, 6], [7, 8]])
邻居匹配
邻居匹配是 Graclus 聚类算法中的一个重要模块。
- class dgl.geometry.neighbor_matching(graph, e_weights=None, relabel_idx=True)[source]
描述
在 Metis 和 Graclus 中用于同构图粗化的边粗化(edge coarsening)的邻居匹配过程。此过程不断选择一个未标记的顶点,并将其与其未标记的邻居(具有最大边权重)之一进行匹配,直到无法再进行匹配。
如果没有给定边权重,此过程将随机为每个顶点选择邻居。
GPU 实现基于 A GPU Algorithm for Greedy Graph Matching
- 注意:输入图必须是双向(无向)图。如果你的图不是双向图,请调用
dgl.to_bidirected
以确保你的图是双向的。
- 参数 graph:
输入的同构图。
- 类型 graph:
DGLGraph
- 参数 edge_weight:
存储每条边的非负标量权重的边权重张量。默认值:
None
- 类型 edge_weight:
torch.Tensor, 可选
- 参数 relabel_idx:
如果为 true,重新标记结果节点标签,使其具有连续的节点 ID。默认值:
True
- 类型 relabel_idx:
bool, 可选
示例
以下示例使用 PyTorch 后端。
>>> import torch, dgl >>> from dgl.geometry import neighbor_matching >>> >>> g = dgl.graph(([0, 1, 1, 2], [1, 0, 2, 1])) >>> res = neighbor_matching(g) tensor([0, 1, 1])
- 注意:输入图必须是双向(无向)图。如果你的图不是双向图,请调用