Skip to main content

rust_robotics_control/experiments/path_tracking_accuracy/
percentile_bucket.rs

1use super::{TrackingAggregationVariant, VariantDescriptor};
2
3#[derive(Debug, Clone)]
4pub struct PercentileBucketTrackingAggregation {
5    percentiles: Vec<f64>,
6}
7
8impl PercentileBucketTrackingAggregation {
9    pub fn new(percentiles: Vec<f64>) -> Self {
10        Self { percentiles }
11    }
12}
13
14impl TrackingAggregationVariant for PercentileBucketTrackingAggregation {
15    fn descriptor(&self) -> VariantDescriptor {
16        VariantDescriptor {
17            id: "percentile-bucket",
18            design_style: "functional-percentile",
19            source_path: concat!(
20                env!("CARGO_MANIFEST_DIR"),
21                "/src/experiments/path_tracking_accuracy/percentile_bucket.rs"
22            ),
23            knob_count: 1,
24            reports_dispersion: true,
25        }
26    }
27
28    fn selected_slots(&self, total_scenarios: usize) -> Vec<usize> {
29        if total_scenarios == 0 {
30            return Vec::new();
31        }
32
33        let mut slots = self
34            .percentiles
35            .iter()
36            .map(|percentile| {
37                let clamped = percentile.clamp(0.0, 1.0);
38                ((total_scenarios - 1) as f64 * clamped).round() as usize
39            })
40            .collect::<Vec<_>>();
41        slots.sort_unstable();
42        slots.dedup();
43        slots
44    }
45}