Skip to content

Commit f6c3fe7

Browse files
committed
correct CMSA init
1 parent 47f0da5 commit f6c3fe7

7 files changed

Lines changed: 505 additions & 42 deletions

File tree

include/settings.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ namespace parameters
7373
mu0 = lambda0 / 2;
7474
}
7575

76-
if (modules.ssa == StepSizeAdaptation::SA)
76+
if (modules.ssa == StepSizeAdaptation::SA || modules.matrix_adaptation == MatrixAdaptationType::CMSA)
7777
{
7878
mu0 = mu.value_or(lambda0 / 4);
7979
}

scripts/matrix/get_data.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@
55
import ioh
66
import pandas as pd
77

8-
from multiprocessing import Pool
8+
from multiprocessing import Pool, Process
99
import cma as pycma
1010

1111
from pprint import pprint
1212

1313
np.random.seed(12)
1414

15-
DIMS = 2, 3, 5, 10, 20, 40, 100
16-
FUNCTIONS = [1, 2, 6, 8, 9, 10, 11, 12, 13, 14]
15+
DIMS = 2, 3, 5, 10, 20, 40, #100
16+
FUNCTIONS = [3, 4, 5, 7] + list(range(15, 25)) #[1, 2, 6, 8, 9, 10, 11, 12, 13, 14]
1717
N_REPEATS = 100
1818
BUDGET = 100_000
19+
ROOT = "data"
20+
1921

2022
def run_modma(problem: ioh.ProblemType,
2123
x0: np.ndarray,
@@ -24,6 +26,7 @@ def run_modma(problem: ioh.ProblemType,
2426
):
2527
modules = modcma.parameters.Modules()
2628
modules.matrix_adaptation = matrix_adaptation
29+
modules.restart_strategy = modcma.options.RestartStrategy.STOP
2730

2831
settings = modcma.Settings(
2932
problem.meta_data.n_variables,
@@ -45,14 +48,17 @@ def run_modma(problem: ioh.ProblemType,
4548
logger_obj.update(cma.p.criteria.items)
4649
cma.step(problem)
4750

51+
if cma.p.criteria.any():
52+
logger_obj.update(cma.p.criteria.items)
53+
4854
cma.run(problem)
4955
stop = perf_counter()
5056
elapsed = stop - start
5157
return elapsed, cma.p.stats.t, problem.state.evaluations, cma.p.stats.n_updates
5258

5359

5460
class RestartCollector:
55-
def __init__(self, strategy = modcma.options.RestartStrategy.NONE):
61+
def __init__(self, strategy = modcma.options.RestartStrategy.STOP):
5662
modules = modcma.parameters.Modules()
5763
modules.restart_strategy = strategy
5864
settings = modcma.Settings(
@@ -77,7 +83,7 @@ def collect(name, option):
7783
logger = ioh.logger.Analyzer(
7884
folder_name=name,
7985
algorithm_name=name,
80-
root="data"
86+
root=ROOT
8187
)
8288
collector = RestartCollector()
8389
logger.add_run_attributes(collector, collector.names)
@@ -105,22 +111,29 @@ def run_pycma(problem: ioh.ProblemType, x0: np.ndarray):
105111
options['CMA_active'] = False
106112
options["verbose"] = -1
107113
options["CMA_diagonal"] = False
114+
options['conditioncov_alleviate'] = False
115+
options['ftarget'] = problem.optimum.y + 1e-8
116+
options['maxfevals'] = problem.meta_data.n_variables * BUDGET
108117

109118
cma = pycma.CMAEvolutionStrategy(x0, 2.0, options=options)
110119
settings = modcma.Settings(problem.meta_data.n_variables)
111120
assert settings.lambda0 == cma.sp.popsize
112121
start = perf_counter()
113122

114123
target = problem.optimum.y + 1e-8
115-
budget = problem.meta_data.n_variables * 100_000
124+
budget = problem.meta_data.n_variables * BUDGET
116125

117126
with warnings.catch_warnings():
118127
warnings.simplefilter("ignore")
119128
while problem.state.evaluations < budget:
120129
X, y = cma.ask_and_eval(problem)
121130
cma.tell(X, y)
131+
122132
if problem.state.current_best.y <= target:
123133
break
134+
if cma.stop():
135+
break
136+
124137

125138
stop = perf_counter()
126139
elapsed = stop - start
@@ -131,7 +144,7 @@ def collect_pycma():
131144
logger = ioh.logger.Analyzer(
132145
folder_name="pycma",
133146
algorithm_name="pycma",
134-
root="data"
147+
root=ROOT
135148
)
136149
for fid in FUNCTIONS:
137150
for d in DIMS:
@@ -146,8 +159,10 @@ def collect_pycma():
146159

147160

148161
if __name__ == "__main__":
149-
collect_modcma()
150-
collect_pycma()
151-
# problem = ioh.get_problem(fid, 1, d)
152-
# run_modma(problem, np.zeros(d), modcma.options.CMSA)
153-
# print(problem.state.evaluations, problem.state.current_best_internal.y)
162+
p1 = Process(target=collect_modcma)
163+
p2 = Process(target=collect_pycma)
164+
165+
p1.start()
166+
p2.start()
167+
p1.join()
168+
p2.join()

scripts/matrix/plots.ipynb

Lines changed: 169 additions & 26 deletions
Large diffs are not rendered by default.

scripts/matrix/test_timing_modules.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,15 @@ def run_pycma(problem: ioh.ProblemType, x0: np.ndarray, max_generations=1000):
3939
options = pycma.CMAOptions()
4040
options['CMA_active'] = False
4141
# options['maxfevals'] = n_evaluations
42-
options["verbose"] = -1
42+
options['conditioncov_alleviate'] = False
43+
options["verbose"] = 10
4344
options["CMA_diagonal"] = False
44-
# pprint(options)
45+
pprint(options)
4546

4647
cma = pycma.CMAEvolutionStrategy(x0, 2.0, options=options)
4748
settings = modcma.Settings(problem.meta_data.n_variables)
4849
assert settings.lambda0 == cma.sp.popsize
50+
np.random.seed(1)
4951
start = perf_counter()
5052
with warnings.catch_warnings():
5153
warnings.simplefilter("ignore")
@@ -95,4 +97,5 @@ def collect():
9597
print(stats[-1])
9698
stats = pd.DataFrame(stats, columns=["method", "dim", "time", "n_gen", "n_evals", "n_updates"])
9799
stats.to_csv("time_stats_pycma.csv")
98-
print(stats)
100+
print(stats)
101+
159 KB
Loading
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
,method,dim,time,n_gen,n_evals,n_updates
2+
0,pycma,2,0.37522817799981567,1000,6000,999
3+
1,pycma,2,0.35026270899834344,1000,6000,999
4+
2,pycma,2,0.38061815299806767,1000,6000,999
5+
3,pycma,2,0.371050321002258,1000,6000,999
6+
4,pycma,2,0.3834923089998483,1000,6000,999
7+
5,pycma,2,0.38832244299919694,1000,6000,999
8+
6,pycma,2,0.3609898909999174,1000,6000,999
9+
7,pycma,2,0.3540546139993239,1000,6000,999
10+
8,pycma,2,0.35726390200215974,1000,6000,999
11+
9,pycma,2,0.37336513600166654,1000,6000,999
12+
10,pycma,2,0.3485748130005959,1000,6000,999
13+
11,pycma,2,0.3616545689983468,1000,6000,999
14+
12,pycma,2,0.3680542699985381,1000,6000,999
15+
13,pycma,2,0.4078554309999163,1000,6000,999
16+
14,pycma,2,0.39954378999755136,1000,6000,999
17+
15,pycma,3,0.4218292980003753,1000,7000,999
18+
16,pycma,3,0.3625786029988376,1000,7000,999
19+
17,pycma,3,0.38367819099948974,1000,7000,999
20+
18,pycma,3,0.3894981869998446,1000,7000,999
21+
19,pycma,3,0.4074977750024118,1000,7000,999
22+
20,pycma,3,0.3648669880021771,1000,7000,999
23+
21,pycma,3,0.3805558249987371,1000,7000,999
24+
22,pycma,3,0.3384024529987073,1000,7000,999
25+
23,pycma,3,0.3313572570004908,1000,7000,999
26+
24,pycma,3,0.3242036880001251,1000,7000,999
27+
25,pycma,3,0.3904495400020096,1000,7000,999
28+
26,pycma,3,0.41853813499983517,1000,7000,999
29+
27,pycma,3,0.3413846920011565,1000,7000,999
30+
28,pycma,3,0.35553036000055727,1000,7000,999
31+
29,pycma,3,0.36115081800016924,1000,7000,999
32+
30,pycma,5,0.38601215000016964,1000,8000,999
33+
31,pycma,5,0.37565997799902107,1000,8000,999
34+
32,pycma,5,0.48298051999881864,1000,8000,999
35+
33,pycma,5,0.3780222640016291,1000,8000,999
36+
34,pycma,5,0.3550963449997653,1000,8000,999
37+
35,pycma,5,0.4183996469982958,1000,8000,999
38+
36,pycma,5,0.38270922800074914,1000,8000,999
39+
37,pycma,5,0.3744809140007419,1000,8000,999
40+
38,pycma,5,0.36361514200325473,1000,8000,999
41+
39,pycma,5,0.3987166539991449,1000,8000,999
42+
40,pycma,5,0.3683125730021857,1000,8000,999
43+
41,pycma,5,0.3756415770003514,1000,8000,999
44+
42,pycma,5,0.403191812998557,1000,8000,999
45+
43,pycma,5,0.35686238199923537,1000,8000,999
46+
44,pycma,5,0.35758409399932134,1000,8000,999
47+
45,pycma,10,0.39849778799907654,1000,10000,999
48+
46,pycma,10,0.4263918309989094,1000,10000,999
49+
47,pycma,10,0.4185187240000232,1000,10000,999
50+
48,pycma,10,0.3943962539997301,1000,10000,999
51+
49,pycma,10,0.4023051649965055,1000,10000,999
52+
50,pycma,10,0.414724254002067,1000,10000,999
53+
51,pycma,10,0.419106314999226,1000,10000,999
54+
52,pycma,10,0.44850920799945015,1000,10000,999
55+
53,pycma,10,0.4095437670002866,1000,10000,999
56+
54,pycma,10,0.4093704320002871,1000,10000,999
57+
55,pycma,10,0.41309320099753677,1000,10000,999
58+
56,pycma,10,0.42540818300039973,1000,10000,999
59+
57,pycma,10,0.4208158609981183,1000,10000,999
60+
58,pycma,10,0.47719614199741045,1000,10000,999
61+
59,pycma,10,0.3971106390017667,1000,10000,999
62+
60,pycma,20,0.5163924760017835,1000,12000,999
63+
61,pycma,20,0.4847462239995366,1000,12000,999
64+
62,pycma,20,0.492077203001827,1000,12000,999
65+
63,pycma,20,0.4922437660025025,1000,12000,999
66+
64,pycma,20,0.48513822200038703,1000,12000,999
67+
65,pycma,20,0.5000314070020977,1000,12000,999
68+
66,pycma,20,0.519929524998588,1000,12000,999
69+
67,pycma,20,0.5026444150025782,1000,12000,999
70+
68,pycma,20,0.49061895799968624,1000,12000,999
71+
69,pycma,20,0.4971232220013917,1000,12000,999
72+
70,pycma,20,0.48960660999728134,1000,12000,999
73+
71,pycma,20,0.4893950049990963,1000,12000,999
74+
72,pycma,20,0.5024925540019467,1000,12000,999
75+
73,pycma,20,0.4991692269977648,1000,12000,999
76+
74,pycma,20,0.5198710129989195,1000,12000,999
77+
75,pycma,40,0.7619934060021478,1000,15000,999
78+
76,pycma,40,0.8076867339987075,1000,15000,999
79+
77,pycma,40,0.725300336998771,1000,15000,999
80+
78,pycma,40,0.7365077829999791,1000,15000,999
81+
79,pycma,40,0.7172894770010316,1000,15000,999
82+
80,pycma,40,0.7249836160008272,1000,15000,999
83+
81,pycma,40,0.7261079090021667,1000,15000,999
84+
82,pycma,40,0.7452911920008773,1000,15000,999
85+
83,pycma,40,0.7764294869994046,1000,15000,999
86+
84,pycma,40,0.7558684180003183,1000,15000,999
87+
85,pycma,40,0.779672420998395,1000,15000,999
88+
86,pycma,40,0.7185493069991935,1000,15000,999
89+
87,pycma,40,0.7282580280007096,1000,15000,999
90+
88,pycma,40,0.725094862998958,1000,15000,999
91+
89,pycma,40,0.7324797670007683,1000,15000,999
92+
90,pycma,100,1.1860735909976938,1000,17000,499
93+
91,pycma,100,1.179873047000001,1000,17000,499
94+
92,pycma,100,1.1579261769984441,1000,17000,499
95+
93,pycma,100,1.1868787919993338,1000,17000,499
96+
94,pycma,100,1.1689511779986788,1000,17000,499
97+
95,pycma,100,1.1685953640007938,1000,17000,499
98+
96,pycma,100,1.1752932720009994,1000,17000,499
99+
97,pycma,100,1.1767060749989469,1000,17000,499
100+
98,pycma,100,1.263973029999761,1000,17000,499
101+
99,pycma,100,1.1710044499996002,1000,17000,499
102+
100,pycma,100,1.1632260660007887,1000,17000,499
103+
101,pycma,100,1.162450912001077,1000,17000,499
104+
102,pycma,100,1.2229755409971403,1000,17000,499
105+
103,pycma,100,1.1903688200000033,1000,17000,499
106+
104,pycma,100,1.1521793680003611,1000,17000,499
107+
105,pycma,200,2.293771057000413,1000,19000,333
108+
106,pycma,200,2.225037386000622,1000,19000,333
109+
107,pycma,200,2.2743380059982883,1000,19000,333
110+
108,pycma,200,2.3483467389996804,1000,19000,333
111+
109,pycma,200,2.406930986999214,1000,19000,333
112+
110,pycma,200,2.2418446960000438,1000,19000,333
113+
111,pycma,200,2.3124730449999333,1000,19000,333
114+
112,pycma,200,2.239005701998394,1000,19000,333
115+
113,pycma,200,2.2397954230000323,1000,19000,333
116+
114,pycma,200,2.29090806000022,1000,19000,333
117+
115,pycma,200,2.2225995649969263,1000,19000,333
118+
116,pycma,200,2.279442361003021,1000,19000,333
119+
117,pycma,200,2.2536674520015367,1000,19000,333
120+
118,pycma,200,2.274126060998242,1000,19000,333
121+
119,pycma,200,2.2505753169971285,1000,19000,333
122+
120,pycma,500,8.518034722001175,1000,22000,199
123+
121,pycma,500,8.57804089199999,1000,22000,199
124+
122,pycma,500,8.334146625998983,1000,22000,199
125+
123,pycma,500,8.673984130000463,1000,22000,199
126+
124,pycma,500,8.340618348000135,1000,22000,199
127+
125,pycma,500,8.30776469799821,1000,22000,199
128+
126,pycma,500,8.358887310998398,1000,22000,199
129+
127,pycma,500,8.40083719500035,1000,22000,199
130+
128,pycma,500,8.47234620999734,1000,22000,199
131+
129,pycma,500,8.808449586998904,1000,22000,199
132+
130,pycma,500,9.255677911998646,1000,22000,199
133+
131,pycma,500,8.432874996000464,1000,22000,199
134+
132,pycma,500,9.10525231200154,1000,22000,199
135+
133,pycma,500,9.15324209100072,1000,22000,199
136+
134,pycma,500,9.024118483001075,1000,22000,199
137+
135,pycma,1000,29.205384237000544,1000,24000,124
138+
136,pycma,1000,30.037788082001498,1000,24000,124
139+
137,pycma,1000,30.567731778999587,1000,24000,124
140+
138,pycma,1000,30.19753730500088,1000,24000,124
141+
139,pycma,1000,30.272570720997464,1000,24000,124
142+
140,pycma,1000,31.294434662999265,1000,24000,124
143+
141,pycma,1000,28.802552930003003,1000,24000,124
144+
142,pycma,1000,28.48719723999966,1000,24000,124
145+
143,pycma,1000,29.00229881999985,1000,24000,124
146+
144,pycma,1000,28.366859042002034,1000,24000,124
147+
145,pycma,1000,29.541915236000932,1000,24000,124
148+
146,pycma,1000,29.24515235400031,1000,24000,124
149+
147,pycma,1000,31.158946973999264,1000,24000,124
150+
148,pycma,1000,30.647990902998572,1000,24000,124
151+
149,pycma,1000,29.235625232999155,1000,24000,124

0 commit comments

Comments
 (0)