KNNGraph#
- class KNNGraph(pos, neighbours, **kwargs)[source]#
Bases:
GraphBuilder
Extends the
GraphBuilder
class to computeedge_index
based on a K-nearest neighbors algorithm.Instantiate the
Graph
class by computing theedge_index
based on the K-nearest neighbors algorithm.- Parameters:
pos (torch.Tensor | LabelTensor) – A tensor of shape
(N, D)
representing the positions ofN
points inD
-dimensional space.neighbours (int) – The number of nearest neighbors to consider when building the graph.
kwargs (dict) – The additional keyword arguments to be passed to
GraphBuilder
andGraph
classes.
- Returns:
A
Graph
instance with the computededge_index
.- Return type:
- static compute_knn_graph(points, neighbours)[source]#
Computes the
edge_index
based on the K-nearest neighbors algorithm.- Parameters:
points (torch.Tensor | LabelTensor) – A tensor of shape
(N, D)
representing the positions ofN
points inD
-dimensional space.neighbours (int) – The number of nearest neighbors to consider when building the graph.
- Returns:
A tensor of shape
(2, E)
, withE
number of edges, representing the edge indices of the graph.- Return type: