Skip to content

Commit

Permalink
Fix early_stop when the metric is the larger the better (#374)
Browse files Browse the repository at this point in the history
* fix early stop best and mean;  update comments accordingly
  • Loading branch information
rayrayraykk authored Sep 13, 2022
1 parent b729f66 commit e64919c
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions federatedscope/core/monitors/early_stopper.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ def __track_and_check_best(self, history_result):
elif self.the_smaller_the_better and self.comparator(
self.improvement_operator(self.best_metric, -self.delta),
new_result):
# by default: add(val_loss, -delta) < new_result
# add(best_metric, -delta) < new_result
self.counter_no_improve += 1
elif not self.the_smaller_the_better and self.comparator(
self.improvement_operator(self.best_metric, self.delta),
new_result):
# typical case: add(eval_score, delta) > new_result
new_result,
self.improvement_operator(self.best_metric, self.delta)):
# new_result < add(best_metric, delta)
self.counter_no_improve += 1
else:
self.best_metric = new_result
Expand All @@ -80,9 +80,10 @@ def __track_and_check_mean(self, history_result):
-self.delta), new_result):
self.early_stopped = True
elif not self.the_smaller_the_better and self.comparator(
new_result,
self.improvement_operator(
np.mean(history_result[-self.patience - 1:-1]),
self.delta), new_result):
self.delta)):
self.early_stopped = True
else:
self.early_stopped = False
Expand Down

0 comments on commit e64919c

Please sign in to comment.