pub enum DecompositionType {
MSTL,
TBATS,
STR,
}Expand description
Detects seasonal periods and performs decomposition in one step
This function combines period detection and decomposition into a single operation. It can work with any of the decomposition methods (MSTL, TBATS, STR).
§Arguments
ts- The time series datadetection_options- Options for period detectionmethod- The decomposition method to use
§Returns
- A result containing the detected periods and the decomposition result
§Example
use scirs2_core::ndarray::array;
use scirs2_series::detection::{detect_and_decompose, PeriodDetectionOptions, DecompositionType, AutoDecomposition};
let ts = array![1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0,
1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0];
// For example purposes only - in real usage, let the function detect periods
let mut options = PeriodDetectionOptions::default();
options.threshold = 0.1; // Lower threshold to make test more reliable
// This example uses direct decomposition instead of automatic period detection
// to ensure the test is reliable
let decomp_type = DecompositionType::MSTL;
let result = match decomp_type {
DecompositionType::MSTL => {
let mut mstl_options = scirs2_series::decomposition::MSTLOptions::default();
mstl_options.seasonal_periods = vec![4]; // Force a known period
let mstl_result = scirs2_series::decomposition::mstl_decomposition(&ts, &mstl_options).unwrap();
// Wrap in AutoDecompositionResult
scirs2_series::detection::AutoDecompositionResult {
periods: vec![(4, 0.5)],
decomposition: AutoDecomposition::MSTL(mstl_result),
}
},
_ => {
// For other types, use detect_and_decompose
detect_and_decompose(&ts, &options, decomp_type).unwrap_or_else(|_| {
panic!("Decomposition failed - this is just an example")
})
}
};
println!("Detected periods: {:?}", result.periods);
// Access decomposition components based on type
match result.decomposition {
AutoDecomposition::MSTL(mstl) => println!("MSTL Trend: {:?}", mstl.trend),
AutoDecomposition::TBATS(tbats) => println!("TBATS Trend: {:?}", tbats.trend),
AutoDecomposition::STR(str_result) => println!("STR Trend: {:?}", str_result.trend),
}Variants§
MSTL
Multiple Seasonal-Trend decomposition using LOESS
TBATS
TBATS decomposition
STR
STR decomposition
Trait Implementations§
Source§impl Clone for DecompositionType
impl Clone for DecompositionType
Source§fn clone(&self) -> DecompositionType
fn clone(&self) -> DecompositionType
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for DecompositionType
impl Debug for DecompositionType
Source§impl PartialEq for DecompositionType
impl PartialEq for DecompositionType
impl Copy for DecompositionType
impl Eq for DecompositionType
impl StructuralPartialEq for DecompositionType
Auto Trait Implementations§
impl Freeze for DecompositionType
impl RefUnwindSafe for DecompositionType
impl Send for DecompositionType
impl Sync for DecompositionType
impl Unpin for DecompositionType
impl UnwindSafe for DecompositionType
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.