Skip to content

Commit

Permalink
[options_parameters] implement amend_restarts_parameter(restarts)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikohansen committed Sep 2, 2024
1 parent e4a96da commit efe1dd4
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions cma/options_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@
from .recombination_weights import RecombinationWeights


default_restart_number_if_not_zero = 9
def amend_restarts_parameter(restarts):
"""return a `dict` with ``'maxrestarts'`` and ``'maxfevals'`` as keys.
`restarts` is a parameter to ``cma.fmin*``, see `cma.fmin`.
"""
if restarts is True:
restarts = {'maxrestarts': default_restart_number_if_not_zero}
elif not restarts:
restarts = {'maxrestarts': 0}
if not isinstance(restarts, dict): # kinda assume that restart is an int
restarts = {'maxrestarts': restarts}
restarts.setdefault('maxrestarts', default_restart_number_if_not_zero)
restarts.setdefault('maxfevals', np.inf)
return restarts

def is_feasible(x, f):
"""default to check feasibility of f-values.
Expand Down

0 comments on commit efe1dd4

Please sign in to comment.