pub mod decision;
pub mod error;
pub mod group;
pub mod metrics;
pub mod observation;
pub mod schema;
pub mod stream;
pub use decision::Thresholds;
pub use error::{Error, Result};
pub use metrics::{
CalibrationResult, DecisionScore, MinRequirements, ScoreConfig, ScoreDispersion, ScoreWeights,
compute_calibration, compute_evaluator_reliability, compute_evaluator_weights,
compute_fleiss_kappa, compute_krippendorff_alpha, compute_report, compute_weighted_majority,
score_all,
};
pub use observation::{Observation, parse_csv, parse_jsonl};
pub use schema::{Decision, StabilityComponents, StabilityReport};
pub use stream::StreamingScorer;
use std::collections::HashMap;
pub fn score_all_weighted(
observations: Vec<Observation>,
config: &ScoreConfig,
) -> Vec<StabilityReport> {
let mut reports = metrics::score_all(observations.clone(), config);
let majority_map: HashMap<String, String> = reports
.iter()
.filter_map(|r| r.majority_label.clone().map(|ml| (r.sample_id.clone(), ml)))
.collect();
let gold_map: HashMap<String, String> = observations
.iter()
.filter_map(|o| o.gold_label.clone().map(|g| (o.sample_id.clone(), g)))
.collect();
let truth: HashMap<String, String> = majority_map
.into_iter()
.map(|(id, ml)| {
let label = gold_map.get(&id).cloned().unwrap_or(ml);
(id, label)
})
.collect();
let evaluator_weights = metrics::compute_evaluator_weights(&observations, &truth);
let groups = group::group_by_sample_id(observations.into_iter());
for report in &mut reports {
if let Some(obs) = groups.get(&report.sample_id) {
let (wml, wlc, wld, conflict) = metrics::compute_weighted_majority(
obs,
report.majority_label.as_deref(),
&evaluator_weights,
);
report.weighted_majority_label = wml;
report.weighted_label_confidence = wlc;
report.weighted_label_distribution = wld;
report.majority_weighted_conflict = conflict;
}
}
reports
}