MCPcopy Create free account
hub / github.com/easy-graph/Easy-Graph / from_feature_kNN

Method from_feature_kNN

easygraph/classes/hypergraph.py:191–206  ·  view source on GitHub ↗

r"""Construct the hypergraph from the feature matrix. Each hyperedge in the hypergraph is constructed by the central vertex ans its :math:`k-1` neighbor vertices. .. note:: The constructed hypergraph is a k-uniform hypergraph. If the feature matrix has the size :math:`N \times C

(
        features: torch.Tensor, k: int, device: torch.device = torch.device("cpu")
    )

Source from the content-addressed store, hash-verified

189
190 @staticmethod
191 def from_feature_kNN(
192 features: torch.Tensor, k: int, device: torch.device = torch.device("cpu")
193 ):
194 r"""Construct the hypergraph from the feature matrix. Each hyperedge in the hypergraph is constructed by the central vertex ans its :math:`k-1` neighbor vertices.
195
196 .. note::
197 The constructed hypergraph is a k-uniform hypergraph. If the feature matrix has the size :math:`N \times C`, the number of vertices and hyperedges of the constructed hypergraph are both :math:`N`.
198
199 Args:
200 ``features`` (``torch.Tensor``): The feature matrix.
201 ``k`` (``int``): The number of nearest neighbors.
202 ``device`` (``torch.device``, optional): The device to store the hypergraph. Defaults to ``torch.device('cpu')``.
203 """
204 e_list = Hypergraph._e_list_from_feature_kNN(features, k)
205 hg = Hypergraph(features.shape[0], e_list, device=device)
206 return hg
207
208 @staticmethod
209 def from_graph(graph, device: torch.device = torch.device("cpu")) -> "Hypergraph":

Callers 1

test_from_feature_kNNFunction · 0.80

Calls 2

HypergraphClass · 0.85

Tested by 1

test_from_feature_kNNFunction · 0.64