alter_ego / serving /src /trust.rs
geraldaton20's picture
initial upload: source code (no build artifacts)
f4f166e verified
Raw History Blame Contribute Delete
2.11 kB
//! The Alter-Ego Trust Score and verdict thresholds.
//!
//! Every experience is scored on five axes and combined into a single
//! trust score. Weights and thresholds are the PRD's starting design
//! (uncalibrated); they are centralized here so calibration is a one-line edit.
pub const W_STRUCTURAL: f32 = 0.15;
pub const W_CONSISTENCY: f32 = 0.25;
pub const W_VERIFIABILITY: f32 = 0.30;
pub const W_NOVELTY: f32 = 0.20;
pub const W_SAFETY: f32 = 0.10;
pub const COMMIT_THRESHOLD: f32 = 0.80;
pub const QUEUE_THRESHOLD: f32 = 0.35;
#[derive(Debug, Clone, Default)]
pub struct TrustScore {
pub structural: f32,
pub consistency: f32,
pub verifiability: f32,
pub novelty: f32,
pub safety: f32,
pub total: f32,
}
impl TrustScore {
/// Combine the five axes into the weighted total.
pub fn combine(
structural: f32,
consistency: f32,
verifiability: f32,
novelty: f32,
safety: f32,
) -> Self {
let total = W_STRUCTURAL * structural
+ W_CONSISTENCY * consistency
+ W_VERIFIABILITY * verifiability
+ W_NOVELTY * novelty
+ W_SAFETY * safety;
Self {
structural,
consistency,
verifiability,
novelty,
safety,
total,
}
}
/// Map the score to a verdict: COMMIT / QUEUE / REJECT.
pub fn verdict(&self) -> Verdict {
if self.total >= COMMIT_THRESHOLD {
Verdict::Commit
} else if self.total >= QUEUE_THRESHOLD {
Verdict::Queue
} else {
Verdict::Reject
}
}
}
/// Verdict on an experience, decided by the alter ego.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Verdict {
Commit,
Queue,
Reject,
}
impl std::fmt::Display for Verdict {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let s = match self {
Verdict::Commit => "COMMIT",
Verdict::Queue => "QUEUE",
Verdict::Reject => "REJECT",
};
f.write_str(s)
}
}