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 (f32orf64).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>
impl<T: Float, I> DynamicScoreSet<T, I>
Sourcepub fn sum(&self, input: &I) -> T
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.
Sourcepub fn score(&self) -> DynamicScoreStage<'_, T, I>
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))
})
});Sourcepub fn iter(&self) -> impl Iterator<Item = &DynamicMember<T, I>>
pub fn iter(&self) -> impl Iterator<Item = &DynamicMember<T, I>>
Iterate over the members.
Sourcepub fn breakdown(&self, input: &I) -> Vec<Breakdown<'_, T>>
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);
}Sourcepub fn builder() -> DynamicScoreSetBuilder<T, I>
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()?;