ruvector_tiny_dancer_core/
uncertainty.rs1pub struct UncertaintyEstimator {
5 calibration_quantile: f32,
7}
8
9impl UncertaintyEstimator {
10 pub fn new() -> Self {
12 Self {
13 calibration_quantile: 0.9, }
15 }
16
17 pub fn with_quantile(quantile: f32) -> Self {
19 Self {
20 calibration_quantile: quantile,
21 }
22 }
23
24 pub fn estimate(&self, _features: &[f32], prediction: f32) -> f32 {
31 let boundary_distance = (prediction - 0.5).abs();
33
34 let boundary_uncertainty = 1.0 - (boundary_distance * 2.0);
36
37 boundary_uncertainty.max(0.0).min(1.0)
39 }
40
41 pub fn calibrate(&mut self, _predictions: &[f32], _outcomes: &[bool]) {
43 }
46
47 pub fn calibration_quantile(&self) -> f32 {
49 self.calibration_quantile
50 }
51}
52
53impl Default for UncertaintyEstimator {
54 fn default() -> Self {
55 Self::new()
56 }
57}
58
59#[cfg(test)]
60mod tests {
61 use super::*;
62
63 #[test]
64 fn test_uncertainty_estimation() {
65 let estimator = UncertaintyEstimator::new();
66
67 let features = vec![0.5; 10];
69 let high_conf = estimator.estimate(&features, 0.95);
70 assert!(high_conf < 0.5);
71
72 let low_conf = estimator.estimate(&features, 0.52);
74 assert!(low_conf > 0.5);
75 }
76
77 #[test]
78 fn test_boundary_uncertainty() {
79 let estimator = UncertaintyEstimator::new();
80 let features = vec![0.5; 10];
81
82 let boundary = estimator.estimate(&features, 0.5);
84 assert!((boundary - 1.0).abs() < 0.01);
85 }
86}