AnchorSelection

class AnchorSelection(num_anchors=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, known_anchors=None)[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 (Optional[ndarray]) – numpy.ndarray an array of already known anchors for getting only unique anchors

Return type

ndarray

Returns

(k,) the selected entity ids

filter_unique(anchor_ranking, known_anchors)[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 (Optional[ndarray]) – shape: (m,) a collection of already known anchors

Return type

ndarray

Returns

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

iter_extra_repr()[source]

Extra components for __repr__.

Return type

Iterable[str]