CSGraphAnchorSearcher

class CSGraphAnchorSearcher[source]

Bases: AnchorSearcher

Find closest anchors using scipy.sparse.csgraph.

Methods Summary

__call__(edge_index, anchors, k[, num_entities])

Find the \(k\) closest anchor nodes for each entity.

topk_argpartition(array, k)

Return the sorted top-k indices using argpartition.

topk_argsort(array, k)

Return the sorted top-k indices using argsort.

Methods Documentation

__call__(edge_index: ndarray, anchors: ndarray, k: int, num_entities: int | None = None) ndarray[source]

Find the \(k\) closest anchor nodes for each entity.

Parameters:
  • edge_index (ndarray) – shape: (2, m) the edge index

  • anchors (ndarray) – shape: (a,) the selected anchor entity Ids

  • k (int) – the number of closest anchors to return

  • num_entities (int | None) – the number of entities

Returns:

shape: (n, k), -1 <= res < a the Ids of the closest anchors

Return type:

ndarray

static topk_argpartition(array: ndarray, k: int) ndarray[source]

Return the sorted top-k indices using argpartition.

Its complexity is \(O(m * (n + k log k))\).

Parameters:
  • array (ndarray) – shape: (n, m) the array

  • k (int) – the value of \(k\)

Returns:

shape: (m, k) the indices of the \(k\) smallest values sorted in descending order

Return type:

ndarray

static topk_argsort(array: ndarray, k: int) ndarray[source]

Return the sorted top-k indices using argsort.

Its complexity is \(O(m * n log n)\).

Parameters:
  • array (ndarray) – shape: (n, m) the array

  • k (int) – the value of \(k\)

Returns:

shape: (m, k) the indices of the \(k\) smallest values sorted in descending order

Return type:

ndarray