ScipySparseAnchorSearcher

class ScipySparseAnchorSearcher(max_iter: int = 5)[source]

基础类:AnchorSearcher

使用scipy.sparse查找最近的锚点。

初始化搜索器。

Parameters:

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

方法总结

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

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

bfs(anchors, adjacency, max_iter, k)

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

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[源代码]

为每个实体找到\(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, adjacency: spmatrix, max_iter: int, k: int) ndarray[源代码]

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

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

  • 邻接 (spmatrix) – 形状: (n, n) 邻接矩阵

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

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

Returns:

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

Return type:

ndarray

static create_adjacency(edge_index: ndarray, num_entities: int | None = None) spmatrix[来源]

从给定的边索引创建一个稀疏邻接矩阵。

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

  • num_entities (int | None) – 实体的数量。可以从edge_index推断出来

Returns:

形状: (n, n) 一个正方形的稀疏邻接矩阵

Return type:

spmatrix

iter_extra_repr() Iterable[str][source]

遍历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: ndarray, k: int) ndarray[来源]

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

Parameters:
  • pool (ndarray) – 形状: (n, a) 每个节点的锚点候选(一个二进制数组)

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

Returns:

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

Return type:

ndarray