Skip to content
Merged
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
22 changes: 18 additions & 4 deletions src/capymoa/drift/detectors/hddm_a.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional
from typing import Literal, Optional

from capymoa.drift.base_detector import MOADriftDetector

Expand All @@ -24,7 +24,7 @@ class HDDMAverage(MOADriftDetector):
>>> for i in range(2000):
... detector.add_element(data_stream[i])
... if detector.detected_change():
... print('Change detected in data: ' + str(data_stream[i]) + ' - at index: ' + str(i))
... print("Change detected in data: " + str(data_stream[i]) + " - at index: " + str(i))
Change detected in data: 5 - at index: 999
Change detected in data: 7 - at index: 1019
Change detected in data: 7 - at index: 1330
Expand All @@ -33,7 +33,7 @@ class HDDMAverage(MOADriftDetector):
----------

Frias-Blanco, Isvani, et al. "Online and non-parametric drift
detection methods based on Hoeffdings bounds." IEEE Transactions on
detection methods based on Hoeffding's bounds." IEEE Transactions on
Knowledge and Data Engineering 27.3 (2014): 810-823.

"""
Expand All @@ -44,9 +44,23 @@ def __init__(
self,
drift_confidence: float = 0.001,
warning_confidence: float = 0.005,
test_type: str = "Two-sided",
test_type: Literal["Two-sided", "One-sided"] = "Two-sided",
CLI: Optional[str] = None,
):
"""
:param drift_confidence: Significance level for drift detection (p-value threshold).
:param warning_confidence: Significance level for warning detection (p-value threshold).
:param test_type: The type of statistical hypothesis test to use.

* ``"Two-sided"`` detects drift in both directions, i.e. both increases and
decreases in the monitored average. Use this when the direction of change
is unknown.
* ``"One-sided"`` only detects increases in the monitored average (i.e.
performance degradation). Use this when only positive drift is relevant.

:param CLI: (Advanced) Override the CLI arguments passed directly to the
underlying MOA detector, bypassing all other parameters.
"""
assert test_type in self.TEST_TYPES, "Wrong test type"

if CLI is None:
Expand Down
24 changes: 20 additions & 4 deletions src/capymoa/drift/detectors/hddm_w.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional
from typing import Literal, Optional

from capymoa.drift.base_detector import MOADriftDetector

Expand All @@ -23,11 +23,11 @@ class HDDMWeighted(MOADriftDetector):
>>> for i in range(2000):
... detector.add_element(data_stream[i])
... if detector.detected_change():
... print('Change detected in data: ' + str(data_stream[i]) + ' - at index: ' + str(i))
... print("Change detected in data: " + str(data_stream[i]) + " - at index: " + str(i))
Change detected in data: 6 - at index: 1234

.. [#f1] Frias-Blanco, Isvani, et al. "Online and non-parametric drift detection methods
based on Hoeffdings bounds." IEEE Transactions on Knowledge and Data Engineering
based on Hoeffding's bounds." IEEE Transactions on Knowledge and Data Engineering
27.3 (2014): 810-823.
"""

Expand All @@ -38,9 +38,25 @@ def __init__(
drift_confidence: float = 0.001,
warning_confidence: float = 0.005,
lambda_: float = 0.05,
test_type: str = "Two-sided",
test_type: Literal["Two-sided", "One-sided"] = "Two-sided",
CLI: Optional[str] = None,
):
"""
:param drift_confidence: Significance level for drift detection (p-value threshold).
:param warning_confidence: Significance level for warning detection (p-value threshold).
:param lambda_: Forgetting factor (decay rate) for the weighted mean. A smaller
value gives more weight to recent observations.
:param test_type: The type of statistical hypothesis test to use.

* ``"Two-sided"`` detects drift in both directions, i.e. both increases and
decreases in the monitored weighted average. Use this when the direction of
change is unknown.
* ``"One-sided"`` only detects increases in the monitored weighted average
(i.e. performance degradation). Use this when only positive drift is relevant.

:param CLI: (Advanced) Override the CLI arguments passed directly to the
underlying MOA detector, bypassing all other parameters.
"""
assert test_type in self.TEST_TYPES, "Wrong test type"

if CLI is None:
Expand Down
Loading