fraug/augmenters/
scaling.rs

1use super::base::Augmenter;
2use tracing::{info_span};
3/// Augmenter that scales a time series with a random scalar within the range specified 
4/// by `min_factor` (inclusive) and `max_factor` (inclusive)
5pub struct Scaling {
6    pub name: String,
7    pub min_factor: f64,
8    pub max_factor: f64,
9    p: f64,
10}
11
12impl Scaling {
13    pub fn new(min: f64, max: f64) -> Self {
14        Scaling {
15            name: "Scaling".to_string(),
16            min_factor: min,
17            max_factor: max,
18            p: 1.0,
19        }
20    }
21}
22
23impl Augmenter for Scaling {
24    fn augment_one(&self, x: &[f64]) -> Vec<f64> {
25        let span = info_span!("", step = "augment_one");
26        let _enter = span.enter();
27
28        let scalar = rand::random_range(self.min_factor..=self.max_factor);
29        x.iter().map(|val| *val * scalar).collect()
30    }
31
32    fn get_probability(&self) -> f64 {
33        self.p
34    }
35
36    fn set_probability(&mut self, probability: f64) {
37        self.p = probability;
38    }
39
40    fn get_name(&self) ->String {
41        self.name.clone()
42    }
43}