STL Rust
Seasonal-trend decomposition for Rust
🎉 Zero dependencies
Installation
Add this line to your application’s Cargo.toml under [dependencies]:
= "0.4"
Getting Started
Decompose a time series
use Stl;
let series = vec!;
let period = 7; // period of the seasonal component
let fit = fit?;
Get the components
let seasonal = fit.seasonal;
let trend = fit.trend;
let remainder = fit.remainder;
Robustness
Use robustness iterations
let fit = params.robust.fit?;
Get robustness weights
let weights = fit.weights;
Multiple Seasonality
Specify multiple periods
use Mstl;
let fit = fit?;
Parameters
Set STL parameters
let fit = params
.seasonal_length // length of the seasonal smoother
.trend_length // length of the trend smoother
.low_pass_length // length of the low-pass filter
.seasonal_degree // degree of locally-fitted polynomial in seasonal smoothing
.trend_degree // degree of locally-fitted polynomial in trend smoothing
.low_pass_degree // degree of locally-fitted polynomial in low-pass smoothing
.seasonal_jump // skipping value for seasonal smoothing
.trend_jump // skipping value for trend smoothing
.low_pass_jump // skipping value for low-pass smoothing
.inner_loops // number of loops for updating the seasonal and trend components
.outer_loops // number of iterations of robust fitting
.robust // if robustness iterations are to be used
.fit?;
Set MSTL parameters
let fit = params
.iterations // number of iterations
.lambda // lambda for Box-Cox transformation
.seasonal_lengths // lengths of the seasonal smoothers
.stl_params // STL params
.fit?;
Strength
Get the seasonal strength
let strength = fit.seasonal_strength;
Get the trend strength
let strength = fit.trend_strength;
Credits
This library was ported from the Fortran implementation.
References
- STL: A Seasonal-Trend Decomposition Procedure Based on Loess
- MSTL: A Seasonal-Trend Decomposition Algorithm for Time Series with Multiple Seasonal Patterns
- Measuring strength of trend and seasonality
History
View the changelog
Contributing
Everyone is encouraged to help improve this project. Here are a few ways you can help:
- Report bugs
- Fix bugs and submit pull requests
- Write, clarify, or fix documentation
- Suggest or add new features
To get started with development: