Skip to content

Commit

Permalink
Merge pull request optuna#5366 from contramundum53/fix-wilcoxon2
Browse files Browse the repository at this point in the history
Fix `average_is_best` implementation in `WilcoxonPruner`
  • Loading branch information
eukaryo committed Mar 28, 2024
2 parents 6a107a4 + 3981f69 commit 84a0c74
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions optuna/pruners/_wilcoxon.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,14 @@ def prune(self, study: "optuna.study.Study", trial: FrozenTrial) -> bool:

if study.direction == StudyDirection.MAXIMIZE:
alt = "less"
average_is_best = best_trial.value <= sum(step_values) / len(step_values)
average_is_best = sum(best_step_values) / len(best_step_values) <= sum(
step_values
) / len(step_values)
else:
alt = "greater"
average_is_best = best_trial.value >= sum(step_values) / len(step_values)
average_is_best = sum(best_step_values) / len(best_step_values) >= sum(
step_values
) / len(step_values)

# We use zsplit to avoid the problem when all values are zero.
p = ss.wilcoxon(diff_values, alternative=alt, zero_method="zsplit").pvalue
Expand Down

0 comments on commit 84a0c74

Please sign in to comment.