Function
get_weights_ffd
(diff_amt: f64, thresh: f64, lim: usize)
Source from the content-addressed store, hash-verified
| 15 | } |
| 16 | |
| 17 | pub fn get_weights_ffd(diff_amt: f64, thresh: f64, lim: usize) -> Vec<f64> { |
| 18 | if lim == 0 { |
| 19 | return Vec::new(); |
| 20 | } |
| 21 | let mut weights = vec![1.0]; |
| 22 | let mut k = 1usize; |
| 23 | let mut ctr = 0usize; |
| 24 | loop { |
| 25 | let next = -weights[weights.len() - 1] * (diff_amt - k as f64 + 1.0) / k as f64; |
| 26 | if next.abs() < thresh { |
| 27 | break; |
| 28 | } |
| 29 | weights.push(next); |
| 30 | k += 1; |
| 31 | ctr += 1; |
| 32 | if ctr == lim - 1 { |
| 33 | break; |
| 34 | } |
| 35 | } |
| 36 | weights.reverse(); |
| 37 | weights |
| 38 | } |
| 39 | |
| 40 | pub fn frac_diff(series: &[f64], diff_amt: f64, thresh: f64) -> Vec<f64> { |
| 41 | let n = series.len(); |