Skip to main content

FiniteScoreSet

Struct FiniteScoreSet 

Source
pub struct FiniteScoreSet<T: Float, I, E> { /* private fields */ }
Expand description

A weighted set of scoring operators using enum-based static dispatch.

FiniteScoreSet stores a Vec of FiniteMembers, each wrapping a variant of a user-declared metric enum. At evaluation time, the enum’s eval method dispatches via match — zero vtable overhead for all non-Custom variants.

Construct via finite_score_set!, the FiniteScoreSetBuilder, or call .score() directly.

§Type parameters

  • T: Float — the floating-point type (f32 or f64).
  • I — the input type passed to each metric.
  • E: Scorable<T, I> — the metric enum generated by finite_metric!.

§Example

let set = FiniteScoreSet::<f64, &str, TestKind<f64, &str>>::normalize(vec![
    (2.0, TestKind::AlwaysZero(ConstMetric::new("zero", 0.0))),
    (3.0, TestKind::AlwaysOne(ConstMetric::new("one", 1.0))),
])?;

let total = set.sum(&"input");
// total = 0.4 * 0 + 0.6 * 1 = 0.6

Implementations§

Source§

impl<T: Float, I, E: Scorable<T, I>> FiniteScoreSet<T, I, E>

Source

pub fn sum(&self, input: &I) -> T

Evaluate all metrics against input and sum their weighted contributions.

This is the most common aggregation: each metric is evaluated, multiplied by its normalized weight, and summed. Zero-allocation convenience.

For custom aggregation, use .score() instead.

Source

pub fn score(&self) -> FiniteScoreStage<'_, T, I, E>

Enter the scoring stage, returning a reference to all members.

Use .by() on the returned stage to apply a custom aggregation, or .sum() for the standard weighted-sum shortcut.

§Example
let total = set.score().by(|members| {
    members.iter().fold(0.0, |acc, m| {
        acc + m.contribute(m.metric().eval(&input))
    })
});
Source

pub fn len(&self) -> usize

Return the number of members in this set.

Source

pub fn is_empty(&self) -> bool

Return true if the set has no members.

Source

pub fn iter(&self) -> impl Iterator<Item = &FiniteMember<T, E>>

Iterate over the members.

Source

pub fn breakdown(&self, input: &I) -> Vec<Breakdown<'_, T>>

Evaluate all metrics against input and return a per-metric breakdown.

Unlike .sum() which returns only the aggregate, breakdown returns one Breakdown row per member with the metric’s name, raw score, normalized weight, and weighted contribution.

Source

pub fn builder() -> FiniteScoreSetBuilder<T, I, E>

Create a builder for incremental construction of a FiniteScoreSet.

Use this when members are not known up front — push them one by one, then call .build() to finalize.

Auto Trait Implementations§

§

impl<T, I, E> Freeze for FiniteScoreSet<T, I, E>

§

impl<T, I, E> RefUnwindSafe for FiniteScoreSet<T, I, E>

§

impl<T, I, E> Send for FiniteScoreSet<T, I, E>
where I: Send, E: Send, T: Send,

§

impl<T, I, E> Sync for FiniteScoreSet<T, I, E>
where I: Sync, E: Sync, T: Sync,

§

impl<T, I, E> Unpin for FiniteScoreSet<T, I, E>
where I: Unpin, E: Unpin, T: Unpin,

§

impl<T, I, E> UnsafeUnpin for FiniteScoreSet<T, I, E>

§

impl<T, I, E> UnwindSafe for FiniteScoreSet<T, I, E>
where I: UnwindSafe, E: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WitnessExt for T

Source§

fn witness(self) -> Witnessing<Self>