Skip to main content

DynamicScoreSet

Struct DynamicScoreSet 

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

A weighted set of scoring operators using dynamic dispatch.

DynamicScoreSet stores a Vec of DynamicMembers, each holding a Box<dyn Scorable<T, I>>. Every evaluation call pays vtable overhead, but the set can contain completely heterogeneous metric types and can be assembled at runtime.

Construct via dynamic_score_set!, the DynamicScoreSetBuilder, or call .score() directly.

§Type parameters

  • T: Float — the floating-point type (f32 or f64).
  • I — the input type passed to each metric.

§Example

let gc: Box<dyn Scorable<f64, &str>> = Box::new(gc_metric);
let len: Box<dyn Scorable<f64, &str>> = Box::new(len_metric);

let set = DynamicScoreSet::<f64, &str>::normalize(vec![
    (2.0, gc),
    (3.0, len),
])?;

let total = set.sum(&"ACGTACGT");

Implementations§

Source§

impl<T: Float, I> DynamicScoreSet<T, I>

Source

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

Evaluate all metrics against input and sum their weighted contributions.

Zero-allocation convenience for the most common aggregation. For custom aggregation, use .score() instead.

Source

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

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 = &DynamicMember<T, I>>

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.

§Example
for row in set.breakdown(&ctx) {
    println!("{}: {:.3} × {:.3} = {:.3}",
        row.name, row.score, row.weight, row.contribution);
}
Source

pub fn builder() -> DynamicScoreSetBuilder<T, I>

Create a builder for incremental construction of a DynamicScoreSet.

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

§Example
let set = DynamicScoreSet::<f64, &str>::builder()
    .push(2.0, gc_metric.boxed())?
    .push(3.0, len_metric.boxed())?
    .build()?;

Auto Trait Implementations§

§

impl<T, I> !RefUnwindSafe for DynamicScoreSet<T, I>

§

impl<T, I> !Send for DynamicScoreSet<T, I>

§

impl<T, I> !Sync for DynamicScoreSet<T, I>

§

impl<T, I> !UnwindSafe for DynamicScoreSet<T, I>

§

impl<T, I> Freeze for DynamicScoreSet<T, I>

§

impl<T, I> Unpin for DynamicScoreSet<T, I>
where T: Unpin,

§

impl<T, I> UnsafeUnpin for DynamicScoreSet<T, I>

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>