pub struct FeatureHasher { /* private fields */ }Expand description
Feature hashing (hashing trick) preprocessor.
Maps an arbitrary-length input feature vector to a fixed-size output of
n_buckets dimensions. For each input feature at index i:
- A bucket is chosen:
bucket = hash(i, BUCKET_SEED) % n_buckets. - A sign is chosen:
sign = if hash(i, SIGN_SEED) & 1 == 0 { +1 } else { -1 }. - The output accumulates:
output[bucket] += sign * features[i].
The sign-flipping ensures that the inner product of two hashed vectors is an unbiased estimator of the original inner product (Weinberger et al., 2009).
Because the transform is purely deterministic and stateless, both
update_and_transform and
transform behave identically, and
reset is a no-op.
Implementations§
Trait Implementations§
Source§impl Clone for FeatureHasher
impl Clone for FeatureHasher
Source§fn clone(&self) -> FeatureHasher
fn clone(&self) -> FeatureHasher
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 FeatureHasher
impl Debug for FeatureHasher
Source§impl StreamingPreprocessor for FeatureHasher
impl StreamingPreprocessor for FeatureHasher
Source§fn update_and_transform(&mut self, features: &[f64]) -> Vec<f64>
fn update_and_transform(&mut self, features: &[f64]) -> Vec<f64>
Update internal statistics from this sample and return transformed features. Read more
Source§fn transform(&self, features: &[f64]) -> Vec<f64>
fn transform(&self, features: &[f64]) -> Vec<f64>
Transform features using current statistics without updating them. Read more
Source§fn output_dim(&self) -> Option<usize>
fn output_dim(&self) -> Option<usize>
Number of output features, or
None if unknown until the first sample.Auto Trait Implementations§
impl Freeze for FeatureHasher
impl RefUnwindSafe for FeatureHasher
impl Send for FeatureHasher
impl Sync for FeatureHasher
impl Unpin for FeatureHasher
impl UnsafeUnpin for FeatureHasher
impl UnwindSafe for FeatureHasher
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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