From 24e1c0579a2d51c026d9928a02d248f374291305 Mon Sep 17 00:00:00 2001 From: hrntsm Date: Fri, 6 Sep 2024 08:26:09 +0900 Subject: [PATCH 1/3] Update MOEA/D --- package/samplers/moead/README.md | 31 +++++++++++-------- .../moead/_child_generation_strategy.py | 3 +- package/samplers/moead/moead.py | 3 +- package/samplers/moead/requirements.txt | 1 + 4 files changed, 23 insertions(+), 15 deletions(-) create mode 100644 package/samplers/moead/requirements.txt diff --git a/package/samplers/moead/README.md b/package/samplers/moead/README.md index d0de99db..b092b058 100644 --- a/package/samplers/moead/README.md +++ b/package/samplers/moead/README.md @@ -2,7 +2,7 @@ author: Hiroaki Natsume title: MOEA/D sampler description: Sampler using MOEA/D algorithm. MOEA/D stands for "Multi-Objective Evolutionary Algorithm based on Decomposition. -tags: [sampler, multiobjective] +tags: [sampler, multi-objective optimization] optuna_versions: [4.0.0] license: MIT License --- @@ -23,6 +23,12 @@ This sampler is specialized for multiobjective optimization. The objective funct pip install scipy ``` +or + +``` +pip install -r https://hub.optuna.org/samplers/moead/requirements.txt +``` + ## Example ```python @@ -38,18 +44,17 @@ def objective(trial: optuna.Trial) -> tuple[float, float]: return v0, v1 -if __name__ == "__main__": - population_size = 100 - n_trials = 1000 +population_size = 100 +n_trials = 1000 - mod = optunahub.load_module("samplers/moead") - sampler = mod.MOEADSampler( - population_size=population_size, - scalar_aggregation_func="tchebycheff", - n_neighbors=population_size // 10, - ) - study = optuna.create_study(sampler=sampler) - study.optimize(objective, n_trials=n_trials) +mod = optunahub.load_module("samplers/moead") +sampler = mod.MOEADSampler( + population_size=population_size, + scalar_aggregation_func="tchebycheff", + n_neighbors=population_size // 10, +) +study = optuna.create_study(sampler=sampler) +study.optimize(objective, n_trials=n_trials) ``` ## Others @@ -71,4 +76,4 @@ See `compare_2objective.py` in moead directory for details. Q. Zhang and H. Li, "MOEA/D: A Multiobjective Evolutionary Algorithm Based on Decomposition," in IEEE Transactions on Evolutionary Computation, vol. 11, no. 6, pp. 712-731, Dec. 2007, -doi: 10.1109/TEVC.2007.892759. +[doi: 10.1109/TEVC.2007.892759](https://doi.org/10.1109/TEVC.2007.892759). diff --git a/package/samplers/moead/_child_generation_strategy.py b/package/samplers/moead/_child_generation_strategy.py index 98ed6147..15f9ccbe 100644 --- a/package/samplers/moead/_child_generation_strategy.py +++ b/package/samplers/moead/_child_generation_strategy.py @@ -79,7 +79,7 @@ def __call__( parent_population: list[FrozenTrial], neighbors: dict[int, list[int]], ) -> dict[str, Any]: - """Generate a child parameter from the given parent population by NSGA-II algorithm. + """Generate a child parameter from the given parent population by MOEA/D algorithm. Args: study: Target study object. @@ -92,6 +92,7 @@ def __call__( Returns: A dictionary containing the parameter names and parameter's values. """ + # TODO: this implementation might have unexpected behavior in the case of multi-threading. subproblem_parent_population = [ parent_population[i] for i in neighbors[self._subproblem_id] ] diff --git a/package/samplers/moead/moead.py b/package/samplers/moead/moead.py index 5925bb09..38496e0e 100644 --- a/package/samplers/moead/moead.py +++ b/package/samplers/moead/moead.py @@ -4,6 +4,7 @@ import hashlib from typing import Any from typing import Dict +from typing import Literal from typing import TYPE_CHECKING import optuna @@ -34,7 +35,7 @@ def __init__( *, population_size: int = 100, n_neighbors: int | None = None, - scalar_aggregation_func: str = "tchebycheff", + scalar_aggregation_func: Literal["weighted_sum", "tchebycheff"] = "tchebycheff", mutation_prob: float | None = None, crossover: BaseCrossover | None = None, crossover_prob: float = 0.9, diff --git a/package/samplers/moead/requirements.txt b/package/samplers/moead/requirements.txt new file mode 100644 index 00000000..1fda602f --- /dev/null +++ b/package/samplers/moead/requirements.txt @@ -0,0 +1 @@ +scipy==1.13.1 \ No newline at end of file From 0bfe0c0ee628b9c6d721457f6ab5da6cc4fe26bb Mon Sep 17 00:00:00 2001 From: hrntsm Date: Fri, 6 Sep 2024 08:33:20 +0900 Subject: [PATCH 2/3] Update MOEA/D sampler README --- package/samplers/moead/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/package/samplers/moead/README.md b/package/samplers/moead/README.md index b092b058..66287303 100644 --- a/package/samplers/moead/README.md +++ b/package/samplers/moead/README.md @@ -13,6 +13,8 @@ Sampler using MOEA/D algorithm. MOEA/D stands for "Multi-Objective Evolutionary This sampler is specialized for multiobjective optimization. The objective function is internally decomposed into multiple single-objective subproblems to perform optimization. +It may not work well with multi-threading. Check results carefully. + ## Class or Function Names - MOEADSampler From af0f5f08a7c3a6d1e5fc75d4616fee0e160a51a0 Mon Sep 17 00:00:00 2001 From: hrntsm Date: Fri, 6 Sep 2024 09:36:38 +0900 Subject: [PATCH 3/3] Update MOEA/D sampler README tags --- package/samplers/moead/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/samplers/moead/README.md b/package/samplers/moead/README.md index 66287303..2c96998f 100644 --- a/package/samplers/moead/README.md +++ b/package/samplers/moead/README.md @@ -2,7 +2,7 @@ author: Hiroaki Natsume title: MOEA/D sampler description: Sampler using MOEA/D algorithm. MOEA/D stands for "Multi-Objective Evolutionary Algorithm based on Decomposition. -tags: [sampler, multi-objective optimization] +tags: [Sampler, Multi-Objective Optimization, Evolutionary Algorithms] optuna_versions: [4.0.0] license: MIT License ---