scouter 0.3.3

Rust Scouter logic
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
use crate::core::drift::psi::types::{
    Bin, PsiDriftConfig, PsiDriftMap, PsiDriftProfile, PsiFeatureDriftProfile,
};
use crate::core::error::MonitorError;
use crate::core::utils::CategoricalFeatureHelpers;
use itertools::Itertools;
use ndarray::prelude::*;
use ndarray::Axis;
use num_traits::{Float, FromPrimitive};
use rayon::prelude::*;
use std::collections::HashMap;

#[derive(Default)]
pub struct PsiMonitor {}

impl CategoricalFeatureHelpers for PsiMonitor {}

impl PsiMonitor {
    pub fn new() -> Self {
        PsiMonitor {}
    }
    fn compute_1d_array_mean<F>(&self, array: &ArrayView<F, Ix1>) -> Result<f64, MonitorError>
    where
        F: Float + FromPrimitive,
        F: Into<f64>,
    {
        Ok(array
            .mean()
            .ok_or(MonitorError::ComputeError(
                "Failed to compute mean".to_string(),
            ))?
            .into())
    }

    fn compute_bin_count<F>(
        &self,
        array: &ArrayView<F, Ix1>,
        lower_threshold: &f64,
        upper_threshold: &f64,
    ) -> usize
    where
        F: Float + FromPrimitive,
        F: Into<f64>,
    {
        array
            .iter()
            .filter(|&&value| value.into() > *lower_threshold && value.into() <= *upper_threshold)
            .count()
    }

    fn data_are_binary<F>(&self, column_vector: &ArrayView1<F>) -> bool
    where
        F: Float,
        F: Into<f64>,
    {
        column_vector
            .iter()
            .all(|&value| value.into() == 0.0 || value.into() == 1.0)
    }

    fn compute_deciles<F>(&self, column_vector: &ArrayView1<F>) -> Result<[F; 9], MonitorError>
    where
        F: Float + Default,
        F: Into<f64>,
    {
        // TODO: Explore using ndarray_stats quantiles instead of manual computation
        if column_vector.len() < 10 {
            return Err(MonitorError::ComputeError(
                "At least 10 values needed to compute deciles".to_string(),
            ));
        }

        let sorted_column_vector = column_vector
            .iter()
            .sorted_by(|a, b| a.partial_cmp(b).unwrap()) // Use partial_cmp and unwrap since we assume no NaNs
            .cloned()
            .collect_vec();

        let n = sorted_column_vector.len();
        let mut deciles: [F; 9] = Default::default();

        for i in 1..=9 {
            let index = ((i as f32 * (n as f32 - 1.0)) / 10.0).floor() as usize;
            deciles[i - 1] = sorted_column_vector[index];
        }
        let decile_vec: [F; 9] = deciles.to_vec().try_into().map_err(|_| {
            MonitorError::ComputeError("Failed to convert deciles to array".to_string())
        })?;

        Ok(decile_vec)
    }

    fn create_categorical_bins<F>(
        &self,
        column_vector: &ArrayView<F, Ix1>,
        categorical_feature_map: &HashMap<String, usize>,
    ) -> Vec<Bin>
    where
        F: Float + FromPrimitive + Default + Sync,
        F: Into<f64>,
    {
        categorical_feature_map
            .into_par_iter()
            .map(|(key, numeric_key)| {
                let count = column_vector
                    .iter()
                    .filter(|&&value| value.into() == *numeric_key as f64)
                    .count();

                Bin {
                    id: key.to_string(),
                    lower_limit: None,
                    upper_limit: None,
                    proportion: (count as f64) / (column_vector.len() as f64),
                }
            })
            .collect()
    }

    fn create_binary_bins<F>(
        &self,
        column_vector: &ArrayView<F, Ix1>,
    ) -> Result<Vec<Bin>, MonitorError>
    where
        F: Float + FromPrimitive + Default + Sync,
        F: Into<f64>,
    {
        let column_vector_mean = self.compute_1d_array_mean(column_vector)?;

        Ok(vec![
            Bin {
                id: 0.to_string(),
                lower_limit: None,
                upper_limit: None,
                proportion: 1.0 - column_vector_mean,
            },
            Bin {
                id: 1.to_string(),
                lower_limit: None,
                upper_limit: None,
                proportion: column_vector_mean,
            },
        ])
    }

    fn create_numeric_bins<F>(
        &self,
        column_vector: &ArrayView1<F>,
    ) -> Result<Vec<Bin>, MonitorError>
    where
        F: Float + FromPrimitive + Default + Sync,
        F: Into<f64>,
    {
        let deciles = self.compute_deciles(column_vector).map_err(|err| {
            MonitorError::ComputeError(format!("Failed to compute deciles: {}", err))
        })?;

        let bins: Vec<Bin> = (0..=deciles.len())
            .into_par_iter()
            .map(|decile| {
                let lower = if decile == 0 {
                    F::neg_infinity()
                } else {
                    deciles[decile - 1]
                };
                let upper = if decile == deciles.len() {
                    F::infinity()
                } else {
                    deciles[decile]
                };
                let bin_count = self.compute_bin_count(column_vector, &lower.into(), &upper.into());
                Bin {
                    id: format!("decile_{}", decile + 1),
                    lower_limit: Some(lower.into()),
                    upper_limit: Some(upper.into()),
                    proportion: (bin_count as f64) / (column_vector.len() as f64),
                }
            })
            .collect();
        Ok(bins)
    }

    fn create_bins<F>(
        &self,
        feature_name: &String,
        column_vector: &ArrayView<F, Ix1>,
        drift_config: &PsiDriftConfig,
    ) -> Result<Vec<Bin>, MonitorError>
    where
        F: Float + FromPrimitive + Default + Sync,
        F: Into<f64>,
    {
        if let Some(categorical_feature_map) = drift_config.feature_map.features.get(feature_name) {
            return Ok(self.create_categorical_bins(column_vector, categorical_feature_map));
        }

        if self.data_are_binary(column_vector) {
            self.create_binary_bins(column_vector)
        } else {
            self.create_numeric_bins(column_vector)
        }
    }

    fn create_psi_feature_drift_profile<F>(
        &self,
        feature_name: String,
        column_vector: &ArrayView<F, Ix1>,
        drift_config: &PsiDriftConfig,
    ) -> Result<PsiFeatureDriftProfile, MonitorError>
    where
        F: Float + Sync + FromPrimitive + Default,
        F: Into<f64>,
    {
        let bins = self
            .create_bins(&feature_name, column_vector, drift_config)
            .map_err(|err| MonitorError::CreateError(format!("Failed to create bins: {}", err)))?;

        Ok(PsiFeatureDriftProfile {
            id: feature_name,
            bins,
            timestamp: chrono::Utc::now().naive_utc(),
        })
    }

    pub fn create_2d_drift_profile<F>(
        &self,
        features: &[String],
        array: &ArrayView2<F>,
        drift_config: &PsiDriftConfig,
    ) -> Result<PsiDriftProfile, MonitorError>
    where
        F: Float + Sync + FromPrimitive + Default,
        F: Into<f64>,
    {
        let mut psi_feature_drift_profiles = HashMap::new();

        // Ensure that the number of features matches the number of columns in the array
        assert_eq!(
            features.len(),
            array.shape()[1],
            "Feature count must match column count."
        );

        let profile_vector = array
            .axis_iter(Axis(1))
            .zip(features)
            .collect_vec()
            .into_par_iter()
            .map(|(column_vector, feature_name)| {
                self.create_psi_feature_drift_profile(
                    feature_name.to_string(),
                    &column_vector,
                    drift_config,
                )
            })
            .collect::<Result<Vec<_>, _>>()?;

        profile_vector
            .into_iter()
            .zip(features)
            .for_each(|(profile, feature_name)| {
                psi_feature_drift_profiles.insert(feature_name.clone(), profile);
            });

        Ok(PsiDriftProfile::new(
            psi_feature_drift_profiles,
            drift_config.clone(),
            None,
        ))
    }

    fn compute_psi_proportion_pairs<F>(
        &self,
        column_vector: &ArrayView<F, Ix1>,
        bin: &Bin,
        categorical_feature_map: Option<&HashMap<String, usize>>,
    ) -> Result<(f64, f64), MonitorError>
    where
        F: Float + FromPrimitive,
        F: Into<f64>,
    {
        if let Some(category_map) = categorical_feature_map {
            let cat_int = category_map.get(&bin.id).unwrap();
            let bin_count = column_vector
                .iter()
                .filter(|&&value| value.into() == *cat_int as f64)
                .count();
            return Ok((
                bin.proportion,
                (bin_count as f64) / (column_vector.len() as f64),
            ));
        }

        if self.data_are_binary(column_vector) {
            let column_vector_mean = self.compute_1d_array_mean(column_vector)?;
            if bin.id == 1.to_string() {
                return Ok((bin.proportion, 1.0 - column_vector_mean));
            }
            return Ok((bin.proportion, column_vector_mean));
        }
        let bin_count = self.compute_bin_count(
            column_vector,
            &bin.lower_limit.unwrap(),
            &bin.upper_limit.unwrap(),
        );

        Ok((
            bin.proportion,
            (bin_count as f64) / (column_vector.len() as f64),
        ))
    }

    pub fn compute_psi(&self, proportion_pairs: &[(f64, f64)]) -> f64 {
        let epsilon = 1e-10;
        proportion_pairs
            .iter()
            .map(|(p, q)| {
                let p_adj = p + epsilon;
                let q_adj = q + epsilon;
                (p_adj - q_adj) * (p_adj / q_adj).ln()
            })
            .sum()
    }

    fn compute_feature_drift<F>(
        &self,
        column_vector: &ArrayView<F, Ix1>,
        features: &PsiFeatureDriftProfile,
        category_map: Option<&HashMap<String, usize>>,
    ) -> Result<f64, MonitorError>
    where
        F: Float + Sync + FromPrimitive,
        F: Into<f64>,
    {
        let bins = &features.bins;
        let feature_proportions: Vec<(f64, f64)> = bins
            .into_par_iter()
            .map(|bin| self.compute_psi_proportion_pairs(column_vector, bin, category_map))
            .collect::<Result<Vec<(f64, f64)>, MonitorError>>()?;

        Ok(self.compute_psi(&feature_proportions))
    }

    fn check_features<F>(
        &self,
        features: &[String],
        array: &ArrayView2<F>,
        drift_profile: &PsiDriftProfile,
    ) -> Result<(), MonitorError>
    where
        F: Float + Sync + FromPrimitive,
        F: Into<f64>,
    {
        assert_eq!(
            features.len(),
            array.shape()[1],
            "Feature count must match column count."
        );

        features
            .iter()
            .try_for_each(|feature_name| {
                if !drift_profile.features.contains_key(feature_name) {
                    // Collect all the keys from the drift profile into a comma-separated string
                    let available_keys = drift_profile
                        .features
                        .keys()
                        .cloned()
                        .collect::<Vec<_>>()
                        .join(", ");

                    return Err(MonitorError::ComputeError(
                        format!(
                            "Feature mismatch, feature '{}' not found. Available features in the drift profile: {}",
                            feature_name, available_keys
                        ),
                    ));
                }
                Ok(())
            })
    }

    pub fn compute_drift<F>(
        &self,
        features: &[String],
        array: &ArrayView2<F>,
        drift_profile: &PsiDriftProfile,
    ) -> Result<PsiDriftMap, MonitorError>
    where
        F: Float + Sync + FromPrimitive,
        F: Into<f64>,
    {
        self.check_features(features, array, drift_profile)?;

        let drift_values: Vec<_> = array
            .axis_iter(Axis(1))
            .zip(features)
            .collect_vec()
            .into_par_iter()
            .map(|(column_vector, feature_name)| {
                self.compute_feature_drift(
                    &column_vector,
                    drift_profile.features.get(feature_name).unwrap(),
                    drift_profile.config.feature_map.features.get(feature_name),
                )
            })
            .collect::<Result<Vec<f64>, MonitorError>>()?;

        let mut psi_drift_features = HashMap::new();

        drift_values
            .into_iter()
            .zip(features)
            .for_each(|(drift_value, feature_name)| {
                psi_drift_features.insert(feature_name.clone(), drift_value);
            });

        Ok(PsiDriftMap {
            features: psi_drift_features,
            name: drift_profile.config.name.clone(),
            repository: drift_profile.config.repository.clone(),
            version: drift_profile.config.version.clone(),
        })
    }
}
#[cfg(test)]
mod tests {
    use super::*;
    use ndarray::Array;
    use ndarray_rand::rand_distr::Uniform;
    use ndarray_rand::RandomExt;

    #[test]
    fn test_check_features_all_exist() {
        let psi_monitor = PsiMonitor::default();

        let array = Array::random((1030, 3), Uniform::new(0., 10.));

        let features = vec![
            "feature_1".to_string(),
            "feature_2".to_string(),
            "feature_3".to_string(),
        ];
        let config = PsiDriftConfig::new(
            Some("name".to_string()),
            Some("repo".to_string()),
            None,
            None,
            None,
            None,
            None,
        );

        let profile = psi_monitor
            .create_2d_drift_profile(&features, &array.view(), &config.unwrap())
            .unwrap();
        assert_eq!(profile.features.len(), 3);

        let result = psi_monitor.check_features(&features, &array.view(), &profile);

        // Assert that the result is Ok
        assert_eq!(result, Ok(()));
    }

    #[test]
    fn test_compute_psi_basic() {
        let psi_monitor = PsiMonitor::default();
        let proportions = vec![(0.3, 0.2), (0.4, 0.4), (0.3, 0.4)];

        let result = psi_monitor.compute_psi(&proportions);

        // Manually compute expected PSI for this case
        let expected_psi = (0.3 - 0.2) * (0.3 / 0.2).ln()
            + (0.4 - 0.4) * (0.4 / 0.4).ln()
            + (0.3 - 0.4) * (0.3 / 0.4).ln();

        assert!((result - expected_psi).abs() < 1e-6);
    }

    #[test]
    fn test_compute_bin_count() {
        let psi_monitor = PsiMonitor::default();

        let data = Array1::from_vec(vec![1.0, 2.5, 3.7, 5.0, 6.3, 8.1]);

        let lower_threshold = 2.0;
        let upper_threshold = 6.0;

        let result =
            psi_monitor.compute_bin_count(&data.view(), &lower_threshold, &upper_threshold);

        // Check that it counts the correct number of elements within the bin
        // In this case, 2.5, 3.7, and 5.0 should be counted (3 elements)
        assert_eq!(result, 3);
    }

    #[test]
    fn test_compute_psi_proportion_pairs_binary() {
        let psi_monitor = PsiMonitor::default();

        let binary_vector = Array::from_vec(vec![0.0, 1.0, 0.0, 1.0, 0.0, 1.0]);

        let binary_zero_bin = Bin {
            id: 0.to_string(),
            lower_limit: None,
            upper_limit: None,
            proportion: 0.4,
        };

        let (_, prod_proportion) = psi_monitor
            .compute_psi_proportion_pairs(&binary_vector.view(), &binary_zero_bin, None)
            .unwrap();

        let expected_prod_proportion = 0.5;

        assert!(
            (prod_proportion - expected_prod_proportion).abs() < 1e-9,
            "prod_proportion was expected to be 50%"
        );
    }

    #[test]
    fn test_compute_psi_proportion_pairs_non_binary() {
        let psi_monitor = PsiMonitor::default();

        let vector = Array::from_vec(vec![
            12.0, 11.0, 10.0, 1.0, 10.0, 21.0, 19.0, 12.0, 12.0, 23.0,
        ]);

        let bin = Bin {
            id: 1.to_string(),
            lower_limit: Some(0.0),
            upper_limit: Some(11.0),
            proportion: 0.4,
        };

        let (_, prod_proportion) = psi_monitor
            .compute_psi_proportion_pairs(&vector.view(), &bin, None)
            .unwrap();

        let expected_prod_proportion = 0.4;

        assert!(
            (prod_proportion - expected_prod_proportion).abs() < 1e-9,
            "prod_proportion was expected to be 40%"
        );
    }

    #[test]
    fn test_data_are_binary_with_binary_vector() {
        let psi_monitor = PsiMonitor::default();

        let binary_vector = Array::from_vec(vec![0.0, 1.0, 1.0, 0.0, 0.0]);

        let result = psi_monitor.data_are_binary(&binary_vector.view());

        assert!(result, "Expected the binary vector to return true");
    }

    #[test]
    fn test_data_are_binary_with_non_binary_vector() {
        let psi_monitor = PsiMonitor::default();

        let non_binary_vector = Array::from_vec(vec![0.0, 2.0, 1.0, 3.0, 0.0]);
        let column_view = non_binary_vector.view();

        let result = psi_monitor.data_are_binary(&column_view);

        assert!(!result, "Expected the non-binary vector to return false");
    }

    #[test]
    fn test_compute_deciles_with_unsorted_input() {
        let psi_monitor = PsiMonitor::default();

        let unsorted_vector = Array::from_vec(vec![
            120.0, 1.0, 33.0, 71.0, 15.0, 59.0, 8.0, 62.0, 4.0, 21.0, 10.0, 2.0, 344.0, 437.0,
            53.0, 39.0, 83.0, 6.0, 4.30, 2.0,
        ]);

        let column_view = unsorted_vector.view();

        let result = psi_monitor.compute_deciles(&column_view);

        let expected_deciles: [f64; 9] = [2.0, 4.0, 6.0, 10.0, 21.0, 39.0, 59.0, 71.0, 120.0];

        assert_eq!(
            result.unwrap().as_ref(),
            expected_deciles.as_ref(),
            "Deciles computed incorrectly for unsorted input"
        );
    }

    #[test]
    fn test_create_bins_binary() {
        let psi_monitor = PsiMonitor::default();

        let binary_data = Array::from_vec(vec![0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0]);

        let result = psi_monitor.create_binary_bins(&ArrayView::from(&binary_data)); // Replace `your_struct_instance` with the actual instance

        assert!(result.is_ok());
        let bins = result.unwrap();
        assert_eq!(bins.len(), 2);
    }

    #[test]
    fn test_create_bins_non_binary() {
        let psi_monitor = PsiMonitor::default();

        let non_binary_data = Array::from_vec(vec![
            120.0, 1.0, 33.0, 71.0, 15.0, 59.0, 8.0, 62.0, 4.0, 21.0, 10.0, 2.0, 344.0, 437.0,
            53.0, 39.0, 83.0, 6.0, 4.30, 2.0,
        ]);

        let result = psi_monitor.create_numeric_bins(&ArrayView::from(&non_binary_data));

        assert!(result.is_ok());
        let bins = result.unwrap();
        assert_eq!(bins.len(), 10);
    }

    #[test]
    fn test_create_bins_categorical() {
        let psi_monitor = PsiMonitor::default();

        let categorical_data = Array::from_vec(vec![
            1.0, 1.0, 2.0, 3.0, 2.0, 3.0, 2.0, 1.0, 2.0, 1.0, 1.0, 2.0, 3.0, 3.0, 2.0, 3.0, 1.0,
            1.0,
        ]);

        let mut categorical_feature_map = HashMap::new();
        categorical_feature_map.insert("cat1".to_string(), 1);
        categorical_feature_map.insert("cat2".to_string(), 2);
        categorical_feature_map.insert("cat3".to_string(), 3);

        let bins = psi_monitor.create_categorical_bins(
            &ArrayView::from(&categorical_data),
            &categorical_feature_map,
        );
        assert_eq!(bins.len(), 3);
    }

    #[test]
    fn test_create_2d_drift_profile() {
        // create 2d array
        let array = Array::random((1030, 3), Uniform::new(0., 10.));

        // cast array to f32
        let array = array.mapv(|x| x as f32);

        let features = vec![
            "feature_1".to_string(),
            "feature_2".to_string(),
            "feature_3".to_string(),
        ];

        let monitor = PsiMonitor::default();
        let config = PsiDriftConfig::new(
            Some("name".to_string()),
            Some("repo".to_string()),
            None,
            None,
            None,
            None,
            None,
        );

        let profile = monitor
            .create_2d_drift_profile(&features, &array.view(), &config.unwrap())
            .unwrap();

        assert_eq!(profile.features.len(), 3);
    }

    #[test]
    fn test_compute_drift() {
        // create 2d array
        let array = Array::random((1030, 3), Uniform::new(0., 10.));

        // cast array to f32
        let array = array.mapv(|x| x as f32);

        let features = vec![
            "feature_1".to_string(),
            "feature_2".to_string(),
            "feature_3".to_string(),
        ];

        let monitor = PsiMonitor::default();
        let config = PsiDriftConfig::new(
            Some("name".to_string()),
            Some("repo".to_string()),
            None,
            None,
            None,
            None,
            None,
        );

        let profile = monitor
            .create_2d_drift_profile(&features, &array.view(), &config.unwrap())
            .unwrap();

        let drift_map = monitor
            .compute_drift(&features, &array.view(), &profile)
            .unwrap();

        assert_eq!(drift_map.features.len(), 3);

        // assert that the drift values are all 0.0
        drift_map
            .features
            .values()
            .for_each(|value| assert!(*value == 0.0));

        // create new array that has drifted values
        let mut new_array = Array::random((1030, 3), Uniform::new(0., 10.)).mapv(|x| x as f32);
        new_array.slice_mut(s![.., 0]).mapv_inplace(|x| x + 0.01);

        let new_drift_map = monitor
            .compute_drift(&features, &new_array.view(), &profile)
            .unwrap();

        // assert that the drift values are all greater than 0.0
        new_drift_map
            .features
            .values()
            .for_each(|value| assert!(*value > 0.0));
    }
}