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
//! # ASAP-RS
//!
//! `asap-rs` is a Rust implementation of Automatic Smoothing for Attention Prioritization (ASAP),
//! an algorithm for automatically smoothing time series data to improve visualization.
//!
//! The algorithm is based on the paper ["ASAP: Prioritizing Attention via Time Series Smoothing"](https://arxiv.org/pdf/1703.00983.pdf)
//! by Kexin Rong, Peter Bailis, et al. from Stanford University.
//!
//! ## Features
//!
//! - Automatically determines optimal smoothing window size based on data characteristics
//! - Maintains important patterns and anomalies while reducing noise
//! - Preserves kurtosis to ensure the overall distribution shape is maintained
//! - Optimizes for reduced visual roughness
//! - Special handling for different data patterns (trending, periodic, zigzag)
//!
//! ## Usage
//!
//! ```
//! use asap_rs::smooth;
//!
//! fn main() {
//! // Example time series data
//! let data = vec![1.0, 2.0, 1.5, 3.0, 2.5, 4.0, 3.5, 5.0, 4.5, 6.0];
//!
//! // Apply ASAP smoothing with target resolution of 5 points
//! let smoothed_data = smooth(&data, 5);
//!
//! println!("Original data: {:?}", data);
//! println!("Smoothed data: {:?}", smoothed_data);
//! }
//! ```
//!
//! ## Algorithm Overview
//!
//! ASAP automatically finds the optimal window size for smoothing by:
//!
//! 1. Computing the roughness (standard deviation of differences between consecutive points)
//! 2. Ensuring that kurtosis (measure of "tailedness" of distribution) is preserved
//! 3. Using autocorrelation to identify potential window sizes aligned with patterns in the data
//! 4. Selecting the window size that minimizes roughness while preserving key statistical properties
//!
//! ### Pattern-Specific Processing
//!
//! ASAP-RS includes specialized handling for different types of time series patterns:
//!
//! - **Periodic data**: Windows aligned with the period are prioritized to preserve seasonality
//! - **Trend data**: Appropriate windows are selected to maintain the trend while removing noise
//! - **Zigzag patterns**: Special detection and handling for highly alternating data patterns
//!
//! For zigzag patterns (rapidly alternating high-low values), ASAP uses a relaxed kurtosis
//! constraint and prioritizes a window size of 2, which is mathematically optimal for smoothing
//! such patterns while preserving their mean value.
//!
//! ## Resolution Parameter
//!
//! The `resolution` parameter controls the trade-off between smoothing and detail preservation:
//!
//! - Lower values (e.g., 2-5) apply more aggressive smoothing, highlighting major trends
//! - Higher values (e.g., 50+) preserve more detail, suitable for dense visualizations
//!
//! The parameter roughly corresponds to the desired number of points in the output, though
//! ASAP may return more or fewer points based on what best preserves important patterns.
pub use smooth;