Enhanced residual vector quantization (ERVQ)
Enhanced residual vector quantization (ERVQ), also known as Stacked quantizers (SQ) is an non-orthogonal MCQ method.
The method is typically intialized with RVQ, and fine-tunes the codebooks to obtain a better approximation that can be quantized efficiently with quantize_rvq
.
Rayuela.quantize_ervq
โ Function.quantize_ervq(X, C, V=false) -> B, singletons
Given data and full-dimensional codebooks, quantize. This methods is identical to quantize_rvq
Arguments
X::Matrix{T}
:d
-by-n
data to quantizeC::Vector{Matrix{T}}
:m
-long vector withd
-by-h
matrix entries. Each matrix is a codebook.V::Bool
: Whether to print progress
Returns
B::Matrix{Int16}
:m
-by-n
codes that approximateX
singletons::Vector{Matrix{T}}
:m
matrices with unused codebook entries
Rayuela.train_ervq
โ Function.train_ervq(X, B, C, m, h, niter, V=false) -> C, B, error
Train an enhanced residual quantizer / stacked quantizer. This method is typically initialized by Residual vector quantization (RVQ)
Arguments
X::Matrix{T}
:d
-by-n
data to quantizeB::Matrix{T2}
:m
-by-n
matrix with pre-trained codesC::Vector{Matrix{T}}
:m
-long vector withd
-by-h
matrices. Each matrix is a pretrained codebook of size approximatelyd
-by-h
.m::Integer
: Number of codebooksh::Integer
: Number of entries in each codebook (typically 256)niter::Integer
: Number of iterations to useV::Bool
: Whether to print progress
T <: AbstractFloat
and T2 <: Integer
Returns
C::Vector{Matrix{T}}
:m
-long vector withd
-by-h
matrix entries. Each matrix is a codebook of size approximatelyd
-by-h
.B::Matrix{Int16}
:m
-by-n
matrix with the codeserror::T
: The quantization error after training
Reference
The main ideas come from
- Ai, L., Junqing, Y., Guan, T., & He, Y. (2014, June). Efficient approximate nearest neighbor search by optimized residual vector quantization. In Content-Based Multimedia Indexing (CBMI), 2014 12th International Workshop on (pp. 1-4). IEEE. [PDF]
Independently, Martinez released a similar method with a some improvements and an open-source implementation:
- Martinez, J., Hoos, H. H., & Little, J. J. (2014). Stacked quantizers for compositional vector compression. arXiv preprint arXiv:1411.2173. [ArXiv]