eval.score_calculator

chunktuner.eval.score_calculator

Weighted scalar score from EvalMetrics for a use case.

ScoreCalculator

ScoreCalculator(use_case, custom_weights=None)

Weighted sum of EvalMetrics fields for a use-case profile.

Source code in src/chunktuner/eval/score_calculator.py
def __init__(self, use_case: str, custom_weights: dict[str, float] | None = None):
    self.use_case = use_case
    self.weights = dict(custom_weights) if custom_weights else score_profile_weights(use_case)
    if custom_weights is not None:
        pos = sum(w for w in self.weights.values() if w > 0)
        if pos <= 0:
            raise ValueError(
                f"custom_weights must contain at least one positive weight; got {self.weights}"
            )

score

score(metrics)

Return a scalar score from weighted metric contributions (missing keys skipped).

Source code in src/chunktuner/eval/score_calculator.py
def score(self, metrics: EvalMetrics) -> float:
    """Return a scalar score from weighted metric contributions (missing keys skipped)."""
    total = 0.0
    for key, w in self.weights.items():
        val = _metric_value(metrics, key)
        if val is None:
            continue
        total += w * float(val)
    return total