Skip to content

Commit

Permalink
Merge pull request optuna#5086 from nabenabe0928/doc/remove-motpe-sam…
Browse files Browse the repository at this point in the history
…pler-and-add-its-description-to-tpe-sampler

Add a note about the deprecation of MOTPESampler to the doc
  • Loading branch information
knshnb authored Nov 6, 2023
2 parents e5835b8 + 3b0e58e commit 523dcc2
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 6 deletions.
28 changes: 26 additions & 2 deletions optuna/multi_objective/samplers/_motpe.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,33 @@
class MOTPEMultiObjectiveSampler(BaseMultiObjectiveSampler):
"""Multi-objective sampler using the MOTPE algorithm.
This sampler is a multiobjective version of :class:`~optuna.samplers.TPESampler`.
This sampler is a multi-objective version of :class:`~optuna.samplers.TPESampler`.
For further information about MOTPE algorithm, please refer to the following paper:
.. note::
For `v2.4.0 <https://github.com/optuna/optuna/releases/tag/v2.4.0>`_ or later,
:class:`~optuna.multi_objective.samplers.MOTPEMultiObjectiveSampler` is deprecated and
:class:`~optuna.samplers.TPESampler` should be used instead. The following code shows how
you apply :class:`~optuna.samplers.TPESampler` to a multi-objective task:
.. testcode::
import optuna
def objective(trial):
x = trial.suggest_float("x", -100, 100)
y = trial.suggest_categorical("y", [-1, 0, 1])
f1 = x**2 + y
f2 = -((x - 2) ** 2 + y)
return f1, f2
# We minimize the first objective and maximize the second objective.
sampler = optuna.samplers.TPESampler()
study = optuna.create_study(directions=["minimize", "maximize"], sampler=sampler)
study.optimize(objective, n_trials=100)
For further information about MOTPE algorithm, please refer to the following papers:
- `Multiobjective tree-structured parzen estimator for computationally expensive optimization
problems <https://dl.acm.org/doi/abs/10.1145/3377930.3389817>`_
Expand Down
28 changes: 26 additions & 2 deletions optuna/samplers/_tpe/multi_objective_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,33 @@ def _default_weights_above(x: int) -> np.ndarray:
class MOTPESampler(TPESampler):
"""Multi-objective sampler using the MOTPE algorithm.
This sampler is a multiobjective version of :class:`~optuna.samplers.TPESampler`.
This sampler is a multi-objective version of :class:`~optuna.samplers.TPESampler`.
For further information about MOTPE algorithm, please refer to the following paper:
.. note::
For `v2.9.0 <https://github.com/optuna/optuna/releases/tag/v2.9.0>`_ or later,
:class:`~optuna.samplers.MOTPESampler` is deprecated and
:class:`~optuna.samplers.TPESampler` should be used instead. The following code shows how
you apply :class:`~optuna.samplers.TPESampler` to a multi-objective task:
.. testcode::
import optuna
def objective(trial):
x = trial.suggest_float("x", -100, 100)
y = trial.suggest_categorical("y", [-1, 0, 1])
f1 = x**2 + y
f2 = -((x - 2) ** 2 + y)
return f1, f2
# We minimize the first objective and maximize the second objective.
sampler = optuna.samplers.TPESampler()
study = optuna.create_study(directions=["minimize", "maximize"], sampler=sampler)
study.optimize(objective, n_trials=100)
For further information about MOTPE algorithm, please refer to the following papers:
- `Multiobjective tree-structured parzen estimator for computationally expensive optimization
problems <https://dl.acm.org/doi/abs/10.1145/3377930.3389817>`_
Expand Down
30 changes: 28 additions & 2 deletions optuna/samplers/_tpe/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,15 @@ class TPESampler(BaseSampler):
<https://papers.nips.cc/paper/4443-algorithms-for-hyper-parameter-optimization.pdf>`_
- `Making a Science of Model Search: Hyperparameter Optimization in Hundreds of
Dimensions for Vision Architectures <http://proceedings.mlr.press/v28/bergstra13.pdf>`_
- `Multiobjective tree-structured parzen estimator for computationally expensive optimization
problems <https://dl.acm.org/doi/10.1145/3377930.3389817>`_
For multi-objective TPE (MOTPE), please refer to the following papers:
- `Multiobjective Tree-Structured Parzen Estimator for Computationally Expensive Optimization
Problems <https://dl.acm.org/doi/10.1145/3377930.3389817>`_
- `Multiobjective Tree-Structured Parzen Estimator <https://doi.org/10.1613/jair.1.13188>`_
Example:
An example of a single-objective optimization is as follows:
.. testcode::
Expand All @@ -94,6 +98,28 @@ def objective(trial):
study = optuna.create_study(sampler=TPESampler())
study.optimize(objective, n_trials=10)
.. note::
:class:`~optuna.samplers.TPESampler` can handle a multi-objective task as well and
the following shows an example:
.. testcode::
import optuna
def objective(trial):
x = trial.suggest_float("x", -100, 100)
y = trial.suggest_categorical("y", [-1, 0, 1])
f1 = x**2 + y
f2 = -((x - 2) ** 2 + y)
return f1, f2
# We minimize the first objective and maximize the second objective.
sampler = optuna.samplers.TPESampler()
study = optuna.create_study(directions=["minimize", "maximize"], sampler=sampler)
study.optimize(objective, n_trials=100)
Args:
consider_prior:
Enhance the stability of Parzen estimator by imposing a Gaussian prior when
Expand Down

0 comments on commit 523dcc2

Please sign in to comment.