| 38 | } |
| 39 | |
| 40 | pub fn frac_diff(series: &[f64], diff_amt: f64, thresh: f64) -> Vec<f64> { |
| 41 | let n = series.len(); |
| 42 | if n == 0 { |
| 43 | return Vec::new(); |
| 44 | } |
| 45 | let weights = get_weights(diff_amt, n); |
| 46 | |
| 47 | let mut cum = Vec::with_capacity(n); |
| 48 | let mut s = 0.0; |
| 49 | for w in &weights { |
| 50 | s += w.abs(); |
| 51 | cum.push(s); |
| 52 | } |
| 53 | let total = *cum.last().unwrap_or(&1.0); |
| 54 | if total != 0.0 { |
| 55 | for v in &mut cum { |
| 56 | *v /= total; |
| 57 | } |
| 58 | } |
| 59 | let skip = cum.iter().filter(|v| **v > thresh).count(); |
| 60 | |
| 61 | let mut out = vec![f64::NAN; n]; |
| 62 | for iloc in skip..n { |
| 63 | let w_start = n - (iloc + 1); |
| 64 | let mut acc = 0.0; |
| 65 | for j in 0..=iloc { |
| 66 | acc += weights[w_start + j] * series[j]; |
| 67 | } |
| 68 | out[iloc] = acc; |
| 69 | } |
| 70 | out |
| 71 | } |
| 72 | |
| 73 | pub fn frac_diff_ffd(series: &[f64], diff_amt: f64, thresh: f64) -> Vec<f64> { |
| 74 | let n = series.len(); |