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
use crateIter;
/// This trait provides an common interface for algorithms that can calculate a simple moving
/// average.
///
/// In this crate, a simple moving average is defined as `sum(window(samples, N)) / length(window(samples, N))`.
/// Here `samples` is a possibly infinite series of samples. The `window` function extracts the last
/// `N` of those samples.
///
/// *Implementation detail:* For the purposes of this library, there is no point in keeping samples
/// outside the sample window around, so they are discarded when newer samples push them out of the
/// window. This allows the implementations to have constant memory requirements and be stack
/// allocated.
///
/// Terminology:
/// - Sample: A data point, a value.
/// - Sample window: The subset of all samples used for average calculations.