|
1 | 1 | //! Configuration types for SPOT detector |
2 | 2 |
|
| 3 | +/// GPD parameter estimator used by SPOT. |
| 4 | +/// |
| 5 | +/// The default keeps the historical libspot-rs behavior: try the supported |
| 6 | +/// estimators and keep the fit with the best log-likelihood. |
| 7 | +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] |
| 8 | +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
| 9 | +pub enum SpotEstimator { |
| 10 | + /// Try the available estimators and keep the best log-likelihood. |
| 11 | + #[default] |
| 12 | + Best, |
| 13 | + /// Force Method of Moments estimation. |
| 14 | + Mom, |
| 15 | +} |
| 16 | + |
| 17 | +/// Initial excess-threshold selection strategy. |
| 18 | +/// |
| 19 | +/// The default keeps the historical libspot-rs behavior. |
| 20 | +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] |
| 21 | +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
| 22 | +pub enum SpotInitialThreshold { |
| 23 | + /// Use the P2 streaming quantile estimator. |
| 24 | + #[default] |
| 25 | + P2, |
| 26 | + /// Use the empirical sorted quantile from the initial batch. |
| 27 | + Empirical, |
| 28 | +} |
| 29 | + |
| 30 | +/// Streaming excess update condition. |
| 31 | +/// |
| 32 | +/// The default keeps the historical libspot-rs behavior. |
| 33 | +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] |
| 34 | +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
| 35 | +pub enum SpotExcessUpdate { |
| 36 | + /// Update the tail when `value >= excess_threshold`. |
| 37 | + #[default] |
| 38 | + GreaterOrEqual, |
| 39 | + /// Update the tail only when `value > excess_threshold`. |
| 40 | + Greater, |
| 41 | +} |
| 42 | + |
3 | 43 | /// Configuration parameters for SPOT detector |
4 | 44 | /// |
5 | 45 | /// # Serialization |
@@ -72,4 +112,22 @@ mod tests { |
72 | 112 | assert_relative_eq!(config1.level, config2.level); |
73 | 113 | assert_eq!(config1.max_excess, config2.max_excess); |
74 | 114 | } |
| 115 | + |
| 116 | + #[test] |
| 117 | + fn test_spot_estimator_default_keeps_existing_behavior() { |
| 118 | + assert_eq!(SpotEstimator::default(), SpotEstimator::Best); |
| 119 | + } |
| 120 | + |
| 121 | + #[test] |
| 122 | + fn test_spot_initial_threshold_default_keeps_existing_behavior() { |
| 123 | + assert_eq!(SpotInitialThreshold::default(), SpotInitialThreshold::P2); |
| 124 | + } |
| 125 | + |
| 126 | + #[test] |
| 127 | + fn test_spot_excess_update_default_keeps_existing_behavior() { |
| 128 | + assert_eq!( |
| 129 | + SpotExcessUpdate::default(), |
| 130 | + SpotExcessUpdate::GreaterOrEqual |
| 131 | + ); |
| 132 | + } |
75 | 133 | } |
0 commit comments