Skip to main content

rust_robotics_mapping/experiments/point_cloud_sampling_quality/
mod.rs

1mod first_scenario;
2mod full_bucket;
3mod percentile_bucket;
4mod sampled_bucket;
5mod variance_triggered;
6
7use std::collections::HashMap;
8use std::f64::consts::PI;
9use std::time::Instant;
10
11use nalgebra::DVector;
12use rand::prelude::IndexedRandom;
13use rand::rngs::StdRng;
14use rand::seq::SliceRandom;
15use rand::{Rng, SeedableRng};
16use rust_robotics_core::{
17    annotate_against_reference as annotate_reference_reports, average_coverage_ratio,
18    read_source_metrics, ExperimentObservation, ExperimentSamplingPlan, ExperimentVariantReport,
19    ExtensibilityMetrics, VariantDescriptor,
20};
21
22use crate::point_cloud_sampling::{
23    farthest_point_sampling, poisson_disk_sampling, voxel_point_sampling,
24};
25
26pub use first_scenario::FirstScenarioPointSamplingAggregation;
27pub use full_bucket::FullBucketPointSamplingAggregation;
28pub use percentile_bucket::PercentileBucketPointSamplingAggregation;
29pub use sampled_bucket::SampledBucketPointSamplingAggregation;
30pub use variance_triggered::VarianceTriggeredPointSamplingAggregation;
31
32pub type PointSamplingSamplingPlan = ExperimentSamplingPlan;
33
34pub trait PointSamplingAggregationVariant {
35    fn descriptor(&self) -> VariantDescriptor;
36    fn selected_slots(&self, total_scenarios: usize) -> Vec<usize>;
37
38    fn sampling_plan(&self, total_scenarios: usize) -> PointSamplingSamplingPlan {
39        PointSamplingSamplingPlan::static_slots(self.selected_slots(total_scenarios))
40    }
41}
42
43#[derive(Debug, Clone, Copy)]
44enum CloudFamilyKind {
45    LayeredPlane,
46    TwinClusterBridge,
47    RingWithOutliers,
48}
49
50#[derive(Debug, Clone, Copy)]
51enum CloudCorruptionMode {
52    None,
53    SlabDrop {
54        axis: usize,
55        center: f64,
56        half_width: f64,
57        drop_probability: f64,
58    },
59    DensityShift {
60        axis: usize,
61        center: f64,
62        half_width: f64,
63        dense_duplicate_probability: f64,
64        sparse_keep_probability: f64,
65    },
66    SectorDrop {
67        start_angle: f64,
68        end_angle: f64,
69        drop_probability: f64,
70    },
71}
72
73#[derive(Debug, Clone)]
74pub struct PointSamplingExperimentCase {
75    pub family_name: &'static str,
76    pub buckets: Vec<u32>,
77    base_point_count: usize,
78    cloud_kind: CloudFamilyKind,
79    base_jitter_scale: f64,
80    base_outlier_fraction: f64,
81    extra_noise_scales: [f64; 3],
82    corruption_mode: CloudCorruptionMode,
83    burst_slots: &'static [usize],
84    burst_noise_scales: [f64; 3],
85    burst_outlier_multiplier: f64,
86}
87
88#[derive(Debug, Clone)]
89pub struct PointSamplingObservation {
90    pub family_name: &'static str,
91    pub bucket: u32,
92    pub total_scenarios: usize,
93    pub initial_slots: Vec<usize>,
94    pub selected_slots: Vec<usize>,
95    pub escalated: bool,
96    pub voxel_bucket_median_score: f64,
97    pub farthest_bucket_median_score: f64,
98    pub poisson_bucket_median_score: f64,
99    pub voxel_min_score: f64,
100    pub voxel_max_score: f64,
101    pub farthest_min_score: f64,
102    pub farthest_max_score: f64,
103    pub poisson_min_score: f64,
104    pub poisson_max_score: f64,
105    pub voxel_wins: usize,
106    pub farthest_wins: usize,
107    pub poisson_wins: usize,
108}
109
110impl PointSamplingObservation {
111    pub fn winner(&self) -> &'static str {
112        let candidates = [
113            ("Voxel", self.voxel_bucket_median_score),
114            ("FarthestPoint", self.farthest_bucket_median_score),
115            ("PoissonDisk", self.poisson_bucket_median_score),
116        ];
117        candidates
118            .into_iter()
119            .min_by(|lhs, rhs| lhs.1.total_cmp(&rhs.1))
120            .map(|entry| entry.0)
121            .unwrap_or("Voxel")
122    }
123
124    pub fn runner_up_over_best(&self) -> f64 {
125        let mut scores = [
126            self.voxel_bucket_median_score,
127            self.farthest_bucket_median_score,
128            self.poisson_bucket_median_score,
129        ];
130        scores.sort_by(f64::total_cmp);
131        scores[1] / scores[0].max(1e-9)
132    }
133
134    pub fn coverage_ratio(&self) -> f64 {
135        self.selected_slots.len() as f64 / self.total_scenarios as f64
136    }
137}
138
139impl ExperimentObservation for PointSamplingObservation {
140    type Key = (&'static str, u32);
141
142    fn comparison_key(&self) -> Self::Key {
143        (self.family_name, self.bucket)
144    }
145
146    fn winner_label(&self) -> &'static str {
147        PointSamplingObservation::winner(self)
148    }
149
150    fn ratio_value(&self) -> f64 {
151        PointSamplingObservation::runner_up_over_best(self)
152    }
153
154    fn coverage_ratio(&self) -> f64 {
155        PointSamplingObservation::coverage_ratio(self)
156    }
157}
158
159pub type PointSamplingVariantReport = ExperimentVariantReport<PointSamplingObservation>;
160
161#[derive(Debug, Clone, Copy)]
162pub struct PointSamplingEvaluationConfig {
163    pub scenarios_per_bucket: usize,
164}
165
166impl Default for PointSamplingEvaluationConfig {
167    fn default() -> Self {
168        Self {
169            scenarios_per_bucket: 10,
170        }
171    }
172}
173
174pub fn mapping_point_cloud_sampling_process_problem() -> Vec<PointSamplingExperimentCase> {
175    vec![
176        PointSamplingExperimentCase {
177            family_name: "layered-plane",
178            buckets: vec![48, 96, 144],
179            base_point_count: 288,
180            cloud_kind: CloudFamilyKind::LayeredPlane,
181            base_jitter_scale: 0.05,
182            base_outlier_fraction: 0.02,
183            extra_noise_scales: [0.0, 0.0, 0.0],
184            corruption_mode: CloudCorruptionMode::None,
185            burst_slots: &[],
186            burst_noise_scales: [0.0, 0.0, 0.0],
187            burst_outlier_multiplier: 1.0,
188        },
189        PointSamplingExperimentCase {
190            family_name: "twin-cluster-bridge",
191            buckets: vec![60, 120, 180],
192            base_point_count: 360,
193            cloud_kind: CloudFamilyKind::TwinClusterBridge,
194            base_jitter_scale: 0.07,
195            base_outlier_fraction: 0.04,
196            extra_noise_scales: [0.0, 0.0, 0.0],
197            corruption_mode: CloudCorruptionMode::None,
198            burst_slots: &[],
199            burst_noise_scales: [0.0, 0.0, 0.0],
200            burst_outlier_multiplier: 1.0,
201        },
202        PointSamplingExperimentCase {
203            family_name: "ring-with-outliers",
204            buckets: vec![72, 132, 192],
205            base_point_count: 420,
206            cloud_kind: CloudFamilyKind::RingWithOutliers,
207            base_jitter_scale: 0.09,
208            base_outlier_fraction: 0.07,
209            extra_noise_scales: [0.0, 0.0, 0.0],
210            corruption_mode: CloudCorruptionMode::None,
211            burst_slots: &[],
212            burst_noise_scales: [0.0, 0.0, 0.0],
213            burst_outlier_multiplier: 1.0,
214        },
215    ]
216}
217
218pub fn mapping_occlusion_corruption_process_problem() -> Vec<PointSamplingExperimentCase> {
219    vec![
220        PointSamplingExperimentCase {
221            family_name: "slab-occluded-plane",
222            buckets: vec![48, 96, 144],
223            base_point_count: 288,
224            cloud_kind: CloudFamilyKind::LayeredPlane,
225            base_jitter_scale: 0.05,
226            base_outlier_fraction: 0.02,
227            extra_noise_scales: [0.2, 1.5, 0.4],
228            corruption_mode: CloudCorruptionMode::SlabDrop {
229                axis: 0,
230                center: 0.0,
231                half_width: 2.4,
232                drop_probability: 0.82,
233            },
234            burst_slots: &[],
235            burst_noise_scales: [0.0, 0.0, 0.0],
236            burst_outlier_multiplier: 1.0,
237        },
238        PointSamplingExperimentCase {
239            family_name: "bridge-shadow-clusters",
240            buckets: vec![60, 120, 180],
241            base_point_count: 360,
242            cloud_kind: CloudFamilyKind::TwinClusterBridge,
243            base_jitter_scale: 0.07,
244            base_outlier_fraction: 0.04,
245            extra_noise_scales: [0.4, 1.0, 1.8],
246            corruption_mode: CloudCorruptionMode::SlabDrop {
247                axis: 1,
248                center: 0.0,
249                half_width: 1.8,
250                drop_probability: 0.76,
251            },
252            burst_slots: &[],
253            burst_noise_scales: [0.0, 0.0, 0.0],
254            burst_outlier_multiplier: 1.0,
255        },
256        PointSamplingExperimentCase {
257            family_name: "sector-dropout-ring",
258            buckets: vec![72, 132, 192],
259            base_point_count: 420,
260            cloud_kind: CloudFamilyKind::RingWithOutliers,
261            base_jitter_scale: 0.09,
262            base_outlier_fraction: 0.05,
263            extra_noise_scales: [1.1, 0.6, 0.9],
264            corruption_mode: CloudCorruptionMode::SectorDrop {
265                start_angle: 0.20 * PI,
266                end_angle: 0.62 * PI,
267                drop_probability: 0.88,
268            },
269            burst_slots: &[],
270            burst_noise_scales: [0.0, 0.0, 0.0],
271            burst_outlier_multiplier: 1.0,
272        },
273    ]
274}
275
276pub fn mapping_density_shift_process_problem() -> Vec<PointSamplingExperimentCase> {
277    vec![
278        PointSamplingExperimentCase {
279            family_name: "density-striped-plane",
280            buckets: vec![48, 96, 144],
281            base_point_count: 288,
282            cloud_kind: CloudFamilyKind::LayeredPlane,
283            base_jitter_scale: 0.05,
284            base_outlier_fraction: 0.02,
285            extra_noise_scales: [1.6, 0.3, 0.6],
286            corruption_mode: CloudCorruptionMode::DensityShift {
287                axis: 1,
288                center: 0.0,
289                half_width: 3.2,
290                dense_duplicate_probability: 0.85,
291                sparse_keep_probability: 0.58,
292            },
293            burst_slots: &[],
294            burst_noise_scales: [0.0, 0.0, 0.0],
295            burst_outlier_multiplier: 1.0,
296        },
297        PointSamplingExperimentCase {
298            family_name: "left-heavy-bridge",
299            buckets: vec![60, 120, 180],
300            base_point_count: 360,
301            cloud_kind: CloudFamilyKind::TwinClusterBridge,
302            base_jitter_scale: 0.07,
303            base_outlier_fraction: 0.03,
304            extra_noise_scales: [0.5, 1.4, 0.7],
305            corruption_mode: CloudCorruptionMode::DensityShift {
306                axis: 0,
307                center: -4.5,
308                half_width: 4.0,
309                dense_duplicate_probability: 0.90,
310                sparse_keep_probability: 0.62,
311            },
312            burst_slots: &[],
313            burst_noise_scales: [0.0, 0.0, 0.0],
314            burst_outlier_multiplier: 1.0,
315        },
316        PointSamplingExperimentCase {
317            family_name: "core-heavy-ring",
318            buckets: vec![72, 132, 192],
319            base_point_count: 420,
320            cloud_kind: CloudFamilyKind::RingWithOutliers,
321            base_jitter_scale: 0.09,
322            base_outlier_fraction: 0.04,
323            extra_noise_scales: [0.8, 0.8, 1.2],
324            corruption_mode: CloudCorruptionMode::DensityShift {
325                axis: 0,
326                center: 0.0,
327                half_width: 5.5,
328                dense_duplicate_probability: 0.95,
329                sparse_keep_probability: 0.54,
330            },
331            burst_slots: &[],
332            burst_noise_scales: [0.0, 0.0, 0.0],
333            burst_outlier_multiplier: 1.0,
334        },
335    ]
336}
337
338pub fn mapping_anisotropic_noise_process_problem() -> Vec<PointSamplingExperimentCase> {
339    vec![
340        PointSamplingExperimentCase {
341            family_name: "sheared-plane-noise",
342            buckets: vec![48, 96, 144],
343            base_point_count: 288,
344            cloud_kind: CloudFamilyKind::LayeredPlane,
345            base_jitter_scale: 0.05,
346            base_outlier_fraction: 0.02,
347            extra_noise_scales: [0.3, 2.2, 0.8],
348            corruption_mode: CloudCorruptionMode::None,
349            burst_slots: &[],
350            burst_noise_scales: [0.0, 0.0, 0.0],
351            burst_outlier_multiplier: 1.0,
352        },
353        PointSamplingExperimentCase {
354            family_name: "bridge-z-noise",
355            buckets: vec![60, 120, 180],
356            base_point_count: 360,
357            cloud_kind: CloudFamilyKind::TwinClusterBridge,
358            base_jitter_scale: 0.07,
359            base_outlier_fraction: 0.04,
360            extra_noise_scales: [0.4, 0.7, 2.4],
361            corruption_mode: CloudCorruptionMode::None,
362            burst_slots: &[],
363            burst_noise_scales: [0.0, 0.0, 0.0],
364            burst_outlier_multiplier: 1.0,
365        },
366        PointSamplingExperimentCase {
367            family_name: "radial-ring-noise",
368            buckets: vec![72, 132, 192],
369            base_point_count: 420,
370            cloud_kind: CloudFamilyKind::RingWithOutliers,
371            base_jitter_scale: 0.09,
372            base_outlier_fraction: 0.06,
373            extra_noise_scales: [1.8, 1.8, 0.5],
374            corruption_mode: CloudCorruptionMode::None,
375            burst_slots: &[],
376            burst_noise_scales: [0.0, 0.0, 0.0],
377            burst_outlier_multiplier: 1.0,
378        },
379    ]
380}
381
382pub fn mapping_sparse_outlier_burst_process_problem() -> Vec<PointSamplingExperimentCase> {
383    vec![
384        PointSamplingExperimentCase {
385            family_name: "plane-burst-outliers",
386            buckets: vec![48, 96, 144],
387            base_point_count: 288,
388            cloud_kind: CloudFamilyKind::LayeredPlane,
389            base_jitter_scale: 0.05,
390            base_outlier_fraction: 0.015,
391            extra_noise_scales: [0.2, 0.2, 0.1],
392            corruption_mode: CloudCorruptionMode::None,
393            burst_slots: &[4, 5, 7],
394            burst_noise_scales: [0.6, 1.0, 2.0],
395            burst_outlier_multiplier: 6.0,
396        },
397        PointSamplingExperimentCase {
398            family_name: "bridge-burst-outliers",
399            buckets: vec![60, 120, 180],
400            base_point_count: 360,
401            cloud_kind: CloudFamilyKind::TwinClusterBridge,
402            base_jitter_scale: 0.07,
403            base_outlier_fraction: 0.02,
404            extra_noise_scales: [0.2, 0.3, 0.2],
405            corruption_mode: CloudCorruptionMode::None,
406            burst_slots: &[4, 5, 7],
407            burst_noise_scales: [0.4, 1.8, 1.2],
408            burst_outlier_multiplier: 6.5,
409        },
410        PointSamplingExperimentCase {
411            family_name: "ring-burst-outliers",
412            buckets: vec![72, 132, 192],
413            base_point_count: 420,
414            cloud_kind: CloudFamilyKind::RingWithOutliers,
415            base_jitter_scale: 0.09,
416            base_outlier_fraction: 0.025,
417            extra_noise_scales: [0.2, 0.2, 0.2],
418            corruption_mode: CloudCorruptionMode::None,
419            burst_slots: &[4, 5, 7],
420            burst_noise_scales: [1.6, 0.7, 0.9],
421            burst_outlier_multiplier: 7.0,
422        },
423    ]
424}
425
426pub fn mapping_resolution_ladder_process_problem() -> Vec<PointSamplingExperimentCase> {
427    vec![
428        PointSamplingExperimentCase {
429            family_name: "plane-resolution-ladder",
430            buckets: vec![48, 96, 144],
431            base_point_count: 288,
432            cloud_kind: CloudFamilyKind::LayeredPlane,
433            base_jitter_scale: 0.045,
434            base_outlier_fraction: 0.01,
435            extra_noise_scales: [0.18, 0.25, 0.15],
436            corruption_mode: CloudCorruptionMode::DensityShift {
437                axis: 1,
438                center: 0.0,
439                half_width: 4.2,
440                dense_duplicate_probability: 0.52,
441                sparse_keep_probability: 0.84,
442            },
443            burst_slots: &[1, 2, 3, 5, 7, 8],
444            burst_noise_scales: [0.35, 0.55, 0.95],
445            burst_outlier_multiplier: 2.4,
446        },
447        PointSamplingExperimentCase {
448            family_name: "bridge-resolution-ladder",
449            buckets: vec![60, 120, 180],
450            base_point_count: 360,
451            cloud_kind: CloudFamilyKind::TwinClusterBridge,
452            base_jitter_scale: 0.06,
453            base_outlier_fraction: 0.015,
454            extra_noise_scales: [0.22, 0.35, 0.30],
455            corruption_mode: CloudCorruptionMode::DensityShift {
456                axis: 0,
457                center: 0.0,
458                half_width: 3.8,
459                dense_duplicate_probability: 0.58,
460                sparse_keep_probability: 0.80,
461            },
462            burst_slots: &[1, 2, 3, 5, 7, 8],
463            burst_noise_scales: [0.28, 0.90, 0.75],
464            burst_outlier_multiplier: 2.8,
465        },
466        PointSamplingExperimentCase {
467            family_name: "ring-resolution-ladder",
468            buckets: vec![72, 132, 192],
469            base_point_count: 420,
470            cloud_kind: CloudFamilyKind::RingWithOutliers,
471            base_jitter_scale: 0.08,
472            base_outlier_fraction: 0.02,
473            extra_noise_scales: [0.30, 0.30, 0.20],
474            corruption_mode: CloudCorruptionMode::DensityShift {
475                axis: 0,
476                center: 0.0,
477                half_width: 5.8,
478                dense_duplicate_probability: 0.60,
479                sparse_keep_probability: 0.76,
480            },
481            burst_slots: &[1, 2, 3, 5, 7, 8],
482            burst_noise_scales: [0.95, 0.48, 0.42],
483            burst_outlier_multiplier: 3.0,
484        },
485    ]
486}
487
488pub fn default_point_sampling_variants() -> Vec<Box<dyn PointSamplingAggregationVariant>> {
489    vec![
490        Box::new(FirstScenarioPointSamplingAggregation::new()),
491        Box::new(SampledBucketPointSamplingAggregation::new(vec![0, 4, 9])),
492        Box::new(PercentileBucketPointSamplingAggregation::new(vec![
493            0.0, 0.25, 0.5, 0.75, 1.0,
494        ])),
495        Box::new(VarianceTriggeredPointSamplingAggregation::new(
496            vec![0, 4, 9],
497            0.08,
498        )),
499        Box::new(FullBucketPointSamplingAggregation::new()),
500    ]
501}
502
503pub fn run_variant_suite(
504    variants: &[Box<dyn PointSamplingAggregationVariant>],
505    cases: &[PointSamplingExperimentCase],
506    config: PointSamplingEvaluationConfig,
507) -> Vec<PointSamplingVariantReport> {
508    let slot_cache = build_slot_sample_cache(cases, config.scenarios_per_bucket);
509    let mut reports = Vec::with_capacity(variants.len());
510
511    for variant in variants {
512        let started = Instant::now();
513        let mut observations = Vec::new();
514        for case in cases {
515            for &bucket in &case.buckets {
516                observations.push(measure_bucket_observation(
517                    &**variant,
518                    case,
519                    bucket,
520                    config.scenarios_per_bucket,
521                    &slot_cache,
522                ));
523            }
524        }
525
526        let descriptor = variant.descriptor();
527        let source_metrics = read_source_metrics(std::path::Path::new(descriptor.source_path))
528            .expect("experiment source metrics should be readable");
529        let extensibility_metrics = ExtensibilityMetrics {
530            average_coverage_ratio: average_coverage_ratio(&observations),
531            knob_count: descriptor.knob_count,
532            reports_dispersion: descriptor.reports_dispersion,
533        };
534
535        reports.push(PointSamplingVariantReport {
536            descriptor,
537            evaluation_runtime_ms: started.elapsed().as_secs_f64() * 1000.0,
538            observations,
539            source_metrics,
540            extensibility_metrics,
541            agreement_vs_reference: None,
542            mean_ratio_error_vs_reference: None,
543        });
544    }
545
546    annotate_reference_reports(&mut reports, "full-bucket");
547    reports
548}
549
550fn measure_bucket_observation(
551    variant: &dyn PointSamplingAggregationVariant,
552    case: &PointSamplingExperimentCase,
553    bucket: u32,
554    total_scenarios: usize,
555    slot_cache: &HashMap<(&'static str, u32, usize), SlotPointSamplingSample>,
556) -> PointSamplingObservation {
557    let plan = variant.sampling_plan(total_scenarios);
558    let initial_slots = normalize_slots(total_scenarios, &plan.initial_slots);
559    assert!(
560        !initial_slots.is_empty(),
561        "{} bucket {} should select at least one scenario",
562        case.family_name,
563        bucket
564    );
565
566    let mut slot_samples = measure_slot_samples(&initial_slots, case, bucket, slot_cache);
567    let mut selected_slots = initial_slots.clone();
568    let mut escalated = false;
569    let escalation_slots = normalize_slots(total_scenarios, &plan.escalation_slots);
570
571    if should_escalate(&slot_samples, &plan) {
572        let additional_slots = escalation_slots
573            .into_iter()
574            .filter(|slot| !selected_slots.contains(slot))
575            .collect::<Vec<_>>();
576        if !additional_slots.is_empty() {
577            slot_samples.extend(measure_slot_samples(
578                &additional_slots,
579                case,
580                bucket,
581                slot_cache,
582            ));
583            selected_slots.extend(additional_slots);
584            selected_slots.sort_unstable();
585            escalated = true;
586        }
587    }
588
589    let voxel_scores = slot_samples
590        .iter()
591        .map(|sample| sample.voxel_score)
592        .collect::<Vec<_>>();
593    let farthest_scores = slot_samples
594        .iter()
595        .map(|sample| sample.farthest_score)
596        .collect::<Vec<_>>();
597    let poisson_scores = slot_samples
598        .iter()
599        .map(|sample| sample.poisson_score)
600        .collect::<Vec<_>>();
601
602    PointSamplingObservation {
603        family_name: case.family_name,
604        bucket,
605        total_scenarios,
606        initial_slots,
607        selected_slots,
608        escalated,
609        voxel_bucket_median_score: median_value(&voxel_scores),
610        farthest_bucket_median_score: median_value(&farthest_scores),
611        poisson_bucket_median_score: median_value(&poisson_scores),
612        voxel_min_score: min_value(&voxel_scores),
613        voxel_max_score: max_value(&voxel_scores),
614        farthest_min_score: min_value(&farthest_scores),
615        farthest_max_score: max_value(&farthest_scores),
616        poisson_min_score: min_value(&poisson_scores),
617        poisson_max_score: max_value(&poisson_scores),
618        voxel_wins: slot_samples
619            .iter()
620            .filter(|sample| sample.winner() == "Voxel")
621            .count(),
622        farthest_wins: slot_samples
623            .iter()
624            .filter(|sample| sample.winner() == "FarthestPoint")
625            .count(),
626        poisson_wins: slot_samples
627            .iter()
628            .filter(|sample| sample.winner() == "PoissonDisk")
629            .count(),
630    }
631}
632
633#[derive(Debug, Clone, Copy)]
634struct SlotPointSamplingSample {
635    voxel_score: f64,
636    farthest_score: f64,
637    poisson_score: f64,
638}
639
640impl SlotPointSamplingSample {
641    fn winner(&self) -> &'static str {
642        [
643            ("Voxel", self.voxel_score),
644            ("FarthestPoint", self.farthest_score),
645            ("PoissonDisk", self.poisson_score),
646        ]
647        .into_iter()
648        .min_by(|lhs, rhs| lhs.1.total_cmp(&rhs.1))
649        .map(|entry| entry.0)
650        .unwrap_or("Voxel")
651    }
652
653    fn runner_up_over_best(&self) -> f64 {
654        let mut scores = [self.voxel_score, self.farthest_score, self.poisson_score];
655        scores.sort_by(f64::total_cmp);
656        scores[1] / scores[0].max(1e-9)
657    }
658}
659
660fn measure_slot_samples(
661    slots: &[usize],
662    case: &PointSamplingExperimentCase,
663    bucket: u32,
664    slot_cache: &HashMap<(&'static str, u32, usize), SlotPointSamplingSample>,
665) -> Vec<SlotPointSamplingSample> {
666    slots
667        .iter()
668        .map(|slot| {
669            *slot_cache
670                .get(&(case.family_name, bucket, *slot))
671                .expect("slot sample should exist")
672        })
673        .collect()
674}
675
676fn should_escalate(
677    slot_samples: &[SlotPointSamplingSample],
678    plan: &PointSamplingSamplingPlan,
679) -> bool {
680    if slot_samples.is_empty() || plan.escalation_slots.is_empty() {
681        return false;
682    }
683
684    let vote_split = {
685        let first_winner = slot_samples[0].winner();
686        slot_samples
687            .iter()
688            .skip(1)
689            .any(|sample| sample.winner() != first_winner)
690    };
691    let ratio_close = plan
692        .escalate_if_ratio_margin_below
693        .map(|threshold| {
694            let ratios = slot_samples
695                .iter()
696                .map(SlotPointSamplingSample::runner_up_over_best)
697                .collect::<Vec<_>>();
698            (median_value(&ratios) - 1.0).abs() < threshold
699        })
700        .unwrap_or(false);
701
702    (plan.escalate_if_vote_split && vote_split) || ratio_close
703}
704
705fn normalize_slots(total_scenarios: usize, slots: &[usize]) -> Vec<usize> {
706    let mut normalized = slots
707        .iter()
708        .copied()
709        .filter(|slot| *slot < total_scenarios)
710        .collect::<Vec<_>>();
711    normalized.sort_unstable();
712    normalized.dedup();
713    normalized
714}
715
716fn generate_point_cloud(
717    case: &PointSamplingExperimentCase,
718    bucket: u32,
719    slot: usize,
720) -> Vec<DVector<f64>> {
721    let seed = family_seed(case.family_name) ^ ((bucket as u64) << 16) ^ slot as u64;
722    let mut rng = StdRng::seed_from_u64(seed);
723    let burst_active = is_burst_slot(case, slot);
724    let jitter_scale = case.base_jitter_scale
725        * (1.0 + bucket as f64 / 260.0)
726        * (1.0 + slot as f64 / 40.0)
727        * if burst_active {
728            1.10 + bucket as f64 / 900.0
729        } else {
730            1.0
731        };
732    let outlier_count = ((case.base_point_count as f64)
733        * case.base_outlier_fraction
734        * (0.6 + bucket as f64 / 300.0))
735        .round() as usize;
736
737    let mut points = match case.cloud_kind {
738        CloudFamilyKind::LayeredPlane => {
739            generate_layered_plane_points(case.base_point_count, jitter_scale, slot, &mut rng)
740        }
741        CloudFamilyKind::TwinClusterBridge => {
742            generate_twin_cluster_points(case.base_point_count, jitter_scale, slot, &mut rng)
743        }
744        CloudFamilyKind::RingWithOutliers => {
745            generate_ring_points(case.base_point_count, jitter_scale, slot, &mut rng)
746        }
747    };
748
749    apply_extra_noise(&mut points, case, bucket, slot, &mut rng);
750    apply_structured_corruption(&mut points, case, bucket, &mut rng);
751    append_outliers(&mut points, outlier_count, &mut rng);
752    append_burst_outliers(&mut points, case, bucket, slot, outlier_count, &mut rng);
753    points
754}
755
756fn build_slot_sample_cache(
757    cases: &[PointSamplingExperimentCase],
758    total_scenarios: usize,
759) -> HashMap<(&'static str, u32, usize), SlotPointSamplingSample> {
760    let mut cache = HashMap::new();
761    for case in cases {
762        for &bucket in &case.buckets {
763            for slot in 0..total_scenarios {
764                let cloud = generate_point_cloud(case, bucket, slot);
765                let target_count = bucket as usize;
766                let voxel_score = evaluate_voxel_quality(&cloud, target_count);
767                let farthest_score = evaluate_farthest_quality(&cloud, target_count, slot as u64);
768                let poisson_score = evaluate_poisson_quality(&cloud, target_count, slot as u64);
769                assert!(voxel_score.is_finite(), "Voxel score must stay finite");
770                assert!(
771                    farthest_score.is_finite(),
772                    "Farthest-point score must stay finite"
773                );
774                assert!(poisson_score.is_finite(), "Poisson score must stay finite");
775                cache.insert(
776                    (case.family_name, bucket, slot),
777                    SlotPointSamplingSample {
778                        voxel_score,
779                        farthest_score,
780                        poisson_score,
781                    },
782                );
783            }
784        }
785    }
786    cache
787}
788
789fn generate_layered_plane_points(
790    base_point_count: usize,
791    jitter_scale: f64,
792    slot: usize,
793    rng: &mut StdRng,
794) -> Vec<DVector<f64>> {
795    let side = ((base_point_count / 2) as f64).sqrt().round() as usize;
796    let mut points = Vec::with_capacity(side * side * 2);
797    let phase = slot as f64 * 0.17;
798    for layer in 0..2 {
799        for ix in 0..side {
800            for iy in 0..side {
801                let x = -12.0 + 24.0 * ix as f64 / (side.saturating_sub(1).max(1) as f64);
802                let y = -12.0 + 24.0 * iy as f64 / (side.saturating_sub(1).max(1) as f64);
803                let z = layer as f64 * 1.8 + 0.25 * (0.22 * x + phase).sin();
804                points.push(jittered_point([x, y, z], jitter_scale, rng));
805            }
806        }
807    }
808    points
809}
810
811fn generate_twin_cluster_points(
812    base_point_count: usize,
813    jitter_scale: f64,
814    slot: usize,
815    rng: &mut StdRng,
816) -> Vec<DVector<f64>> {
817    let bridge_count = base_point_count / 6;
818    let cluster_count = (base_point_count - bridge_count) / 2;
819    let mut points = Vec::with_capacity(base_point_count);
820    let phase = slot as f64 * 0.11;
821
822    for _ in 0..cluster_count {
823        points.push(jittered_point(
824            [
825                -7.0 + rng.random_range(-2.4..2.4),
826                -2.0 + rng.random_range(-2.6..2.6),
827                1.0 + rng.random_range(-1.5..1.5),
828            ],
829            jitter_scale,
830            rng,
831        ));
832    }
833    for _ in 0..cluster_count {
834        points.push(jittered_point(
835            [
836                7.0 + rng.random_range(-2.2..2.2),
837                2.0 + rng.random_range(-2.3..2.3),
838                -0.8 + rng.random_range(-1.3..1.3),
839            ],
840            jitter_scale,
841            rng,
842        ));
843    }
844    for index in 0..bridge_count {
845        let t = if bridge_count <= 1 {
846            0.0
847        } else {
848            index as f64 / (bridge_count - 1) as f64
849        };
850        let x = -4.5 + 9.0 * t;
851        let y = 1.4 * (2.0 * PI * t + phase).sin();
852        let z = 0.9 * (PI * t + phase * 0.5).cos();
853        points.push(jittered_point([x, y, z], jitter_scale, rng));
854    }
855    points
856}
857
858fn generate_ring_points(
859    base_point_count: usize,
860    jitter_scale: f64,
861    slot: usize,
862    rng: &mut StdRng,
863) -> Vec<DVector<f64>> {
864    let ring_count = base_point_count * 3 / 4;
865    let core_count = base_point_count - ring_count;
866    let mut points = Vec::with_capacity(base_point_count);
867    let phase = slot as f64 * 0.09;
868
869    for index in 0..ring_count {
870        let t = index as f64 / ring_count.max(1) as f64;
871        let theta = 2.0 * PI * t;
872        let radius = 8.0 + 1.2 * (5.0 * theta + phase).sin();
873        let x = radius * theta.cos();
874        let y = radius * theta.sin();
875        let z = 1.5 * (theta * 0.5 + phase).cos();
876        points.push(jittered_point([x, y, z], jitter_scale, rng));
877    }
878    for _ in 0..core_count {
879        let theta = rng.random_range(0.0..2.0 * PI);
880        let radius = rng.random_range(0.0..3.0);
881        let x = radius * theta.cos();
882        let y = radius * theta.sin();
883        let z = rng.random_range(-1.5..1.5);
884        points.push(jittered_point([x, y, z], jitter_scale, rng));
885    }
886    points
887}
888
889fn append_outliers(points: &mut Vec<DVector<f64>>, outlier_count: usize, rng: &mut StdRng) {
890    for _ in 0..outlier_count {
891        points.push(DVector::from_vec(vec![
892            rng.random_range(-18.0..18.0),
893            rng.random_range(-18.0..18.0),
894            rng.random_range(-6.0..6.0),
895        ]));
896    }
897}
898
899fn apply_extra_noise(
900    points: &mut [DVector<f64>],
901    case: &PointSamplingExperimentCase,
902    bucket: u32,
903    slot: usize,
904    rng: &mut StdRng,
905) {
906    let noise_scales = effective_noise_scales(case, slot);
907    if noise_scales == [0.0, 0.0, 0.0] {
908        return;
909    }
910
911    let severity = 0.35 + bucket as f64 / 220.0;
912    for point in points {
913        for dim in 0..3 {
914            let amplitude = case.base_jitter_scale * noise_scales[dim] * severity;
915            if amplitude > 0.0 {
916                point[dim] += rng.random_range(-amplitude..amplitude);
917            }
918        }
919    }
920}
921
922fn effective_noise_scales(case: &PointSamplingExperimentCase, slot: usize) -> [f64; 3] {
923    if !is_burst_slot(case, slot) {
924        return case.extra_noise_scales;
925    }
926
927    [
928        case.extra_noise_scales[0] + case.burst_noise_scales[0],
929        case.extra_noise_scales[1] + case.burst_noise_scales[1],
930        case.extra_noise_scales[2] + case.burst_noise_scales[2],
931    ]
932}
933
934fn is_burst_slot(case: &PointSamplingExperimentCase, slot: usize) -> bool {
935    case.burst_slots.contains(&slot)
936}
937
938fn append_burst_outliers(
939    points: &mut Vec<DVector<f64>>,
940    case: &PointSamplingExperimentCase,
941    bucket: u32,
942    slot: usize,
943    base_outlier_count: usize,
944    rng: &mut StdRng,
945) {
946    if !is_burst_slot(case, slot) || case.burst_outlier_multiplier <= 1.0 {
947        return;
948    }
949
950    let extra_count = ((base_outlier_count as f64) * (case.burst_outlier_multiplier - 1.0))
951        .round()
952        .max(6.0) as usize;
953    let severity = 0.9 + bucket as f64 / 180.0;
954    let centers = burst_cluster_centers(case.cloud_kind);
955    for index in 0..extra_count {
956        let center = centers[index % centers.len()];
957        points.push(DVector::from_vec(vec![
958            center[0] + rng.random_range(-1.4 * severity..1.4 * severity),
959            center[1] + rng.random_range(-1.2 * severity..1.2 * severity),
960            center[2] + rng.random_range(-severity..severity),
961        ]));
962    }
963}
964
965fn burst_cluster_centers(cloud_kind: CloudFamilyKind) -> [[f64; 3]; 3] {
966    match cloud_kind {
967        CloudFamilyKind::LayeredPlane => {
968            [[16.0, -13.0, 4.5], [-15.0, 14.0, -3.8], [13.5, 15.5, 3.2]]
969        }
970        CloudFamilyKind::TwinClusterBridge => {
971            [[0.0, 13.5, 7.0], [14.0, -13.5, -6.0], [-13.0, 12.5, 6.2]]
972        }
973        CloudFamilyKind::RingWithOutliers => {
974            [[0.0, 0.0, 12.5], [15.5, 0.0, -10.5], [-15.5, 1.5, 10.5]]
975        }
976    }
977}
978
979fn apply_structured_corruption(
980    points: &mut Vec<DVector<f64>>,
981    case: &PointSamplingExperimentCase,
982    bucket: u32,
983    rng: &mut StdRng,
984) {
985    let severity_scale = (0.75 + bucket as f64 / 260.0).clamp(0.0, 1.0);
986    match case.corruption_mode {
987        CloudCorruptionMode::None => {}
988        CloudCorruptionMode::SlabDrop {
989            axis,
990            center,
991            half_width,
992            drop_probability,
993        } => {
994            points.retain(|point| {
995                let in_slab = (point[axis] - center).abs() <= half_width;
996                !(in_slab && rng.random_bool((drop_probability * severity_scale).clamp(0.0, 0.98)))
997            });
998        }
999        CloudCorruptionMode::DensityShift {
1000            axis,
1001            center,
1002            half_width,
1003            dense_duplicate_probability,
1004            sparse_keep_probability,
1005        } => {
1006            let target_len = points.len();
1007            let mut shifted = Vec::with_capacity(target_len * 2);
1008            for point in points.iter() {
1009                let favored = (point[axis] - center).abs() <= half_width;
1010                if favored {
1011                    shifted.push(point.clone());
1012                    if rng.random_bool(
1013                        (dense_duplicate_probability * severity_scale).clamp(0.0, 0.98),
1014                    ) {
1015                        let mut duplicate = point.clone();
1016                        let amplitude = case.base_jitter_scale * (0.35 + bucket as f64 / 480.0);
1017                        for dim in 0..duplicate.len() {
1018                            let axis_scale = if dim == axis { 1.0 } else { 0.35 };
1019                            duplicate[dim] +=
1020                                rng.random_range(-amplitude * axis_scale..amplitude * axis_scale);
1021                        }
1022                        shifted.push(duplicate);
1023                    }
1024                } else if rng.random_bool(
1025                    (sparse_keep_probability + 0.15 * (1.0 - severity_scale)).clamp(0.0, 1.0),
1026                ) {
1027                    shifted.push(point.clone());
1028                }
1029            }
1030            if shifted.is_empty() {
1031                shifted.extend(points.iter().cloned());
1032            }
1033            while shifted.len() < target_len {
1034                let source = shifted
1035                    .choose(rng)
1036                    .cloned()
1037                    .or_else(|| points.choose(rng).cloned())
1038                    .expect("density shift should have a source point");
1039                shifted.push(source);
1040            }
1041            if shifted.len() > target_len {
1042                shifted.shuffle(rng);
1043                shifted.truncate(target_len);
1044            }
1045            *points = shifted;
1046        }
1047        CloudCorruptionMode::SectorDrop {
1048            start_angle,
1049            end_angle,
1050            drop_probability,
1051        } => {
1052            points.retain(|point| {
1053                let theta = point[1].atan2(point[0]);
1054                let normalized = if theta < 0.0 { theta + 2.0 * PI } else { theta };
1055                let in_sector = normalized >= start_angle && normalized <= end_angle;
1056                !(in_sector
1057                    && rng.random_bool((drop_probability * severity_scale).clamp(0.0, 0.98)))
1058            });
1059        }
1060    }
1061}
1062
1063fn jittered_point(base: [f64; 3], jitter_scale: f64, rng: &mut StdRng) -> DVector<f64> {
1064    DVector::from_vec(vec![
1065        base[0] + rng.random_range(-jitter_scale..jitter_scale),
1066        base[1] + rng.random_range(-jitter_scale..jitter_scale),
1067        base[2] + rng.random_range(-0.8 * jitter_scale..0.8 * jitter_scale),
1068    ])
1069}
1070
1071fn evaluate_voxel_quality(points: &[DVector<f64>], target_count: usize) -> f64 {
1072    let target_count = target_count.clamp(8, points.len());
1073    let spacing = characteristic_spacing(points, target_count);
1074    let mut best_score = f64::INFINITY;
1075    for factor in [0.35, 0.55, 0.85, 1.30, 2.0] {
1076        let sample = voxel_point_sampling(points, (spacing * factor).max(1e-4));
1077        let quality = score_sample_quality(points, &sample, target_count);
1078        best_score = best_score.min(quality);
1079    }
1080    best_score
1081}
1082
1083fn evaluate_farthest_quality(points: &[DVector<f64>], target_count: usize, slot_seed: u64) -> f64 {
1084    let target_count = target_count.clamp(8, points.len());
1085    let sample = farthest_point_sampling(points, target_count, family_seed("fps") ^ slot_seed);
1086    score_sample_quality(points, &sample, target_count)
1087}
1088
1089fn evaluate_poisson_quality(points: &[DVector<f64>], target_count: usize, slot_seed: u64) -> f64 {
1090    let target_count = target_count.clamp(8, points.len());
1091    let spacing = characteristic_spacing(points, target_count);
1092    let max_iter = points.len() * 40;
1093    let mut best_score = f64::INFINITY;
1094    for factor in [0.10, 0.20, 0.35, 0.60, 1.0, 1.45] {
1095        let sample = poisson_disk_sampling(
1096            points,
1097            target_count,
1098            (spacing * factor).max(1e-6),
1099            family_seed("poisson") ^ slot_seed,
1100            max_iter,
1101        );
1102        let quality = score_sample_quality(points, &sample, target_count);
1103        best_score = best_score.min(quality);
1104    }
1105    best_score
1106}
1107
1108fn score_sample_quality(
1109    original: &[DVector<f64>],
1110    sample: &[DVector<f64>],
1111    target_count: usize,
1112) -> f64 {
1113    if sample.is_empty() {
1114        return f64::INFINITY;
1115    }
1116
1117    let coverage_error = average_nearest_distance(original, sample);
1118    let support_error = average_nearest_distance(sample, original);
1119    let spacing = mean_sample_spacing(sample);
1120    let count_error_ratio =
1121        (sample.len() as f64 - target_count as f64).abs() / target_count.max(1) as f64;
1122    let centroid_error = centroid_distance(original, sample);
1123
1124    coverage_error
1125        + 0.25 * support_error
1126        + 0.45 * count_error_ratio
1127        + 0.12 / spacing.max(1e-6)
1128        + 0.08 * centroid_error
1129}
1130
1131fn average_nearest_distance(points: &[DVector<f64>], reference: &[DVector<f64>]) -> f64 {
1132    if points.is_empty() || reference.is_empty() {
1133        return f64::INFINITY;
1134    }
1135
1136    points
1137        .iter()
1138        .map(|point| {
1139            reference
1140                .iter()
1141                .map(|candidate| (point - candidate).norm())
1142                .fold(f64::INFINITY, f64::min)
1143        })
1144        .sum::<f64>()
1145        / points.len() as f64
1146}
1147
1148fn mean_sample_spacing(sample: &[DVector<f64>]) -> f64 {
1149    if sample.len() <= 1 {
1150        return 1e-6;
1151    }
1152
1153    sample
1154        .iter()
1155        .enumerate()
1156        .map(|(index, point)| {
1157            sample
1158                .iter()
1159                .enumerate()
1160                .filter(|(candidate_index, _)| *candidate_index != index)
1161                .map(|(_, candidate)| (point - candidate).norm())
1162                .fold(f64::INFINITY, f64::min)
1163        })
1164        .sum::<f64>()
1165        / sample.len() as f64
1166}
1167
1168fn centroid_distance(lhs: &[DVector<f64>], rhs: &[DVector<f64>]) -> f64 {
1169    if lhs.is_empty() || rhs.is_empty() {
1170        return f64::INFINITY;
1171    }
1172
1173    let lhs_centroid = mean_point(lhs);
1174    let rhs_centroid = mean_point(rhs);
1175    (lhs_centroid - rhs_centroid).norm()
1176}
1177
1178fn mean_point(points: &[DVector<f64>]) -> DVector<f64> {
1179    let dim = points.first().map(DVector::len).unwrap_or(0);
1180    let mut mean = DVector::zeros(dim);
1181    for point in points {
1182        mean += point;
1183    }
1184    mean / points.len().max(1) as f64
1185}
1186
1187fn characteristic_spacing(points: &[DVector<f64>], target_count: usize) -> f64 {
1188    let (min_point, max_point) = bounds(points);
1189    let extent = (&max_point - &min_point).norm().max(1e-3);
1190    let dim = points.first().map(DVector::len).unwrap_or(3) as f64;
1191    extent / (target_count.max(1) as f64).powf(1.0 / dim).max(1.0)
1192}
1193
1194fn bounds(points: &[DVector<f64>]) -> (DVector<f64>, DVector<f64>) {
1195    let mut min_point = points
1196        .first()
1197        .cloned()
1198        .unwrap_or_else(|| DVector::from_vec(vec![0.0, 0.0, 0.0]));
1199    let mut max_point = min_point.clone();
1200    for point in points.iter().skip(1) {
1201        for dim in 0..point.len() {
1202            min_point[dim] = min_point[dim].min(point[dim]);
1203            max_point[dim] = max_point[dim].max(point[dim]);
1204        }
1205    }
1206    (min_point, max_point)
1207}
1208
1209fn family_seed(name: &str) -> u64 {
1210    name.bytes().fold(0u64, |hash, byte| {
1211        hash.wrapping_mul(131).wrapping_add(byte as u64)
1212    })
1213}
1214
1215fn median_value(values: &[f64]) -> f64 {
1216    let mut sorted = values.to_vec();
1217    sorted.sort_by(f64::total_cmp);
1218    let mid = sorted.len() / 2;
1219    if sorted.len() % 2 == 0 {
1220        (sorted[mid - 1] + sorted[mid]) / 2.0
1221    } else {
1222        sorted[mid]
1223    }
1224}
1225
1226fn min_value(values: &[f64]) -> f64 {
1227    values.iter().copied().fold(f64::INFINITY, f64::min)
1228}
1229
1230fn max_value(values: &[f64]) -> f64 {
1231    values.iter().copied().fold(f64::NEG_INFINITY, f64::max)
1232}
1233
1234#[cfg(test)]
1235mod tests {
1236    use super::*;
1237
1238    fn reduced_problem() -> Vec<PointSamplingExperimentCase> {
1239        mapping_point_cloud_sampling_process_problem()
1240            .into_iter()
1241            .take(1)
1242            .map(|mut case| {
1243                case.buckets.truncate(1);
1244                case
1245            })
1246            .collect()
1247    }
1248
1249    #[test]
1250    fn point_sampling_problem_runs_and_stays_finite() {
1251        let reports = run_variant_suite(
1252            &default_point_sampling_variants(),
1253            &reduced_problem(),
1254            PointSamplingEvaluationConfig {
1255                scenarios_per_bucket: 2,
1256            },
1257        );
1258        assert_eq!(reports.len(), 5);
1259        assert!(reports
1260            .iter()
1261            .all(|report| report.evaluation_runtime_ms.is_finite()));
1262        assert!(reports.iter().all(|report| {
1263            report.observations.iter().all(|observation| {
1264                observation.voxel_bucket_median_score.is_finite()
1265                    && observation.farthest_bucket_median_score.is_finite()
1266                    && observation.poisson_bucket_median_score.is_finite()
1267            })
1268        }));
1269    }
1270
1271    #[test]
1272    fn point_sampling_problem_reference_covers_all_scenarios() {
1273        let reports = run_variant_suite(
1274            &default_point_sampling_variants(),
1275            &reduced_problem(),
1276            PointSamplingEvaluationConfig {
1277                scenarios_per_bucket: 3,
1278            },
1279        );
1280        let reference = reports
1281            .iter()
1282            .find(|report| report.descriptor.id == "full-bucket")
1283            .expect("full-bucket report should exist");
1284        assert!(reference.observations.iter().all(|observation| {
1285            observation.selected_slots.len() == observation.total_scenarios
1286        }));
1287    }
1288
1289    #[test]
1290    fn occlusion_problem_runs_and_stays_finite() {
1291        let reports = run_variant_suite(
1292            &default_point_sampling_variants(),
1293            &mapping_occlusion_corruption_process_problem()
1294                .into_iter()
1295                .take(1)
1296                .map(|mut case| {
1297                    case.buckets.truncate(1);
1298                    case
1299                })
1300                .collect::<Vec<_>>(),
1301            PointSamplingEvaluationConfig {
1302                scenarios_per_bucket: 2,
1303            },
1304        );
1305        assert_eq!(reports.len(), 5);
1306        assert!(reports.iter().all(|report| {
1307            report.observations.iter().all(|observation| {
1308                observation.voxel_bucket_median_score.is_finite()
1309                    && observation.farthest_bucket_median_score.is_finite()
1310                    && observation.poisson_bucket_median_score.is_finite()
1311            })
1312        }));
1313    }
1314
1315    #[test]
1316    fn density_shift_problem_runs_and_stays_finite() {
1317        let reports = run_variant_suite(
1318            &default_point_sampling_variants(),
1319            &mapping_density_shift_process_problem()
1320                .into_iter()
1321                .take(1)
1322                .map(|mut case| {
1323                    case.buckets.truncate(1);
1324                    case
1325                })
1326                .collect::<Vec<_>>(),
1327            PointSamplingEvaluationConfig {
1328                scenarios_per_bucket: 2,
1329            },
1330        );
1331        assert_eq!(reports.len(), 5);
1332        assert!(reports.iter().all(|report| {
1333            report.observations.iter().all(|observation| {
1334                observation.voxel_bucket_median_score.is_finite()
1335                    && observation.farthest_bucket_median_score.is_finite()
1336                    && observation.poisson_bucket_median_score.is_finite()
1337            })
1338        }));
1339    }
1340
1341    #[test]
1342    fn anisotropic_noise_problem_runs_and_stays_finite() {
1343        let reports = run_variant_suite(
1344            &default_point_sampling_variants(),
1345            &mapping_anisotropic_noise_process_problem()
1346                .into_iter()
1347                .take(1)
1348                .map(|mut case| {
1349                    case.buckets.truncate(1);
1350                    case
1351                })
1352                .collect::<Vec<_>>(),
1353            PointSamplingEvaluationConfig {
1354                scenarios_per_bucket: 2,
1355            },
1356        );
1357        assert_eq!(reports.len(), 5);
1358        assert!(reports.iter().all(|report| {
1359            report.observations.iter().all(|observation| {
1360                observation.voxel_bucket_median_score.is_finite()
1361                    && observation.farthest_bucket_median_score.is_finite()
1362                    && observation.poisson_bucket_median_score.is_finite()
1363            })
1364        }));
1365    }
1366
1367    #[test]
1368    fn sparse_outlier_burst_problem_runs_and_stays_finite() {
1369        let reports = run_variant_suite(
1370            &default_point_sampling_variants(),
1371            &mapping_sparse_outlier_burst_process_problem()
1372                .into_iter()
1373                .take(1)
1374                .map(|mut case| {
1375                    case.buckets.truncate(1);
1376                    case
1377                })
1378                .collect::<Vec<_>>(),
1379            PointSamplingEvaluationConfig {
1380                scenarios_per_bucket: 2,
1381            },
1382        );
1383        assert_eq!(reports.len(), 5);
1384        assert!(reports.iter().all(|report| {
1385            report.observations.iter().all(|observation| {
1386                observation.voxel_bucket_median_score.is_finite()
1387                    && observation.farthest_bucket_median_score.is_finite()
1388                    && observation.poisson_bucket_median_score.is_finite()
1389            })
1390        }));
1391    }
1392
1393    #[test]
1394    fn resolution_ladder_problem_runs_and_stays_finite() {
1395        let reports = run_variant_suite(
1396            &default_point_sampling_variants(),
1397            &mapping_resolution_ladder_process_problem()
1398                .into_iter()
1399                .take(1)
1400                .map(|mut case| {
1401                    case.buckets.truncate(1);
1402                    case
1403                })
1404                .collect::<Vec<_>>(),
1405            PointSamplingEvaluationConfig {
1406                scenarios_per_bucket: 2,
1407            },
1408        );
1409        assert_eq!(reports.len(), 5);
1410        assert!(reports.iter().all(|report| {
1411            report.observations.iter().all(|observation| {
1412                observation.voxel_bucket_median_score.is_finite()
1413                    && observation.farthest_bucket_median_score.is_finite()
1414                    && observation.poisson_bucket_median_score.is_finite()
1415            })
1416        }));
1417    }
1418}