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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
//! augurs adapter — on-graph time-series analysis powered by the
//! [`augurs`](https://docs.rs/augurs) toolkit.
//!
//! Unlike the messaging adapters in this crate, augurs is a pure-Rust compute
//! library rather than an external service — there is nothing to connect to and
//! no Docker container to run. The adapter therefore exposes **transform nodes**
//! that maintain a sliding window of an input stream and apply augurs models on
//! the graph thread each cycle:
//!
//! - [`AugursForecastOperators::augurs_forecast`] — buffers a window of an
//! `f64` stream, fits a forecasting model ([`AutoETS`](augurs::ets::AutoETS)
//! or [MSTL](augurs::mstl)) and emits an [`AugursForecast`] (point forecast +
//! optional prediction intervals).
//! - [`AugursOutlierOperators::augurs_outlier`] — buffers a window of a
//! `Vec<f64>` stream (one value per series per tick), runs an outlier detector
//! ([MAD](augurs::outlier::MADDetector) or
//! [DBSCAN](augurs::outlier::DbscanDetector)) and emits an [`AugursOutliers`]
//! (which series are outlying + their latest scores).
//! - [`AugursChangepointOperators::augurs_changepoint`] — Bayesian online
//! changepoint detection over a window of an `f64` stream, emitting the
//! [`AugursChangepoints`] indices within the window.
//! - [`AugursSeasonsOperators::augurs_seasons`] — periodogram seasonality
//! detection over a window of an `f64` stream, emitting the detected
//! [`AugursSeasons`] period lengths.
//! - [`AugursDtwOperators::augurs_dtw`] — dynamic time warping distance matrix
//! over a window of a `Vec<f64>` (multi-series) stream, emitting an
//! [`AugursDistanceMatrix`].
//! - [`AugursClusterOperators::augurs_cluster`] — DBSCAN clustering of the
//! series in a `Vec<f64>` window using their DTW distances, emitting the
//! per-series [`AugursClusters`] labels.
//!
//! Models are fitted inside `cycle()`. This is pure CPU work on the
//! single-threaded graph engine (no locks, no I/O), but refitting is not free —
//! throttle the input with [`sample`](crate::StreamOperators) /
//! [`throttle`](crate::StreamOperators) upstream if you do not need a fresh fit
//! on every tick.
//!
//! # Forecasting
//!
//! ```ignore
//! use wingfoil::adapters::augurs::*;
//! use wingfoil::*;
//!
//! // A noisy upward ramp; forecast 5 steps ahead with 95% intervals.
//! ticker(std::time::Duration::from_secs(1))
//! .count()
//! .map(|n| n as f64 + (n as f64 * 0.3).sin())
//! .augurs_forecast(AugursForecastConfig::new(64, 5).with_level(0.95))
//! .for_each(|f, _| println!("next 5: {:?}", f.point))
//! .run(RunMode::RealTime, RunFor::Forever)
//! .unwrap();
//!
//! // Seasonal data: fit MSTL with a period-24 season instead of plain ETS.
//! # use wingfoil::adapters::augurs::*;
//! # use wingfoil::*;
//! # let hourly: std::rc::Rc<dyn Stream<f64>> = constant(0.0);
//! hourly.augurs_forecast(AugursForecastConfig::new(240, 24).mstl(vec![24]));
//! ```
//!
//! # Outlier detection
//!
//! ```ignore
//! use wingfoil::adapters::augurs::*;
//! use wingfoil::*;
//!
//! // Each tick carries one reading per monitored series.
//! some_stream_of_readings // Rc<dyn Stream<Vec<f64>>>
//! .augurs_outlier(AugursOutlierConfig::mad(32, 0.5))
//! .for_each(|o, _| println!("outlying series: {:?}", o.outlying))
//! .run(RunMode::RealTime, RunFor::Forever)
//! .unwrap();
//! ```
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
use VecDeque;
/// Push `value` onto a sliding-window buffer, evicting the oldest samples until
/// at most `window` remain. Shared by every augurs node's `cycle()` so the
/// ring-buffer maintenance lives in one place.
pub
/// Transpose a window of per-tick multi-series samples (one value per series per
/// tick) into aligned per-series columns of equal length. Short samples are
/// forward-filled with the series' previous value so every column spans the full
/// window. A series that first appears part-way through the window has its
/// leading gap back-filled with its own first observed value — never a
/// fabricated `0.0`, which would read as a large deviation to the outlier / DTW
/// operators for the rest of the window.
///
/// Shared by the multi-series operators ([`augurs_outlier`](AugursOutlierOperators),
/// [`augurs_dtw`](AugursDtwOperators), [`augurs_cluster`](AugursClusterOperators)).
pub
/// A forecast produced by [`AugursForecastOperators::augurs_forecast`].
///
/// `point` holds the n-ahead point forecasts (length = `horizon`). `lower` /
/// `upper` hold the prediction-interval bounds when a confidence level was
/// requested, and are empty otherwise.
/// The result of [`AugursOutlierOperators::augurs_outlier`] for one cycle.
/// The result of [`AugursChangepointOperators::augurs_changepoint`] for one
/// cycle — the indices, within the current window, at which a changepoint was
/// detected.
/// The result of [`AugursSeasonsOperators::augurs_seasons`] for one cycle — the
/// seasonal period lengths (in samples) detected in the current window.
/// A row-major square distance matrix produced by
/// [`AugursDtwOperators::augurs_dtw`]. `rows[i][j]` is the DTW distance between
/// series `i` and series `j` over the current window.
/// The result of [`AugursClusterOperators::augurs_cluster`] for one cycle — a
/// cluster label per series. A label of `-1` marks a noise point (unclustered);
/// non-negative labels group series into clusters.