Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions nrt/monitor/iqr.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ class IQR(BaseNrt):
trend (bool): Indicate whether stable period fit is performed with
trend or not
harmonic_order (int): The harmonic order of the time-series regression
sensitivity (float): sensitivity of the monitoring. Lower numbers are
high sensitivity. Value can't be zero.
sensitivity (float, float) | (float): sensitivity of the monitoring. Lower numbers are
high sensitivity. Value can't be zero. Sensitivity for deviations of the residuals
in the negative and positive direction can be passed as a tuple (lower, upper).
If a single value is passed, the same sensitivity will be used for upper and lower deviations
boundary (int): Number of consecutive observations identified as outliers
to signal as disturbance
**kwargs: Used to set internal attributes when initializing with
Expand All @@ -70,7 +72,11 @@ def __init__(self, trend=True, harmonic_order=3, sensitivity=1.5, mask=None,
harmonic_order=harmonic_order,
boundary=boundary,
**kwargs)
self.sensitivity = sensitivity
self.sensitivity = (
sensitivity
if isinstance(sensitivity, tuple)
else (sensitivity, sensitivity)
)
self.q25 = kwargs.get('q25')
self.q75 = kwargs.get('q75')
self.monitoring_strategy = 'IQR'
Expand All @@ -89,8 +95,8 @@ def fit(self, dataarray, method='OLS', **kwargs):
def _update_process(self, residuals, is_valid):
# Compute upper and lower thresholds
iqr = self.q75 - self.q25
lower_limit = self.q25 - self.sensitivity * iqr
upper_limit = self.q75 + self.sensitivity * iqr
lower_limit = self.q25 - self.sensitivity[0] * iqr
upper_limit = self.q75 + self.sensitivity[1] * iqr
# compare residuals to thresholds
is_outlier = np.logical_or(residuals > upper_limit,
residuals < lower_limit)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ docs = [
"sphinx==7.4.7",
"dask",
"sphinx_rtd_theme==2.0.0",
"matplotlib==3.9.1",
"matplotlib==3.9.2",
"sphinx-gallery==0.17.0"
]

Expand Down
5 changes: 5 additions & 0 deletions tests/integration_tests/test_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
marks=pytest.mark.ewma),
'IQR': pytest.param(iqr.IQR, {'trend': False, 'harmonic_order': 1}, 3,
marks=pytest.mark.iqr),
'IQR_sensitivity_tuple': pytest.param(
iqr.IQR,
{'trend': False, 'harmonic_order': 1, 'sensitivity': (1,3)}, 3,
marks=pytest.mark.iqr_sens
),
'CUSUM': pytest.param(cusum.CuSum, {}, 6,
marks=pytest.mark.cusum),
'MOSUM': pytest.param(mosum.MoSum, {}, 6,
Expand Down
Loading