dgl.geometry
dgl.geometry
包包含几何操作:
点云采样的最远点采样
用于graclus池化的邻居匹配模块
注意
此包是实验性的,接口可能会在未来的版本中发生变化。
最远点采样器
最远点采样是一种从点云数据中迭代采样的贪心算法。它从一个随机单点样本开始。在每次迭代中,它从剩余的点中采样,这些点距离已采样点集合最远。
- class dgl.geometry.farthest_point_sampler(pos, npoints, start_idx=None)[source]
无需计算所有距离对的最远点采样器。
在每批中,算法从
start_idx
指定的样本索引开始。 然后对于每个点,我们保持最小到样本的距离。 最后,我们选择具有最大距离的点。 这个过程将重复sample_points
- 1次。- Parameters:
- Returns:
每批中的采样索引。
- Return type:
形状为 (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]
Description
在Metis和Graclus中,用于同质图粗化的边粗化的邻居匹配过程。这个过程持续选择一个未标记的顶点,并将其与其未标记的邻居(最大化其边权重)进行匹配,直到无法再进行匹配。
如果没有给出边的权重,此过程将为每个顶点随机选择邻居。
GPU实现基于A GPU Algorithm for Greedy Graph Matching
- NOTE: The input graph must be bi-directed (undirected) graph. Call
dgl.to_bidirected
如果你不确定你的图是否是双向的。
- param graph:
输入的齐次图。
- type graph:
DGLGraph
- param edge_weight:
边缘权重张量,为每条边保存非负标量权重。 默认值:
None
- type edge_weight:
torch.Tensor, 可选的
- param relabel_idx:
如果为真,重新标记生成的节点标签以具有连续的节点ID。 默认值:
True
- type relabel_idx:
布尔值,可选
示例
以下示例使用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])
- NOTE: The input graph must be bi-directed (undirected) graph. Call