Skip to content

Commit

Permalink
Make HDDM drift detectors report downward changes (online-ml#575)
Browse files Browse the repository at this point in the history
* Make HDDM_A properly report downward drift with two_sided_test

* Make HDDM_W report concept drift during downward changes when two_sided_test is set to True

* Fix downward warning zone in HDDM_W

* Fix downward warning zone in HDDM_W
  • Loading branch information
Michał Pogoda authored Aug 17, 2021
1 parent 32aadd0 commit 8ef9774
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
24 changes: 15 additions & 9 deletions river/drift/hddm_a.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,19 @@ def update(self, value) -> tuple:
self._in_concept_change = False
self._in_warning_zone = False

if self.two_sided_test and self._mean_decr(
self.c_max, self.n_max, self.total_c, self.total_n
):
self.n_estimation = self.total_n - self.n_max
self.c_estimation = self.total_c - self.c_max
self.n_min = self.n_max = self.total_n = 0
self.c_min = self.c_max = self.total_c = 0
if self.two_sided_test:
if self._mean_decr(
self.c_max, self.n_max, self.total_c, self.total_n, self.drift_confidence
):
self.n_estimation = self.total_n - self.n_max
self.c_estimation = self.total_c - self.c_max
self.n_min = self.n_max = self.total_n = 0
self.c_min = self.c_max = self.total_c = 0
self._in_concept_change = True
elif self._mean_decr(
self.c_max, self.n_max, self.total_c, self.total_n, self.warning_confidence
):
self._in_warning_zone = True

self._update_estimations()

Expand All @@ -153,12 +159,12 @@ def _mean_incr(c_min, n_min, total_c, total_n, confidence):
cota = sqrt(m / 2 * log(2.0 / confidence))
return total_c / total_n - c_min / n_min >= cota

def _mean_decr(self, c_max, n_max, total_c, total_n):
def _mean_decr(self, c_max, n_max, total_c, total_n, confidence):
if n_max == total_n:
return False

m = (total_n - n_max) / n_max * (1.0 / total_n)
cota = sqrt(m / 2 * log(2.0 / self.drift_confidence))
cota = sqrt(m / 2 * log(2.0 / confidence))
return c_max / n_max - total_c / total_n >= cota

def reset(self):
Expand Down
9 changes: 7 additions & 2 deletions river/drift/hddm_w.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,13 @@ def update(self, value):
self._in_warning_zone = False

self._update_decr_statistics(value, self.drift_confidence)
if self.two_sided_test and self._monitor_mean_decr(self.drift_confidence):
self.reset()
if self.two_sided_test:
if self._monitor_mean_decr(self.drift_confidence):
self.reset()
self._in_concept_change = True
elif self._monitor_mean_decr(self.warning_confidence):
self._in_warning_zone = True

self.estimation = self.total.EWMA_estimator

return self._in_concept_change, self._in_warning_zone
Expand Down

0 comments on commit 8ef9774

Please sign in to comment.