1pub fn mean(x: &[f64]) -> f64 {
2 let sum: f64 = x.iter().sum();
3 let n: f64 = x.len() as f64;
4 return sum / n;
5}
6
7pub fn standard_deviation(x: &[f64]) -> f64 {
8 let mean_x: f64 = mean(x);
9 let sum_x_minus_mean: f64 = x.iter().map(|a| (a - mean_x).powi(2)).sum();
10 return (sum_x_minus_mean / (x.len() as f64)).sqrt();
11}
12
13pub fn cumsum(x: &[f64]) -> Vec<f64> {
14 let result: Vec<f64> = x.iter()
15 .scan(0f64, |acc, &a| {
16 *acc = *acc + a;
17 Some(*acc)
18 }).collect();
19 return result;
20}
21
22pub fn minmax(x: &[f64]) -> (f64, f64) {
23 return x.iter().fold((x[0], x[0]), |acc, &x| (acc.0.min(x), acc.1.max(x)));
24}
25
26pub fn rscalc(x: &[f64]) -> f64 {
28 let x_mean: f64 = mean(x);
29 let x_minus_mean: Vec<f64> = x.iter()
30 .map(|x| x - x_mean)
31 .collect();
32 let y: Vec<f64> = cumsum(&x_minus_mean);
33 let (min_y, max_y) = minmax(&y);
34 let r: f64 = (max_y - min_y).abs();
35 let s: f64 = standard_deviation(&x);
36 let result: f64 = r / s;
37 return result;
38}
39
40pub fn half(n: &Vec<u64>, original_length: u64) -> Vec<u64> {
42 let previous_step: u64 = n[1];
43 let next_step: u64 = previous_step / 2;
44 let length: u64 = original_length / next_step;
45 let range: Vec<u64> = (0..length + 1).collect();
46 let result: Vec<u64> = range.iter().map(|a| a * next_step).collect();
47 return result
48}