From 36676bb288e2ad7bd15fc248c5747067b9d2e827 Mon Sep 17 00:00:00 2001 From: Toshihiko Yanase Date: Wed, 12 Jun 2024 19:57:55 +0900 Subject: [PATCH] Add median pruner --- package/pruners/median/LICENSE | 21 ++++++++++++++++++ package/pruners/median/README.md | 37 ++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 package/pruners/median/LICENSE create mode 100644 package/pruners/median/README.md diff --git a/package/pruners/median/LICENSE b/package/pruners/median/LICENSE new file mode 100644 index 00000000..4e2b34c1 --- /dev/null +++ b/package/pruners/median/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Preferred Networks, Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/package/pruners/median/README.md b/package/pruners/median/README.md new file mode 100644 index 00000000..bb58845a --- /dev/null +++ b/package/pruners/median/README.md @@ -0,0 +1,37 @@ +--- +author: 'Optuna team' +title: 'Median Pruner' +description: 'Pruner using the median stopping rule.' +tags: ['pruner', 'built-in'] +optuna_versions: ['3.6.1'] +license: 'MIT License' +--- + +## Class or Function Names +- MedianPruner + +## Example +```python +import optuna +from optuna.pruners import MedianPruner + + +def objective(trial): + s = 0 + for step in range(20): + x = trial.suggest_float(f"x_{step}", -5, 5) + s += x**2 + trial.report(s, step) + if trial.should_prune(): + raise optuna.TrialPruned() + return s + + +pruner = MedianPruner() +study = optuna.create_study(pruner=pruner) +study.optimize(objective, n_trials=20) +``` + +## Others +See the [documentation](https://optuna.readthedocs.io/en/stable/reference/generated/optuna.pruners.MedianPruner.html) for more details. +