1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use crateNoiseWindowView;
use crate;
/// Trait used for implementing algorithms.
///
/// # Example
///
/// ``` rust
/// # use adaptif::Error;
/// use adaptif::Algorithm;
/// use adaptif::types::NoiseWindowView;
/// use adaptif::types:: WindowSize;
///
/// // Create a struct to hold any required parameters or state
/// pub struct MyAlgorithm {
/// // Some parameter
/// pub alpha: f64,
/// // The algorithm's window size
/// pub window_size: WindowSize,
/// }
/// // Implement the Algorithm trait so the algorithm can be used with FilterBase
/// impl Algorithm<f64> for MyAlgorithm {
/// // This function is called every iteration during adaptation to update the weights
/// fn update_step(&mut self, weights: &mut [f64], error: f64, noise_window: NoiseWindowView<f64>) {
/// for (w, x) in weights.iter_mut().zip(noise_window.iter()) {
/// *w += self.alpha * error * x;
/// }
/// }
///
/// // Certain algorithms need to know the filter's window size to initialize buffers, etc.
/// // To make sure `FilterBase` has the same window size as the algorithm object, we
/// // have to define this function so that it can be access when constructing `FilterBase`.
/// fn window_size(&self) -> WindowSize {
/// self.window_size
/// }
/// }
///
/// # Ok::<(), Error>(())
/// ```