结构体 faiss::OPQMatrix

struct OPQMatrix : public faiss::LinearTransform

应用旋转来对齐维度与PQ,以最小化重建误差。可以在 IndexPQIndexIVFPQ 之前使用。该方法是以下论文中描述的非参数版本

“用于近似最近邻搜索的优化乘积量化” Tiezheng Ge, Kaiming He, Qifa Ke, Jian Sun, CVPR'13

公共函数

explicit OPQMatrix(int d = 0, int M = 1, int d2 = -1)

如果 d2 != -1,则输出此维度的向量

virtual void train(idx_t n, const float *x) override

在一组具有代表性的向量上执行训练。默认情况下不执行任何操作。

参数:
  • n – 训练向量的数量

  • x – 训练向量,大小为 n * d

virtual void apply_noalloc(idx_t n, const float *x, float *xt) const override

与 apply 相同,但结果是预先分配的

void transform_transpose(idx_t n, const float *y, float *x) const

计算 x = A^T * (x - b),如果 A 具有正交线,则是反向变换

virtual void reverse_transform(idx_t n, const float *xt, float *x) const override

仅在 is_orthonormal 为真时有效

void set_is_orthonormal()

计算 A^T * A 以设置 is_orthonormal 标志

void print_if_verbose(const char *name, const std::vector<double> &mat, int n, int d) const
virtual void check_identical(const VectorTransform &other) const override
float *apply(idx_t n, const float *x) const

应用变换,并在分配的指针中返回结果

参数:
  • n – 要变换的向量数

  • x – 输入向量,大小为 n * d_in

返回值:

输出向量,大小为 n * d_out

公共成员

int M

子量化器的数量

int niter = 50

外部训练迭代的次数。

int niter_pq = 4

PQ的训练迭代次数。

int niter_pq_0 = 40

相同,用于第一次外部迭代

size_t max_train_points = 256 * 256

如果训练点太多,则重新采样

bool verbose = false
ProductQuantizer *pq = nullptr

如果非 NULL,则使用此乘积量化器进行训练,应使用 (d_out, M, _) 构建

bool have_bias
bool is_orthonormal

!是否使用偏置项

检查矩阵 A 是否为正交矩阵(启用 reverse_transform)

std::vector<float> A

变换矩阵,大小为 d_out * d_in。

std::vector<float> b

偏置向量,大小为 d_out

int d_in
int d_out

!输入维度

bool is_trained

如果 VectorTransform 不需要训练,或者已经完成训练,则设置