Upload crates/iosdiag-core/src/inference/scoring.rs with huggingface_hub
Browse files
crates/iosdiag-core/src/inference/scoring.rs
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//! Scoring system for diagnostic confidence
|
| 2 |
+
|
| 3 |
+
/// Scorer for calculating confidence levels
|
| 4 |
+
pub struct Scorer;
|
| 5 |
+
|
| 6 |
+
impl Scorer {
|
| 7 |
+
/// Calculate confidence score based on evidence
|
| 8 |
+
pub fn calculate_confidence(evidence_count: usize, evidence_quality: f32) -> f32 {
|
| 9 |
+
let count_factor = (evidence_count as f32).min(10.0) / 10.0;
|
| 10 |
+
(count_factor * evidence_quality).min(1.0)
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
/// Calculate severity score
|
| 14 |
+
pub fn calculate_severity(impact: &str) -> f32 {
|
| 15 |
+
match impact {
|
| 16 |
+
"critical" => 1.0,
|
| 17 |
+
"high" => 0.75,
|
| 18 |
+
"medium" => 0.5,
|
| 19 |
+
"low" => 0.25,
|
| 20 |
+
_ => 0.0,
|
| 21 |
+
}
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
/// Combine multiple scores
|
| 25 |
+
pub fn combine_scores(scores: &[f32]) -> f32 {
|
| 26 |
+
if scores.is_empty() {
|
| 27 |
+
return 0.0;
|
| 28 |
+
}
|
| 29 |
+
scores.iter().sum::<f32>() / scores.len() as f32
|
| 30 |
+
}
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
#[cfg(test)]
|
| 34 |
+
mod tests {
|
| 35 |
+
use super::*;
|
| 36 |
+
|
| 37 |
+
#[test]
|
| 38 |
+
fn test_calculate_confidence() {
|
| 39 |
+
assert_eq!(Scorer::calculate_confidence(5, 0.8), 0.4);
|
| 40 |
+
assert_eq!(Scorer::calculate_confidence(10, 1.0), 1.0);
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
#[test]
|
| 44 |
+
fn test_calculate_severity() {
|
| 45 |
+
assert_eq!(Scorer::calculate_severity("critical"), 1.0);
|
| 46 |
+
assert_eq!(Scorer::calculate_severity("low"), 0.25);
|
| 47 |
+
}
|
| 48 |
+
}
|