pub struct DistanceWeightedMetaModel { /* private fields */ }Expand description
Picks the training record that maximizes evidence × w(distance),
where w(d) = 1 / (d + epsilon) over z-score-normalized Euclidean
distance and evidence is MetaTrainingRecord::score_lift when
present, falling back to best_score for legacy records.
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 evidence into the selection — a record is “good” if
it’s both similar to the query AND demonstrated real tuner signal.
Using lift instead of the raw score avoids the easy-corpus bias:
best_score = 0.9 on an easy corpus is weaker evidence than
best_score = 0.6 that beat its run’s mean by a wide margin. At
N = 1 this degenerates to NN (same record either way).
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 (const: unstable) · 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 is_fitted(&self) -> bool
fn is_fitted(&self) -> bool
fit has been called with at least one usable record.
Self::predict panics when this is false, so Result-returning
boundaries (e.g. SphereQLPipeline::new_from_metamodel) check
this first. No default impl on purpose: every model must answer
for its own notion of “fitted” rather than inherit a guess.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, or check Self::is_fitted when the
training state isn’t statically known.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> 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>
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