Skip to main content

Objective

Trait Objective 

Source
pub trait Objective<T>: Send + Sync {
    // Required method
    fn score(&self, candidate: &T, context: &ObjectiveContext) -> f64;

    // Provided methods
    fn precision(&self, _candidate: &T, _context: &ObjectiveContext) -> f64 { ... }
    fn passes_score(&self, score: f64, context: &ObjectiveContext) -> bool { ... }
    fn passes(&self, candidate: &T, context: &ObjectiveContext) -> bool { ... }
    fn batch_score(
        &self,
        candidates: &[T],
        context: &ObjectiveContext,
    ) -> Vec<(usize, f64)> { ... }
    fn select<'a>(
        &self,
        candidates: &'a [T],
        context: &ObjectiveContext,
    ) -> Vec<Selection<&'a T>> { ... }
    fn select_top<'a>(
        &self,
        candidates: &'a [T],
        n: usize,
        context: &ObjectiveContext,
    ) -> Vec<Selection<&'a T>> { ... }
    fn name(&self) -> &str { ... }
}
Expand description

Deterministic, composable objective function over a candidate set.

Required Methods§

Source

fn score(&self, candidate: &T, context: &ObjectiveContext) -> f64

Evaluate a single candidate.

Provided Methods§

Source

fn precision(&self, _candidate: &T, _context: &ObjectiveContext) -> f64

Precision (inverse variance) of the score estimate; default 1.0 (fully trusted).

Source

fn passes_score(&self, score: f64, context: &ObjectiveContext) -> bool

Check if a score passes the threshold; non-finite scores never pass.

Source

fn passes(&self, candidate: &T, context: &ObjectiveContext) -> bool

Check if a candidate passes the threshold.

Source

fn batch_score( &self, candidates: &[T], context: &ObjectiveContext, ) -> Vec<(usize, f64)>

Score a batch of candidates and return passing (index, score) pairs.

Source

fn select<'a>( &self, candidates: &'a [T], context: &ObjectiveContext, ) -> Vec<Selection<&'a T>>

Select all passing candidates in score-descending order.

Source

fn select_top<'a>( &self, candidates: &'a [T], n: usize, context: &ObjectiveContext, ) -> Vec<Selection<&'a T>>

Select the top N candidates by precision-weighted score.

Source

fn name(&self) -> &str

Get the name of this objective.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T, F> Objective<T> for F
where F: Fn(&T, &ObjectiveContext) -> f64 + Send + Sync,

Implement Objective for closures.

Source§

impl<T, O: Objective<T>> Objective<T> for ScaleObjective<O>

Source§

impl<T: HasSalience + Send + Sync> Objective<T> for SalienceObjective

Source§

impl<T: HasTimestamp + HasSalience + Send + Sync> Objective<T> for RelevanceObjective

Source§

impl<T: HasTimestamp + Send + Sync> Objective<T> for RecencyObjective

Source§

impl<T: Send + Sync, F> Objective<T> for FirstMatchObjective<T, F>
where F: Fn(&T) -> bool + Send + Sync,

Source§

impl<T: Send + Sync, F> Objective<T> for MaxScoreObjective<T, F>
where F: Fn(&T) -> f64 + Send + Sync,

Source§

impl<T: Send + Sync, F> Objective<T> for ThresholdObjective<T, F>
where F: Fn(&T) -> f64 + Send + Sync,

Source§

impl<T: Send + Sync> Objective<T> for ConsensusObjective<T>

Source§

impl<T: Send + Sync> Objective<T> for NegateObjective<T>

Source§

impl<T: Send + Sync> Objective<T> for PriorityObjective<T>

Source§

impl<T: Send + Sync> Objective<T> for UnionObjective<T>

Source§

impl<T: Send + Sync> Objective<T> for WeightedObjective<T>