文件 PolysemousTraining.h
-
namespace faiss
实现具有多种变体的 k-means 聚类。
版权所有 (c) Facebook, Inc. 及其附属公司。
此源代码已获得 MIT 许可的授权,该许可位于此源树的根目录中的 LICENSE 文件中。
IDSelector 旨在定义要处理的向量子集(用于删除或作为搜索子集)
PQ4 SIMD 打包和累积函数
基本内核使用 bbs = nb * 2 * 16 个向量累积 nq 查询向量,并生成该输出矩阵。 它对于 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 SimulatedAnnealingParameters
- #include <PolysemousTraining.h>
用于模拟退火方法的参数
由 faiss::PolysemousTraining, faiss::SimulatedAnnealingOptimizer 继承
公共函数
-
inline SimulatedAnnealingParameters()
公共成员
-
初始温度 init_temperature = 0.7
-
温度衰减率 temperature_decay = 0.9997893011688015
-
迭代次数 n_iter = 500000
-
重做次数 n_redo = 2
-
随机数种子 seed = 123
-
详细模式 verbose = 0 (0=关闭, >0=开启)
-
仅翻转位 only_bit_flips = false
-
随机初始化 init_random = false
-
inline SimulatedAnnealingParameters()
-
struct PermutationObjective
- #include <PolysemousTraining.h>
损失函数的抽象类
被 faiss::ReproduceDistancesObjective 继承
公共函数
-
计算排列的损失。
-
计算交换后的损失变化。
-
虚析构函数。
公共成员
-
排列的大小。
-
计算排列的损失。
-
struct ReproduceDistancesObjective : public faiss::PermutationObjective
公共函数
-
距离权重函数。
-
获取原始距离。
-
计算排列的损失(重写)。
-
计算交换后的损失变化(重写)。
-
ReproduceDistancesObjective(int n, const double *source_dis_in, const double *target_dis_in, double dis_weight_factor)
-
void set_affine_target_dis(const double *source_dis_in)
-
inline ~ReproduceDistancesObjective() override
-
距离权重函数。
-
struct SimulatedAnnealingOptimizer : public faiss::SimulatedAnnealingParameters
- #include <PolysemousTraining.h>
用于排列的模拟退火优化算法。
公共函数
-
SimulatedAnnealingOptimizer(PermutationObjective *obj, const SimulatedAnnealingParameters &p)
记录成本函数的值
-
double optimize(int *perm)
-
double run_optimization(int *best_perm)
-
virtual ~SimulatedAnnealingOptimizer()
-
SimulatedAnnealingOptimizer(PermutationObjective *obj, const SimulatedAnnealingParameters &p)
-
struct PolysemousTraining : public faiss::SimulatedAnnealingParameters
- #include <PolysemousTraining.h>
优化 ProductQuantizer 中索引的顺序
公共类型
公共函数
-
PolysemousTraining()
-
void optimize_pq_for_hamming(ProductQuantizer &pq, size_t n, const float *x) const
重新排序质心,使汉明距离成为 SDC 距离的良好近似值(由 train 调用)
-
void optimize_ranking(ProductQuantizer &pq, size_t n, const float *x) const
由 optimize_pq_for_hamming 调用
-
void optimize_reproduce_distances(ProductQuantizer &pq) const
由 optimize_pq_for_hamming 调用
-
size_t memory_usage_per_thread(const ProductQuantizer &pq) const
确保我们不会耗尽内存
公共成员
-
Optimization_type_t optimization_type
-
int ntrain_permutation
使用 1/4 的训练点进行优化,最多 ntrain_permutation。如果 ntrain_permutation == 0:在质心上训练
-
double dis_weight_factor
对距离损失进行加权的 exp 衰减
-
size_t max_memory
如果需要超过该数量的 RAM,则拒绝训练
-
double init_temperature = 0.7
-
double temperature_decay = 0.9997893011688015
-
int n_iter = 500000
-
int n_redo = 2
-
int seed = 123
-
int verbose = 0
-
bool only_bit_flips = false
-
bool init_random = false
-
PolysemousTraining()
-
struct SimulatedAnnealingParameters