SparseBFSSearcher

class SparseBFSSearcher(max_iter: int = 5, device: str | device | None = None)[来源]

基础类:AnchorSearcher

在GPU上使用torch_sparse查找最近的锚点。

初始化分词器。

Parameters:
  • max_iter (int) – 通过Metis获得的分区数量。

  • device (str | device | None) – 用于标记化的设备

方法总结

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

为每个实体找到\(k\)个最近的锚节点。

bfs(anchors, edge_list, max_iter, k, device)

使用广度优先搜索确定候选池。

create_adjacency(edge_index[, num_entities])

从给定的边索引创建一个稀疏邻接矩阵(以边列表的形式)。

iter_extra_repr()

遍历extra_repr()的组件。

select(pool, k)

从给定的池中选择 \(k\) 个锚点。

方法文档

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

为每个实体找到\(k\)个最近的锚节点。

Parameters:
  • edge_index (ndarray) – 形状: (2, m) 边索引

  • anchors (ndarray) – 形状: (a,) 选定的锚点实体ID

  • k (int) – 返回的最接近的锚点数量

  • num_entities (int | None) – 实体的数量

Returns:

形状: (n, k), -1 <= res < a 最近锚点的ID

Return type:

ndarray

static bfs(anchors: ndarray, edge_list: tensor, max_iter: int, k: int, device: device) ndarray[source]

使用广度优先搜索确定候选池。

Parameters:
  • anchors (ndarray) – 形状: (a,) 锚点节点ID

  • edge_list (tensor) – 形状: (2, n) 包含对称边和自环的边列表

  • max_iter (int) – 要考虑的最大跳数

  • k (int) – 达到的最小锚节点数

  • device (device) – 计算所执行的设备

Returns:

形状: (n, a) 一个布尔数组,指示锚点 \(j\) 是否在节点 \(i\)\(k\) 个最近锚点的集合中

Raises:

ImportError – 如果未安装 torch_sparse

Return type:

ndarray

static create_adjacency(edge_index: ndarray, num_entities: int | None = None) tensor[源代码]

从给定的边索引创建一个稀疏邻接矩阵(以边列表的形式)。

Parameters:
  • edge_index (ndarray) – 形状: (2, m) 边索引

  • num_entities (int | None) – 实体的数量。如果未给出,则从边索引推断

Returns:

形状: (2, 2m + n) 包含反向边和自环的边列表

Return type:

张量

iter_extra_repr() Iterable[str][来源]

遍历extra_repr()的组件。

此方法通常被重写。一个常见的模式是

def iter_extra_repr(self) -> Iterable[str]:
    yield from super().iter_extra_repr()
    yield "<key1>=<value1>"
    yield "<key2>=<value2>"
Returns:

一个可迭代的extra_repr()的各个组件

Return type:

Iterable[str]

static select(pool: tensor, k: int) ndarray[来源]

从给定的池中选择 \(k\) 个锚点。

Parameters:
  • pool (tensor) – 形状: (n, a) 每个节点的锚点候选者及其距离

  • k (int) – 选择候选者的数量

Returns:

形状: (n, k) 选中的锚点。如果候选数量不足,可能包含-1

Return type:

ndarray