diff --git a/optuna/multi_objective/samplers/_motpe.py b/optuna/multi_objective/samplers/_motpe.py index 87b0787e15..9f358b798a 100644 --- a/optuna/multi_objective/samplers/_motpe.py +++ b/optuna/multi_objective/samplers/_motpe.py @@ -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 `_ 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 `_ diff --git a/optuna/samplers/_tpe/multi_objective_sampler.py b/optuna/samplers/_tpe/multi_objective_sampler.py index ebd35d1352..6f9ff9f78e 100644 --- a/optuna/samplers/_tpe/multi_objective_sampler.py +++ b/optuna/samplers/_tpe/multi_objective_sampler.py @@ -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 `_ 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 `_ diff --git a/optuna/samplers/_tpe/sampler.py b/optuna/samplers/_tpe/sampler.py index 4835109ef4..cdb66fdd4c 100644 --- a/optuna/samplers/_tpe/sampler.py +++ b/optuna/samplers/_tpe/sampler.py @@ -74,11 +74,15 @@ class TPESampler(BaseSampler): `_ - `Making a Science of Model Search: Hyperparameter Optimization in Hundreds of Dimensions for Vision Architectures `_ - - `Multiobjective tree-structured parzen estimator for computationally expensive optimization - problems `_ + + For multi-objective TPE (MOTPE), please refer to the following papers: + + - `Multiobjective Tree-Structured Parzen Estimator for Computationally Expensive Optimization + Problems `_ - `Multiobjective Tree-Structured Parzen Estimator `_ Example: + An example of a single-objective optimization is as follows: .. testcode:: @@ -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