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 (f32orf64).I— the input type passed to each metric.E: Scorable<T, I>— the metric enum generated byfinite_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.6Implementations§
Source§impl<T: Float, I, E: Scorable<T, I>> FiniteScoreSet<T, I, E>
impl<T: Float, I, E: Scorable<T, I>> FiniteScoreSet<T, I, E>
Sourcepub fn sum(&self, input: &I) -> T
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.
Sourcepub fn score(&self) -> FiniteScoreStage<'_, T, I, E>
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))
})
});Sourcepub fn iter(&self) -> impl Iterator<Item = &FiniteMember<T, E>>
pub fn iter(&self) -> impl Iterator<Item = &FiniteMember<T, E>>
Iterate over the members.
Sourcepub fn builder() -> FiniteScoreSetBuilder<T, I, E>
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.