Fractional differentiation utilities (AFML chapter 5 style).
(diff_amt: f64, size: usize)
| 1 | //! Fractional differentiation utilities (AFML chapter 5 style). |
| 2 | |
| 3 | pub fn get_weights(diff_amt: f64, size: usize) -> Vec<f64> { |
| 4 | if size == 0 { |
| 5 | return Vec::new(); |
| 6 | } |
| 7 | let mut weights = Vec::with_capacity(size); |
| 8 | weights.push(1.0); |
| 9 | for k in 1..size { |
| 10 | let w = -weights[k - 1] * (diff_amt - k as f64 + 1.0) / k as f64; |
| 11 | weights.push(w); |
| 12 | } |
| 13 | weights.reverse(); |
| 14 | weights |
| 15 | } |
| 16 | |
| 17 | pub fn get_weights_ffd(diff_amt: f64, thresh: f64, lim: usize) -> Vec<f64> { |
| 18 | if lim == 0 { |
no outgoing calls