pub struct DistanceWeightedMetaModel { /* private fields */ }Expand description
Picks the training record that maximizes best_score × w(distance),
where w(d) = 1 / (d + epsilon) over z-score-normalized Euclidean
distance.
The distinction from NearestNeighborMetaModel: NN picks the
closest record regardless of how well that record performed, so a
single poorly-tuned outlier can pull predictions off. Distance-weighted
folds the record’s score into the selection — a record is “good” if
it’s both similar to the query AND had a high score. At N = 1 this
degenerates to NN (same record either way). At N ≥ 3 the two models
start diverging in predictable, useful ways.
epsilon is a smoothing floor on the distance term; at d ≈ 0 it
prevents the weight from exploding and over-committing to a single
near-duplicate record. Default 0.1.
Implementations§
Source§impl DistanceWeightedMetaModel
impl DistanceWeightedMetaModel
pub fn new() -> Self
Sourcepub fn with_epsilon(self, epsilon: f64) -> Self
pub fn with_epsilon(self, epsilon: f64) -> Self
Override the smoothing constant added to distance before
inversion. Larger epsilon makes predictions smoother; smaller
sharpens the preference for near-duplicate records. Must be
strictly positive (silently clamped to 1e-12 if a zero or
negative value is passed).
pub fn records(&self) -> &[MetaTrainingRecord]
Sourcepub fn score_candidates(
&self,
features: &CorpusFeatures,
) -> Vec<(usize, f64, f64)>
pub fn score_candidates( &self, features: &CorpusFeatures, ) -> Vec<(usize, f64, f64)>
Per-record (weighted_score, distance) pairs for the given query features, sorted by descending weighted score. Useful for introspecting why a particular prediction was made.
Trait Implementations§
Source§impl Clone for DistanceWeightedMetaModel
impl Clone for DistanceWeightedMetaModel
Source§fn clone(&self) -> DistanceWeightedMetaModel
fn clone(&self) -> DistanceWeightedMetaModel
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DistanceWeightedMetaModel
impl Debug for DistanceWeightedMetaModel
Source§impl Default for DistanceWeightedMetaModel
impl Default for DistanceWeightedMetaModel
Source§impl MetaModel for DistanceWeightedMetaModel
impl MetaModel for DistanceWeightedMetaModel
Source§fn fit(&mut self, records: &[MetaTrainingRecord])
fn fit(&mut self, records: &[MetaTrainingRecord])
Source§fn predict(&self, features: &CorpusFeatures) -> PipelineConfig
fn predict(&self, features: &CorpusFeatures) -> PipelineConfig
fit has not been called with at least
one record — callers should treat MetaModel as a trained object
and front-load fit.Auto Trait Implementations§
impl Freeze for DistanceWeightedMetaModel
impl RefUnwindSafe for DistanceWeightedMetaModel
impl Send for DistanceWeightedMetaModel
impl Sync for DistanceWeightedMetaModel
impl Unpin for DistanceWeightedMetaModel
impl UnsafeUnpin for DistanceWeightedMetaModel
impl UnwindSafe for DistanceWeightedMetaModel
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 more