Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Commit af9eec6

Browse files
author
Jaquier Aurélien Tristan
committed
make the stagnation stopping criterion optional
1 parent 7f8df7d commit af9eec6

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

bluepyopt/deapext/CMA_MO.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def __init__(
9090
weight_hv=0.5,
9191
map_function=None,
9292
use_scoop=False,
93+
use_stagnation_criterion=True,
9394
):
9495
"""Constructor
9596
@@ -109,6 +110,8 @@ def __init__(
109110
map_function (map): function used to map (parallelize) the
110111
evaluation function calls
111112
use_scoop (bool): use scoop map for parallel computation
113+
use_stagnation_criterion (bool): whether to use the stagnation
114+
stopping criterion on top of the maximum generation criterion
112115
"""
113116

114117
if offspring_size is None:
@@ -165,8 +168,11 @@ def __init__(
165168

166169
self.stopping_conditions = [
167170
MaxNGen(max_ngen),
168-
Stagnationv2(lambda_, self.problem_size),
169171
]
172+
if use_stagnation_criterion:
173+
self.stopping_conditions.append(
174+
Stagnationv2(lambda_, self.problem_size)
175+
)
170176

171177
def _select(self, candidates):
172178
"""Select the best candidates of the population

bluepyopt/deapext/CMA_SO.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def __init__(
5959
RandIndCreator,
6060
map_function=None,
6161
use_scoop=False,
62+
use_stagnation_criterion=True,
6263
):
6364
"""Constructor
6465
@@ -74,6 +75,8 @@ def __init__(
7475
map_function (map): function used to map (parallelize) the
7576
evaluation function calls
7677
use_scoop (bool): use scoop map for parallel computation
78+
use_stagnation_criterion (bool): whether to use the stagnation
79+
stopping criterion on top of the maximum generation criterion
7780
"""
7881

7982
if offspring_size is None:
@@ -108,7 +111,6 @@ def __init__(
108111

109112
self.stopping_conditions = [
110113
MaxNGen(max_ngen),
111-
Stagnationv2(lambda_, self.problem_size),
112114
TolHistFun(lambda_, self.problem_size),
113115
EqualFunVals(lambda_, self.problem_size),
114116
NoEffectAxis(self.problem_size),
@@ -117,6 +119,10 @@ def __init__(
117119
ConditionCov(),
118120
NoEffectCoor(),
119121
]
122+
if use_stagnation_criterion:
123+
self.stopping_conditions.append(
124+
Stagnationv2(lambda_, self.problem_size)
125+
)
120126

121127
def update(self, population):
122128
"""Update the current covariance matrix strategy from the

bluepyopt/deapext/optimisationsCMA.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def __init__(
6161
selector_name="single_objective",
6262
weight_hv=0.5,
6363
fitness_reduce=numpy.sum,
64+
use_stagnation_criterion=True,
6465
):
6566
"""Constructor
6667
@@ -85,6 +86,8 @@ def __init__(
8586
is computed as 1 - weight_hv.
8687
fitness_reduce (fcn): function used to reduce the objective values
8788
to a single fitness score
89+
use_stagnation_criterion (bool): whether to use the stagnation
90+
stopping criterion on top of the maximum generation criterion
8891
"""
8992

9093
super(DEAPOptimisationCMA, self).__init__(evaluator=evaluator)
@@ -118,6 +121,8 @@ def __init__(
118121
"or 'multi_objective'. Not "
119122
"{}".format(self.selector_name)
120123
)
124+
125+
self.use_stagnation_criterion = use_stagnation_criterion
121126

122127
# Number of objective values
123128
self.problem_size = len(self.evaluator.params)
@@ -286,6 +291,7 @@ def run(
286291
RandIndCreator=self.toolbox.RandomInd,
287292
map_function=self.map_function,
288293
use_scoop=self.use_scoop,
294+
use_stagnation_criterion=self.use_stagnation_criterion,
289295
)
290296

291297
if self.selector_name == "multi_objective":

0 commit comments

Comments
 (0)