score-set
A Rust library for building static weighted scoring operator sets. Declare a set of named metrics with weights, normalize at build time, score at runtime via a user-provided closure that freely injects inputs and context.
Usage
use *;
// 1. Build metrics
let gc = metric
.measure
.by
.map01
.by;
let length = metric
.measure
.by
.map01
.by;
// 2. Declare the set — weights are normalized automatically
let ms = score_set! ?;
// 3. Score with runtime data
let dna = "ACGTACGT";
let score = ms.score.by;
// score ≈ 0.248
# Ok::
Concepts
Metrics. A Metric is a two-stage scoring operator: measure maps input to a raw value, map01 maps the raw value (with the original input still available for context) to a validated [0, 1] score.
metric
.measure.by
.map01.by
Score Sets. score_set! declares a weighted set of metrics. Weights are validated strictly positive and normalized to sum to 1. Validation fails at build time if any weight is ≤ 0.
let ms = score_set! ?;
Scoring. score().by(closure) gives access to every member. Each member provides .metric() (the operator) and .contribute(value01) (score × normalized weight). The closure composes contributions arbitrarily — different operators can consume different input shapes, capture external context, or conditionally participate.
Linear combination:
let score = ms.score.by;
Geometric (product) — all-or-nothing scoring sensitive to any weak metric:
let score = ms.score.by;
Controlled values.
| Function | Returns | Guarantee |
|---|---|---|
Value01::witness(v) |
Witnessed<T, Value01> |
finite, ∈ [0, 1] |
NormalizedContainer::witness(vec) |
Witnessed<Vec<T>, NormalizedContainer> |
all ∈ [0, 1], sum = 1 |
NormalizedWeight credentials are extracted from a validated container via NormalizedWeight::from_normalized_container(value, &container), which binary-searches for membership verification.
Arity
Default supports up to 8 metrics per set. Opt into larger arities via Cargo features:
= { = ["level-16"] } # up to 16
= { = ["level-128"] } # up to 128
License
MIT OR Apache-2.0