Skip to content

Commit 9513c3c

Browse files
committed
restart
1 parent 874efa1 commit 9513c3c

2 files changed

Lines changed: 45 additions & 16 deletions

File tree

src/interface.cpp

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ void define_options(py::module &main)
8585
.value("NONE", MatrixAdaptationType::NONE)
8686
.value("MATRIX", MatrixAdaptationType::MATRIX)
8787
.value("SEPERABLE", MatrixAdaptationType::SEPERABLE)
88+
.value("ONEPLUSONE", MatrixAdaptationType::ONEPLUSONE)
8889
.export_values();
8990

9091
py::enum_<CenterPlacement>(m, "CenterPlacement")
@@ -326,14 +327,6 @@ void define_matrix_adaptation(py::module &main)
326327
.def_readwrite("dd", &Adaptation::dd)
327328
.def_readwrite("expected_length_z", &Adaptation::expected_length_z)
328329
.def_readwrite("inv_C", &CovarianceAdaptation::inv_C)
329-
.def("adapt", &Adaptation::adapt,
330-
py::arg("weights"),
331-
py::arg("modules"),
332-
py::arg("population"),
333-
py::arg("mu"),
334-
py::arg("settings"),
335-
py::arg("stats")
336-
)
337330
.def("adapt_evolution_paths", &Adaptation::adapt_evolution_paths,
338331
py::arg("pop"),
339332
py::arg("weights"),
@@ -346,7 +339,9 @@ void define_matrix_adaptation(py::module &main)
346339
py::arg("modules"),
347340
py::arg("population"),
348341
py::arg("mu"),
349-
py::arg("settings"))
342+
py::arg("settings"),
343+
py::arg("stats")
344+
)
350345
.def("restart", &Adaptation::restart, py::arg("settings"))
351346
.def("compute_y", &Adaptation::compute_y, py::arg("zi"))
352347
.def("invert_x", &Adaptation::invert_x, py::arg("xi"), py::arg("sigma"))
@@ -421,6 +416,28 @@ void define_matrix_adaptation(py::module &main)
421416
ss << ">";
422417
return ss.str(); });
423418

419+
py::class_<OnePlusOneAdaptation, CovarianceAdaptation, std::shared_ptr<OnePlusOneAdaptation>>(m, "OnePlusOneAdaptation")
420+
.def(py::init<size_t, Vector, double>(), py::arg("dimension"), py::arg("x0"), py::arg("expected_length_z"))
421+
.def("__repr__", [](SeperableAdaptation &dyn)
422+
{
423+
std::stringstream ss;
424+
ss << std::boolalpha;
425+
ss << "<OnePlusOneAdaptation";
426+
ss << " m: " << dyn.m.transpose();
427+
ss << " m_old: " << dyn.m_old.transpose();
428+
ss << " dm: " << dyn.dm.transpose();
429+
ss << " pc: " << dyn.pc.transpose();
430+
ss << " ps: " << dyn.ps.transpose();
431+
ss << " d: " << dyn.d.transpose();
432+
ss << " B: " << dyn.B;
433+
ss << " C: " << dyn.C;
434+
ss << " inv_root_C: " << dyn.inv_root_C;
435+
ss << " dd: " << dyn.dd;
436+
ss << " expected_length_z: " << dyn.expected_length_z;
437+
ss << " hs: " << dyn.hs;
438+
ss << ">";
439+
return ss.str(); });
440+
424441
py::class_<MatrixAdaptation, Adaptation, std::shared_ptr<MatrixAdaptation>>(m, "MatrixAdaptation")
425442
.def(py::init<size_t, Vector, double>(), py::arg("dimension"), py::arg("x0"), py::arg("expected_length_z"))
426443
.def_readwrite("M", &MatrixAdaptation::M)
@@ -501,6 +518,7 @@ void define_parameters(py::module &main)
501518
.def_readwrite("current_best", &Stats::current_best)
502519
.def_readwrite("global_best", &Stats::global_best)
503520
.def_readwrite("has_improved", &Stats::has_improved)
521+
.def_readwrite("success_ratio", &Stats::success_ratio)
504522
.def("__repr__", [](Stats &stats)
505523
{
506524
std::stringstream ss;
@@ -613,6 +631,7 @@ void define_parameters(py::module &main)
613631
std::shared_ptr<matrix_adaptation::MatrixAdaptation>,
614632
std::shared_ptr<matrix_adaptation::CovarianceAdaptation>,
615633
std::shared_ptr<matrix_adaptation::SeperableAdaptation>,
634+
std::shared_ptr<matrix_adaptation::OnePlusOneAdaptation>,
616635
std::shared_ptr<matrix_adaptation::None>>;
617636

618637
py::class_<Parameters, std::shared_ptr<Parameters>>(main, "Parameters")
@@ -636,6 +655,8 @@ void define_parameters(py::module &main)
636655
return std::dynamic_pointer_cast<matrix_adaptation::None>(self.adaptation);
637656
case MatrixAdaptationType::SEPERABLE:
638657
return std::dynamic_pointer_cast<matrix_adaptation::SeperableAdaptation>(self.adaptation);
658+
case MatrixAdaptationType::ONEPLUSONE:
659+
return std::dynamic_pointer_cast<matrix_adaptation::OnePlusOneAdaptation>(self.adaptation);
639660
default:
640661
case MatrixAdaptationType::COVARIANCE:
641662
return std::dynamic_pointer_cast<matrix_adaptation::CovarianceAdaptation>(self.adaptation);
@@ -797,7 +818,7 @@ void define_mutation(py::module &main)
797818
py::arg("damps"),
798819
py::arg("sigma0"),
799820
py::arg("expected_length_z"))
800-
.def_readwrite("success_ratio", &PSR::succes_ratio);
821+
.def_readwrite("success_ratio", &PSR::success_ratio);
801822

802823
py::class_<XNES, CSA, std::shared_ptr<XNES>>(m, "XNES")
803824
.def(py::init<std::shared_ptr<ThresholdConvergence>, std::shared_ptr<SequentialSelection>, std::shared_ptr<SigmaSampler>, double, double, double, double>(),
@@ -830,7 +851,7 @@ void define_mutation(py::module &main)
830851
py::arg("expected_length_z"));
831852

832853

833-
py::class_<SR, CSA, std::shared_ptr<PSR>>(m, "SR")
854+
py::class_<SR, CSA, std::shared_ptr<SR>>(m, "SR")
834855
.def(py::init<std::shared_ptr<ThresholdConvergence>, std::shared_ptr<SequentialSelection>, std::shared_ptr<SigmaSampler>, double, double, double, double>(),
835856
py::arg("threshold_convergence"),
836857
py::arg("sequential_selection"),
@@ -839,9 +860,8 @@ void define_mutation(py::module &main)
839860
py::arg("damps"),
840861
py::arg("sigma0"),
841862
py::arg("expected_length_z"))
842-
.def_readwrite("success_ratio", &SR::succes_ratio)
843-
.def_readwrite("tgt_success_ratio", &SR::tgt_success_ratio)
844-
.def_readwrite("max_success_ratio", &SR::max_success_ratio);
863+
// .def_staticreadwrite("tgt_success_ratio", &SR::tgt_success_ratio)
864+
;
845865
}
846866

847867
void define_population(py::module &main)

src/restart.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,16 @@ namespace restart
125125
bool RestartCriteria::operator()(const parameters::Parameters &p)
126126
{
127127
update(p);
128-
any = exceeded_max_iter() or no_improvement() or flat_fitness() or stagnation() or min_sigma();
129-
any = any or (p.settings.modules.matrix_adaptation == parameters::MatrixAdaptationType::COVARIANCE and (tolx() or tolupsigma() or conditioncov() or noeffectaxis() or noeffectcoor()));
128+
any = exceeded_max_iter() or no_improvement() or stagnation() or min_sigma();
129+
if (p.settings.lambda0 > 1)
130+
{
131+
any = any or flat_fitness();
132+
}
133+
if (p.settings.modules.matrix_adaptation == parameters::MatrixAdaptationType::COVARIANCE)
134+
{
135+
any = any or tolx() or tolupsigma() or conditioncov() or noeffectaxis() or noeffectcoor();
136+
}
137+
130138
if (any)
131139
{
132140
if (p.settings.verbose)
@@ -141,6 +149,7 @@ namespace restart
141149
std::cout << " conditioncov: " << conditioncov();
142150
std::cout << " noeffectaxis: " << noeffectaxis();
143151
std::cout << " noeffectcoor: " << noeffectcoor();
152+
std::cout << " min_sigma: " << min_sigma();
144153
std::cout << " stagnation: " << stagnation() << '\n';
145154
}
146155
return true;

0 commit comments

Comments
 (0)