pub struct CompensatedCosineNormalized { /* private fields */ }Expand description
Compensated CosineNormalized distance function.
Implementations§
Trait Implementations§
Source§impl AsFunctor<CompensatedCosineNormalized> for ScalarQuantizer
impl AsFunctor<CompensatedCosineNormalized> for ScalarQuantizer
fn as_functor(&self) -> CompensatedCosineNormalized
Source§impl Clone for CompensatedCosineNormalized
impl Clone for CompensatedCosineNormalized
Source§fn clone(&self) -> CompensatedCosineNormalized
fn clone(&self) -> CompensatedCosineNormalized
Returns a duplicate of the value. Read more
1.0.0 · 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 CompensatedCosineNormalized
impl Debug for CompensatedCosineNormalized
Source§impl<const NBITS: usize> DistanceFunction<VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, Compensation>>, VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, Compensation>>, Result<MathematicalValue<f32>, UnequalLengths>> for CompensatedCosineNormalizedwhere
Unsigned: Representation<NBITS>,
SquaredL2: for<'a, 'b> PureDistanceFunction<BitSlice<'a, NBITS, Unsigned>, BitSlice<'b, NBITS, Unsigned>, MathematicalResult<u32>>,
CosineNormalized
impl<const NBITS: usize> DistanceFunction<VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, Compensation>>, VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, Compensation>>, Result<MathematicalValue<f32>, UnequalLengths>> for CompensatedCosineNormalizedwhere
Unsigned: Representation<NBITS>,
SquaredL2: for<'a, 'b> PureDistanceFunction<BitSlice<'a, NBITS, Unsigned>, BitSlice<'b, NBITS, Unsigned>, MathematicalResult<u32>>,
CosineNormalized
This implementation calculates the <x, y> = 1 - L2 / 2 value, which will be further used to compute the CosineNormalised distance function
§Notes
s = 1 - cosine(X, Y) = 1- <X, Y> / (||X|| * ||Y||)
We can make simply assumption that ||X|| = 1 and ||Y|| = 1. Then s = 1 - <X, Y>
The squared L2 distance can be computed as follows: p = ||x||^2 + ||y||^2 - 2<x, y> When vectors are normalized, this becomes p = 2 - 2<x, y> = 2 * (1 - <x, y>)
In other words, the similarity score for the squared L2 distance in an ideal world is 2 times that for cosine similarity. Therefore, squared L2 may serves as a stand-in for cosine normalized as ordering is preserved.
Source§fn evaluate_similarity(
&self,
x: CompensatedVectorRef<'_, NBITS>,
y: CompensatedVectorRef<'_, NBITS>,
) -> MathematicalResult<f32>
fn evaluate_similarity( &self, x: CompensatedVectorRef<'_, NBITS>, y: CompensatedVectorRef<'_, NBITS>, ) -> MathematicalResult<f32>
Perform a distance computation between the left-hand and right-hand arguments.
Source§impl<const NBITS: usize> DistanceFunction<VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, Compensation>>, VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, Compensation>>, Result<f32, UnequalLengths>> for CompensatedCosineNormalizedwhere
Unsigned: Representation<NBITS>,
Self: for<'a, 'b> DistanceFunction<CompensatedVectorRef<'a, NBITS>, CompensatedVectorRef<'b, NBITS>, MathematicalResult<f32>>,
impl<const NBITS: usize> DistanceFunction<VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, Compensation>>, VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, Compensation>>, Result<f32, UnequalLengths>> for CompensatedCosineNormalizedwhere
Unsigned: Representation<NBITS>,
Self: for<'a, 'b> DistanceFunction<CompensatedVectorRef<'a, NBITS>, CompensatedVectorRef<'b, NBITS>, MathematicalResult<f32>>,
Source§fn evaluate_similarity(
&self,
x: CompensatedVectorRef<'_, NBITS>,
y: CompensatedVectorRef<'_, NBITS>,
) -> Result<f32>
fn evaluate_similarity( &self, x: CompensatedVectorRef<'_, NBITS>, y: CompensatedVectorRef<'_, NBITS>, ) -> Result<f32>
Perform a distance computation between the left-hand and right-hand arguments.
impl Copy for CompensatedCosineNormalized
Auto Trait Implementations§
impl Freeze for CompensatedCosineNormalized
impl RefUnwindSafe for CompensatedCosineNormalized
impl Send for CompensatedCosineNormalized
impl Sync for CompensatedCosineNormalized
impl Unpin for CompensatedCosineNormalized
impl UnsafeUnpin for CompensatedCosineNormalized
impl UnwindSafe for CompensatedCosineNormalized
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
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>
Converts
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>
Converts
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 more