pub struct FibMultiLevelQuantizer { /* private fields */ }Expand description
Multi-level additive quantizer: main codebook + N trained residual codebooks.
Each residual level is trained with Lloyd-Max on the residual distribution from the previous levels, producing codebooks adapted to the actual data rather than random directions.
num_levels = 1 means main only (no residual codebooks).
num_levels = 2 means main + 1 residual level (equivalent to 2-level).
num_levels = 3 means main + 2 residual levels.
Implementations§
Source§impl FibMultiLevelQuantizer
impl FibMultiLevelQuantizer
Sourcepub fn new(
profile: FibQuantProfileV1,
num_levels: usize,
residual_sizes: Vec<usize>,
) -> Result<Self>
pub fn new( profile: FibQuantProfileV1, num_levels: usize, residual_sizes: Vec<usize>, ) -> Result<Self>
Build a multi-level quantizer with trained residual codebooks.
§Arguments
profile- The quantization profile.num_levels- Total number of levels (1 = main only, 2 = main + 1 residual, etc.).residual_sizes- Number of codewords for each residual level (length must benum_levels - 1).
Sourcepub fn quantizer(&self) -> &FibQuantizer
pub fn quantizer(&self) -> &FibQuantizer
Access the main quantizer.
Sourcepub fn residual_codebooks(&self) -> &[ResidualCodebookV1]
pub fn residual_codebooks(&self) -> &[ResidualCodebookV1]
Access all residual codebooks.
Sourcepub fn num_levels(&self) -> usize
pub fn num_levels(&self) -> usize
Total number of levels (1 + residual codebooks count).
Sourcepub fn multi_level_codebook(&self) -> MultiLevelResidualCodebookV1
pub fn multi_level_codebook(&self) -> MultiLevelResidualCodebookV1
Get a MultiLevelResidualCodebookV1 view of the residual codebooks.
Sourcepub fn encode(&self, x: &[f32]) -> Result<MultiLevelCode>
pub fn encode(&self, x: &[f32]) -> Result<MultiLevelCode>
Encode a vector with multi-level additive quantization.
Encodes with the main codebook, then iteratively encodes the residual with each residual level: residual[i+1] = residual[i] - cw_i[idx_i].
Sourcepub fn decode(&self, code: &MultiLevelCode) -> Result<Vec<f32>>
pub fn decode(&self, code: &MultiLevelCode) -> Result<Vec<f32>>
Decode a multi-level code.
Reconstructs: codeword[main] + residual_cw[0] + residual_cw[1] + … then applies inverse rotation and norm scaling.
Sourcepub fn cosine_similarity(&self, x: &[f32]) -> Result<f64>
pub fn cosine_similarity(&self, x: &[f32]) -> Result<f64>
Reconstruction cosine similarity.
Trait Implementations§
Source§impl Clone for FibMultiLevelQuantizer
impl Clone for FibMultiLevelQuantizer
Source§fn clone(&self) -> FibMultiLevelQuantizer
fn clone(&self) -> FibMultiLevelQuantizer
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for FibMultiLevelQuantizer
impl RefUnwindSafe for FibMultiLevelQuantizer
impl Send for FibMultiLevelQuantizer
impl Sync for FibMultiLevelQuantizer
impl Unpin for FibMultiLevelQuantizer
impl UnsafeUnpin for FibMultiLevelQuantizer
impl UnwindSafe for FibMultiLevelQuantizer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.