Struct faiss::OPQMatrix

struct faiss::OPQMatrix : public faiss::LinearTransform

Applies a rotation to align the dimensions with a PQ to minimize the reconstruction error. Can be used before an IndexPQ or an IndexIVFPQ. The method is the non-parametric version described in:

“Optimized Product Quantization for Approximate Nearest Neighbor Search” Tiezheng Ge, Kaiming He, Qifa Ke, Jian Sun, CVPR’13

Public Types

typedef Index::idx_t idx_t

Public Functions

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

if d2 != -1, output vectors of this dimension

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

Perform training on a representative set of vectors. Does nothing by default.

Parameters
  • n – nb of training vectors

  • x – training vecors, size n * d

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

same as apply, but result is pre-allocated

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

compute x = A^T * (x - b) is reverse transform if A has orthonormal lines

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

works only if is_orthonormal

void set_is_orthonormal()

compute A^T * A to set the is_orthonormal flag

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

apply the random rotation, return new allocated matrix

Parameters

x – size n * d_in

Returns

size n * d_out

Public Members

int M

nb of subquantizers

int niter

Number of outer training iterations.

int niter_pq

Number of training iterations for the PQ.

int niter_pq_0

same, for the first outer iteration

size_t max_train_points

if there are too many training points, resample

bool verbose
ProductQuantizer *pq

if non-NULL, use this product quantizer for training should be constructed with (d_out, M, _)

bool have_bias
bool is_orthonormal

! whether to use the bias term

check if matrix A is orthonormal (enables reverse_transform)

std::vector<float> A

Transformation matrix, size d_out * d_in.

std::vector<float> b

bias vector, size d_out

int d_in
int d_out

! input dimension

bool is_trained

set if the VectorTransform does not require training, or if training is done already