结构体 faiss::LinearTransform

struct LinearTransform : public faiss::VectorTransform

通用线性变换,在输出上应用偏置项 y = A * x + b

faiss::ITQMatrix, faiss::OPQMatrix, faiss::PCAMatrix, faiss::RandomRotationMatrix 继承

公共函数

explicit LinearTransform(int d_in = 0, int d_out = 0, bool have_bias = false)

支持 d_in > d_out 和 d_out < d_in

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
inline ~LinearTransform() override
virtual void train(idx_t n, const float *x)

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

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

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

float *apply(idx_t n, const float *x) const

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

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

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

返回值:

输出向量,大小为 n * d_out

公共成员

bool have_bias
bool is_orthonormal

! 是否使用偏置项

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

std::vector<float> A

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

std::vector<float> b

偏置向量,大小为 d_out

bool verbose
int d_in
int d_out

! 输入维度

bool is_trained

设置 VectorTransform 是否不需要训练,或者是否已经完成训练