AnchorSelection

class AnchorSelection(num_anchors: int = 32)[source]

Bases: ExtraReprMixin, ABC

Anchor entity selection strategy.

Initialize the strategy.

Parameters:

num_anchors (int) – the number of anchor nodes to select. # TODO: allow relative

Methods Summary

__call__(edge_index[, known_anchors])

Select anchor nodes.

filter_unique(anchor_ranking, known_anchors)

Filter out already known anchors, and select from remaining ones afterwards.

iter_extra_repr()

Extra components for __repr__.

Methods Documentation

abstract __call__(edge_index: ndarray, known_anchors: ndarray | None = None) ndarray[source]

Select anchor nodes.

Note

the number of selected anchors may be smaller than \(k\), if there are less entities present in the edge index.

Parameters:
  • edge_index (ndarray) – shape: (m, 2) the edge_index, i.e., adjacency list.

  • known_anchors (ndarray | None) – numpy.ndarray an array of already known anchors for getting only unique anchors

Returns:

(k,) the selected entity ids

Return type:

ndarray

filter_unique(anchor_ranking: ndarray, known_anchors: ndarray | None) ndarray[source]

Filter out already known anchors, and select from remaining ones afterwards.

Note

the output size may be smaller, if there are not enough candidates remaining.

Parameters:
  • anchor_ranking (ndarray) – shape: (n,) the anchor node IDs sorted by preference, where the first one is the most preferrable.

  • known_anchors (ndarray | None) – shape: (m,) a collection of already known anchors

Returns:

shape: (m + num_anchors,) the extended anchors, i.e., the known ones and num_anchors novel ones.

Return type:

ndarray

iter_extra_repr() Iterable[str][source]

Extra components for __repr__.

Return type:

Iterable[str]