文件 AutoTune.h
-
namespace faiss
实现了具有多种变体的 k-means 聚类。
版权所有 (c) Facebook, Inc. 及其附属公司。
此源代码已获得 MIT 许可,该许可位于此源树根目录中的 LICENSE 文件中。
IDSelector 旨在定义要处理的向量子集(用于删除或作为搜索的子集)
PQ4 SIMD 打包和累积函数
基本内核将 nq 查询向量与 bbs = nb * 2 * 16 向量累积,并为此生成一个输出矩阵。对于 nq * nb <= 4 很有用,否则寄存器溢出变得太大。
这些函数的实现分布在 3 个 cpp 文件中,以减少并行编译时间。模板是显式实例化的。
此文件包含用于计算距离的内核的回调。
在整个库中,向量以 float * 指针的形式提供。当在批处理中一起处理(添加/搜索)多个向量时,大多数算法都可以进行优化。在这种情况下,它们作为矩阵传递。当 n 个大小为 d 的向量以 float * x 的形式提供时,向量 i 的分量 j 是
x[ i * d + j ]
其中 0 <= i < n 并且 0 <= j < d。换句话说,矩阵始终是紧凑的。当指定矩阵的大小时,我们将其称为 n*d 矩阵,这意味着行优先存储。
I/O 函数可以读/写到文件名、文件句柄或抽象介质的对象。
读取函数返回应该使用 delete 释放的对象。这些对象中的所有引用都由该对象拥有。
倒排列表的定义 + 一些实现该接口的通用类。
由于 IVF(倒排文件)索引对于大规模用例非常有用,因此我们将与它们相关的一些函数分组到这个小型库中。大多数函数都适用于 IndexIVF 和嵌入在 IndexPreTransform 中的 IndexIVF。
在此文件中,实现了 L2 和内积之外的额外指标
实现了一些神经网络层,主要用于支持 QINCo
定义一些将转换应用于一组向量的对象。通常这些是预处理步骤。
-
struct AutoTuneCriterion
- #include <AutoTune.h>
评估标准。返回 [0,1] 中的性能指标,越高越好。
由 faiss::IntersectionCriterion、faiss::OneRecallAtRCriterion 子类化
公共函数
-
void set_groundtruth(int gt_nnn, const float *gt_D_in, const idx_t *gt_I_in)
初始化 gt_D 和 gt_I 向量。 必须在评估之前调用
- 参数:
gt_D_in – 大小为 nq * gt_nnn
gt_I_in – 大小为 nq * gt_nnn
-
virtual double evaluate(const float *D, const idx_t *I) const = 0
评估标准。
- 参数:
D – 大小为 nq * nnn
I – 大小为 nq * nnn
- 返回值:
标准,介于 0 和 1 之间。越大越好。
-
inline virtual ~AutoTuneCriterion()
-
void set_groundtruth(int gt_nnn, const float *gt_D_in, const idx_t *gt_I_in)
-
struct OneRecallAtRCriterion : public faiss::AutoTuneCriterion
-
struct IntersectionCriterion : public faiss::AutoTuneCriterion
-
struct OperatingPoint
- #include <AutoTune.h>
维护一个实验结果列表。每个操作点是一个 (perf, t, key) 三元组,其中 perf 越高且 t 越低越好。 key 字段是操作点的任意标识符。
包括用于提取 (perf, t) 空间中的 Pareto 最优操作点的原语。
-
struct OperatingPoints
公共函数
-
OperatingPoints()
-
int merge_with(const OperatingPoints &other, const std::string &prefix = "")
将其他操作点添加到此操作点,并为键添加前缀
-
void clear()
-
double t_for_perf(double perf) const
获取达到给定性能指标所需的时间
-
void display(bool only_optimal = true) const
易于阅读的输出
-
void all_to_gnuplot(const char *fname) const
输出为易于gnuplot消化的格式
-
void optimal_to_gnuplot(const char *fname) const
公共成员
-
std::vector<OperatingPoint> all_pts
所有操作点
-
std::vector<OperatingPoint> optimal_pts
最佳操作点,按性能排序
-
OperatingPoints()
-
struct ParameterRange
- #include <AutoTune.h>
参数的可能值,从最不昂贵/准确到最昂贵/准确排序
-
struct ParameterSpace
- #include <AutoTune.h>
使用关于Faiss索引的先验知识来提取可调参数。
被 faiss::gpu::GpuParameterSpace 继承
公共函数
-
ParameterSpace()
-
size_t n_combinations() const
组合数量,= 值大小的乘积
-
bool combination_ge(size_t c1, size_t c2) const
返回组合 c1 >= c2 在元组意义上是否成立
-
void display() const
在 stdout 上打印描述
-
ParameterRange &add_range(const std::string &name)
添加一个新参数(如果已存在则返回它)
-
virtual void set_index_parameter(Index *index, const std::string &name, double val) const
设置其中一个参数,返回设置是否成功
-
void update_bounds(size_t cno, const OperatingPoint &op, double *upper_bound_perf, double *lower_bound_t) const
对于给定的另一个操作点 op,找到配置 cno 的性能上限和 t 的下限
-
void explore(Index *index, size_t nq, const float *xq, const AutoTuneCriterion &crit, OperatingPoints *ops) const
探索操作点
- 参数:
index – 要运行的索引
xq – 查询向量 (大小为 nq * index.d)
crit – 选择标准
ops – 结果操作点
-
inline virtual ~ParameterSpace()
-
ParameterSpace()
-
struct AutoTuneCriterion