pub mod agreement;
pub mod calibration;
pub mod config;
pub mod decision;
pub mod error;
pub mod group;
pub mod observation;
pub mod schema;
pub mod scoring;
pub mod stream;
pub mod weighting;
pub use agreement::{compute_fleiss_kappa, compute_krippendorff_alpha};
pub use calibration::{CalibrationResult, compute_calibration};
pub use config::{DecisionScore, MinRequirements, ScoreConfig, ScoreDispersion, ScoreWeights};
pub use decision::Thresholds;
pub use error::{Error, Result};
pub use observation::{Observation, parse_csv, parse_jsonl};
pub use schema::{Decision, StabilityComponents, StabilityReport};
pub use scoring::{compute_report, score_all};
pub use stream::StreamingScorer;
pub use weighting::{
compute_evaluator_label_weights, compute_evaluator_reliability, compute_evaluator_weights,
compute_weighted_majority, compute_weighted_majority_by_label,
};
use std::collections::HashMap;
pub fn score_all_weighted(
observations: Vec<Observation>,
config: &ScoreConfig,
) -> Vec<StabilityReport> {
let mut reports = scoring::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 = weighting::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) = weighting::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
}
pub fn score_all_gold_weighted(
observations: Vec<Observation>,
config: &ScoreConfig,
) -> Vec<StabilityReport> {
let mut reports = scoring::score_all(observations.clone(), config);
let truth: HashMap<String, String> = observations
.iter()
.filter_map(|o| o.gold_label.clone().map(|g| (o.sample_id.clone(), g)))
.collect();
let label_weights = weighting::compute_evaluator_label_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) = weighting::compute_weighted_majority_by_label(
obs,
report.majority_label.as_deref(),
&label_weights,
);
*report = scoring::compute_report_inner(&report.sample_id, obs, config, wlc);
report.weighted_majority_label = wml;
report.weighted_label_confidence = wlc;
report.weighted_label_distribution = wld;
report.majority_weighted_conflict = conflict;
}
}
reports
}