pub struct BinaryQuantizer { /* private fields */ }Expand description
Binary quantizer (BQ): one bit per dimension, 32× compression.
Build one with BinaryQuantizer::new (or Default), train it once
with a representative sample, then quantize and compare. BQ supports
DistanceMetric::Hamming only; other metrics return
IqdbError::InvalidMetric.
§Examples
use iqdb_quantize::{BinaryQuantizer, Quantizer};
use iqdb_types::DistanceMetric;
let mut bq = BinaryQuantizer::new();
bq.train(&[&[0.0_f32, 1.0, 2.0][..], &[2.0_f32, 1.0, 0.0][..]])
.expect("two non-empty, finite vectors of equal dim");
let code = bq.quantize(&[0.5_f32, 1.5, 2.5]).expect("dim matches");
let d = bq
.distance(&[0.5_f32, 1.5, 2.5], &code, DistanceMetric::Hamming)
.expect("dim matches");
// Self-distance is zero.
assert_eq!(d, 0.0);Implementations§
Source§impl BinaryQuantizer
impl BinaryQuantizer
Sourcepub fn new() -> Self
pub fn new() -> Self
Build an untrained binary quantizer.
Every hot method returns IqdbError::InvalidConfig until
Quantizer::train succeeds.
§Examples
use iqdb_quantize::BinaryQuantizer;
let _bq = BinaryQuantizer::new();Trait Implementations§
Source§impl Clone for BinaryQuantizer
impl Clone for BinaryQuantizer
Source§fn clone(&self) -> BinaryQuantizer
fn clone(&self) -> BinaryQuantizer
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for BinaryQuantizer
impl Debug for BinaryQuantizer
Source§impl Default for BinaryQuantizer
impl Default for BinaryQuantizer
Source§fn default() -> BinaryQuantizer
fn default() -> BinaryQuantizer
Returns the “default value” for a type. Read more
Source§impl PartialEq for BinaryQuantizer
impl PartialEq for BinaryQuantizer
Source§fn eq(&self, other: &BinaryQuantizer) -> bool
fn eq(&self, other: &BinaryQuantizer) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl Quantizer for BinaryQuantizer
impl Quantizer for BinaryQuantizer
Source§type Quantized = BqCode
type Quantized = BqCode
The compact code produced by
Quantizer::quantize.Source§fn train(&mut self, vectors: &[&[f32]]) -> Result<()>
fn train(&mut self, vectors: &[&[f32]]) -> Result<()>
Train the quantizer from a sample of representative vectors. Read more
Source§fn quantize(&self, vector: &[f32]) -> Result<Self::Quantized>
fn quantize(&self, vector: &[f32]) -> Result<Self::Quantized>
Encode
vector as a compact code. Read moreimpl StructuralPartialEq for BinaryQuantizer
Auto Trait Implementations§
impl Freeze for BinaryQuantizer
impl RefUnwindSafe for BinaryQuantizer
impl Send for BinaryQuantizer
impl Sync for BinaryQuantizer
impl Unpin for BinaryQuantizer
impl UnsafeUnpin for BinaryQuantizer
impl UnwindSafe for BinaryQuantizer
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
Mutably borrows from an owned value. Read more