Skip to content

Commit 2ac476e

Browse files
authored
Merge pull request #48 from IOHprofiler/refactoring_restarting
Refactoring restarting
2 parents 90d3891 + 5a7006d commit 2ac476e

2 files changed

Lines changed: 40 additions & 3 deletions

File tree

README.md

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,13 +379,29 @@ For C++, the `BaseSampler` enum should be provided to the `sampler` member of th
379379

380380
```python
381381
...
382-
modules.sampler = c_maes.options.BaseSampler.GAUSSIAN
382+
modules.sampler = c_maes.options.BaseSampler.UNIFORM
383383
# or
384384
modules.sampler = c_maes.options.BaseSampler.SOBOL
385385
# or
386386
modules.sampler = c_maes.options.BaseSampler.HALTON
387387
```
388388

389+
Here, this works slightly different. The base sampler only defined the method for generating uniform sampling in a $[0,1)^d$ hyperbox. In order to define that a, for example, Gaussian distribution (this is default) should be used when running the algorithm, we need to specify the `sample_transformation` type:
390+
391+
```python
392+
modules.sample_transformation = c_maes.options.SampleTranformerType.GAUSSIAN
393+
# or
394+
modules.sample_transformation = c_maes.options.SampleTranformerType.SCALED_UNIFORM
395+
# or
396+
modules.sample_transformation = c_maes.options.SampleTranformerType.LAPLACE
397+
# or
398+
modules.sample_transformation = c_maes.options.SampleTranformerType.LOGISTIC
399+
# or
400+
modules.sample_transformation = c_maes.options.SampleTranformerType.CAUCHY
401+
# or
402+
modules.sample_transformation = c_maes.options.SampleTranformerType.DOUBLE_WEIBULL
403+
```
404+
389405
### Recombination Weights <a name="recombination-weights"></a>
390406

391407
We implemented three different variants of the recombination weights used in the update of the strategy parameters, default, equal and $1/2\lambda$.
@@ -478,7 +494,27 @@ modules.restart_strategy = c_maes.options.RestartStrategy.NONE
478494
modules.restart_strategy = c_maes.options.RestartStrategy.IPOP
479495
```
480496

481-
Note that the C++ version has an addtional option here, `STOP`, which forces the algortihm to stop whenever a restart condition is met (not to be confused with a break condition).
497+
Note that the C++ version has an addtional option here, `STOP`, which forces the algortihm to stop whenever a restart condition is met (not to be confused with a break condition). The C++ version also offers fine control over when a restart happens. The `Parameters` object has an `criteria` member, of which the `items` member defines a list of `Criterion` objects, which are triggers for when a restart should happen. This list can be freely changed, and default items can be deleted and modified if desired. For example, `cma.p.criteria.items = []`, clears this list entirely, and no restarts will happen. Several of the currently defined `Criterion` object can also be modified, often this can be controlled by setting the `tolerance` parameter. For example, for the `MinSigma` criterion, you can set `c_maes.restart.MinSigma.tolerance = 1` to ensure a parameter value of sigma below 1 triggers a restart. Note that this is a static varaible, so modifying it in this fashion sets this for all instances of `c_maes.restart.MinSigma`. Alternatively, it is possible to define a custom `Criterion` like so:
498+
499+
```python
500+
class MyCriterion(modcma.restart.Criterion):
501+
def __init__(self):
502+
super().__init__("MyCriterionName")
503+
504+
def on_reset(self, par: modcma.Parameters):
505+
"""Called when a restart happens (also at the start)"""
506+
507+
def update(self, par: modcma.Parameters):
508+
"""Called after each iteration, needs to modify self.met"""
509+
self.met = True
510+
511+
# Python needs a reference to this object,
512+
# so you CANNOT create it in place, i.e.
513+
# cma.p.criteria.items = [MyCriterion()]
514+
# will produce an error
515+
c = MyCriterion()
516+
cma.p.criteria.items = [c]
517+
```
482518

483519
### Bound correction
484520

src/mutation.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ namespace mutation
220220
default:
221221
case StepSizeAdaptation::CSA:
222222
cs = cs0.value_or((mueff + 2.0) / (d + mueff + 5.0));
223-
damps = 1.0 + (2.0 * std::max(Float{0.0}, sqrt((mueff - 1.0) / (d + 1)) - 1) + cs);
223+
const Float rhs = std::sqrt((mueff - Float(1.0)) / (d + 1)) - 1;
224+
damps = 1.0 + (2.0 * std::max(Float(0.0), rhs) + cs);
224225
return std::make_shared<CSA>(tc, sq, ss, cs, damps, sigma, expected_z);
225226
}
226227
}

0 commit comments

Comments
 (0)