torch_geometric.transforms.KNNGraph
- class KNNGraph(k: int = 6, loop: bool = False, force_undirected: bool = False, flow: str = 'source_to_target', cosine: bool = False, num_workers: int = 1)[source]
Bases:
BaseTransform基于节点位置
data.pos创建一个k-NN图 (功能名称:knn_graph)。- Parameters:
k (int, optional) – 邻居的数量。(默认值:
6)loop (bool, optional) – If
True, the graph will contain self-loops. (default:False)force_undirected (bool, 可选) – 如果设置为
True,新的边将是无向的。(默认值:False)flow (str, 可选) – 当与消息传递结合使用时,表示流动方向 (
"source_to_target"或"target_to_source")。 如果设置为"source_to_target",每个目标节点将恰好有 \(k\) 个源节点指向它。 (默认:"source_to_target")cosine (bool, optional) – If
True, will use the cosine distance instead of euclidean distance to find nearest neighbors. (default:False)num_workers (int) – Number of workers to use for computation. Has no effect in case
batchis notNone, or the input lies on the GPU. (default:1)