44
55namespace parameters
66{
7- static Float get_default_cs (const StepSizeAdaptation ssa , const Float mueff, const Float d)
7+ static Float get_default_cs (const Settings& settings , const Float mueff, const Float d)
88 {
9- switch (ssa)
9+ if (settings.modules .matrix_adaptation == MatrixAdaptationType::NATURAL_GRADIENT)
10+ return (9.0 + 3.0 + std::log (d)) / (5.0 * d * std::sqrt (d));
11+
12+ switch (settings.modules .ssa )
1013 {
1114 case StepSizeAdaptation::XNES:
1215 // return mueff / (2.0 * std::log(std::max(Float{ 2. }, d)) * sqrt(d));
@@ -26,9 +29,10 @@ namespace parameters
2629 }
2730 }
2831
29- static Float get_default_damps (const StepSizeAdaptation ssa, const Float mueff, const Float d, const Float cs)
32+
33+ static Float get_default_damps (const Settings& settings, const Float mueff, const Float d, const Float cs)
3034 {
31- switch (ssa)
35+ switch (settings. modules . ssa )
3236 {
3337 case StepSizeAdaptation::SR:
3438 return 1.0 + (d / 2.0 );
@@ -42,6 +46,49 @@ namespace parameters
4246 }
4347 }
4448
49+
50+ static Float get_default_c1 (const Settings& settings, const Float d, const Float mueff)
51+ {
52+ if (settings.one_plus_one )
53+ return 2.0 / (pow (d, 2 ) + 6.0 );
54+
55+ return 2.0 / (pow (d + 1.3 , 2 ) + mueff);
56+ }
57+
58+ static Float get_default_cc (const Settings& settings, const Float d, const Float mueff, const Float cs)
59+ {
60+ if (settings.modules .matrix_adaptation == MatrixAdaptationType::NATURAL_GRADIENT)
61+ return !settings.one_plus_one ? 0.5 * cs : (1.0 / (4.0 * pow (d, 1.5 )));
62+
63+
64+ if (settings.one_plus_one )
65+ return 2.0 / (d + 2.0 );
66+
67+ return (4.0 + (mueff / d)) / (d + 4.0 + (2.0 * mueff / d));
68+ }
69+
70+ static Float get_default_cmu (
71+ const Settings& settings,
72+ const Float d,
73+ const Float mueff,
74+ const Float c1
75+ )
76+ {
77+ Float cmu_default = std::min (
78+ 1.0 - c1, 2.0 * ((mueff - 2.0 + (1.0 / mueff)) / (pow (d + 2.0 , 2 ) + (2.0 * mueff / 2 ))));
79+
80+ if (settings.modules .matrix_adaptation == MatrixAdaptationType::SEPERABLE)
81+ cmu_default *= ((d + 2.0 ) / 3.0 );
82+
83+ if (settings.lambda0 == 1 )
84+ {
85+ cmu_default = 2 / (pow (d, 2 ) + 6.0 );
86+ }
87+ return cmu_default;
88+ }
89+
90+
91+
4592 Weights::Weights (
4693 const size_t dim,
4794 const size_t mu,
@@ -69,52 +116,29 @@ namespace parameters
69116 mueff_neg = std::pow (negative.sum (), 2 ) / negative.dot (negative);
70117 positive /= positive.sum ();
71118
72- c1 = settings.c1 .value_or (2.0 / (pow (d + 1.3 , 2 ) + mueff));
73-
74- Float cmu_default = std::min (
75- 1.0 - c1, 2.0 * ((mueff - 2.0 + (1.0 / mueff)) / (pow (d + 2.0 , 2 ) + (2.0 * mueff / 2 ))));
76-
77- if (settings.modules .matrix_adaptation == MatrixAdaptationType::SEPERABLE)
78- cmu_default *= ((d + 2.0 ) / 3.0 );
79-
80-
81- if (settings.lambda0 == 1 )
82- {
83- cmu_default = 2 / (pow (d, 2 ) + 6.0 );
84- }
85- cmu = settings.cmu .value_or (cmu_default);
86- cc = settings.cmu .value_or (
87- (4.0 + (mueff / d)) / (d + 4.0 + (2.0 * mueff / d))
88- );
89119
120+ c1 = settings.c1 .value_or (get_default_c1 (settings, d, mueff));
121+ cmu = settings.cmu .value_or (get_default_cmu (settings, d, mueff, c1));
122+ cs = settings.cs .value_or (get_default_cs (settings, mueff, d));
123+ cc = settings.cmu .value_or (get_default_cc (settings, d, mueff, cs));
124+ damps = get_default_damps (settings, mueff, d, cs);
90125
126+ sqrt_cs_mueff = std::sqrt (cs * (2.0 - cs) * mueff);
127+ sqrt_cc_mueff = std::sqrt (cc * (2.0 - cc) * mueff);
128+
91129 const Float amu_neg = 1.0 + (c1 / static_cast <Float>(mu));
92130 const Float amueff_neg = 1.0 + ((2.0 * mueff_neg) / (mueff + 2.0 ));
93131 const Float aposdef_neg = (1.0 - c1 - cmu) / (d * cmu);
94-
95132 const Float neg_scaler = std::min (amu_neg, std::min (amueff_neg, aposdef_neg));
96133
97134 negative *= (neg_scaler / negative.cwiseAbs ().sum ());
98135 weights << positive, negative;
99-
100136 lazy_update_interval = 1.0 / (c1 + cmu + 1e-23 ) / d / 10.0 ;
101-
102- cs = settings.cs .value_or (get_default_cs (settings.modules .ssa , mueff, d));//
103- damps = get_default_damps (settings.modules .ssa , mueff, d, cs);
104- sqrt_cs_mueff = std::sqrt (cs * (2.0 - cs) * mueff);
105- sqrt_cc_mueff = std::sqrt (cc * (2.0 - cc) * mueff);
106-
107137 expected_length_ps = (1.4 + (2.0 / (d + 1.0 ))) * expected_length_z;
108138
109139 beta = 1.0 / std::sqrt (2.0 * mueff);
110140 if (settings.modules .ssa == StepSizeAdaptation::LPXNES)
111141 beta = std::log (2.0 ) / (std::sqrt (d) * std::log (d));
112-
113- if (settings.modules .matrix_adaptation == MatrixAdaptationType::NATURAL_GRADIENT)
114- {
115- cs = (9.0 + 3.0 + std::log (d)) / (5.0 * d * std::sqrt (d));
116- cc = lambda != 1 ? 0.5 * cs : (1.0 / (4.0 * pow (d, 1.5 )));
117- }
118142 }
119143
120144
0 commit comments