-
Notifications
You must be signed in to change notification settings - Fork 0
/
HOWTO_CMAES.txt
148 lines (127 loc) · 8.68 KB
/
HOWTO_CMAES.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import cma
es = cma.CMAEvolutionStrategy(8 * [0], 0.5)
f = cma.fitness_functions.FitnessFunctions()
es.optimize(f.rosen)
See "Example" here:
https://www.lri.fr/~hansen/html-pythoncma/
'''
From a python shell:
import cma
help(cma) # "this" help message, use cma? in ipython
help(cma.fmin) # !!! THIS IS REALLY IMPORTANT !!!
help(cma.CMAEvolutionStrategy)
help(cma.CMAOptions)
cma.CMAOptions('tol') # display 'tolerance' termination options
cma.CMAOptions('verb') # display verbosity options
res = cma.fmin(cma.Fcts.tablet, 15 * [1], 1)
res[0] # best evaluated solution
res[5] # mean solution, presumably better with noise
'''
Then navigate to "fun_as_arg()":
'''
fun_as_arg(self, x, *args)
source code
fun_as_arg(x, fun, *more_args) calls fun(x, *more_args).
Use case:
fmin(cma.fun_as_arg, args=(fun,), gradf=grad_numerical)
calls fun_as_args(x, args) and grad_numerical(x, fun, args=args)
'''
Use case:
>>> def fun2(a):
... return 5+a
...
>>>
>>> f = cma.fitness_functions.FitnessFunctions()
>>> f.fun_as_arg(2, fun2)
7
------------------------------------------------------------------------------------------------
sigma0=0.25, tol=0.01
(4_w,8)-aCMA-ES (mu_w=2.6,w_1=52%) in dimension 4 (seed=939799, Fri Dec 22 02:17:15 2017)
Iterat #Fevals function value axis ratio sigma min&max std t[m:s]
1 8 3.500322417719047e-01 1.0e+00 3.18e-01 3e-01 3e-01 0:00.0
2 16 3.196031798170505e-01 1.1e+00 3.42e-01 3e-01 3e-01 0:09.1
3 24 2.832826121112688e-01 1.3e+00 3.10e-01 3e-01 3e-01 0:12.6
4 32 2.802472681021081e-01 1.5e+00 2.72e-01 2e-01 2e-01 0:16.0
6 48 2.928869519282105e-01 2.0e+00 1.99e-01 2e-01 2e-01 0:21.5
11 88 2.768139756423783e-01 6.4e+00 9.25e-02 7e-02 8e-02 0:28.0
100 800 2.761423759686246e-01 3.5e+04 2.03e-04 3e-05 2e-04 0:29.3
141 1128 2.761423749168277e-01 1.1e+07 6.22e-05 1e-05 9e-05 0:29.3
termination on tolconditioncov=1e+14 (Fri Dec 22 02:18:25 2017)
final/bestever f-value = 2.761424e-01 2.761424e-01
incumbent solution: [0.7276294945685613, 0.27350932491377372, 0.77533716554721155, 0.2281513848511246]
std deviation: [1.3060258804087609e-05, 2.6013914932070593e-05, 8.0786370602097766e-05, 9.4144412517739015e-05]
(array([ 0.72763902, 0.27353999, 0.77524017, 0.22803988]), 0.27614237491576132, 1075, 1129, 141, array([ 0.72762949, 0.27350932, 0.77533717, 0.22815138]), array([ 1.30602588e-05, 2.60139149e-05, 8.07863706e-05,
9.41444125e-05]), {'tolconditioncov': 100000000000000.0}, <cma.evolution_strategy.CMAEvolutionStrategy object at 0x107183b50>, <cma.evolution_strategy.CMADataLogger object at 0x107183e50>)
------------------------------------------------------------------------------------------------
sigma0=0.25, tol=0.001
(4_w,8)-aCMA-ES (mu_w=2.6,w_1=52%) in dimension 4 (seed=1047727, Fri Dec 22 02:18:49 2017)
Iterat #Fevals function value axis ratio sigma min&max std t[m:s]
1 8 3.250835963366027e-01 1.0e+00 2.40e-01 2e-01 2e-01 0:00.0
2 16 2.984823229571308e-01 1.3e+00 2.31e-01 2e-01 2e-01 2:23.3
3 24 2.878675718773976e-01 1.7e+00 2.26e-01 2e-01 2e-01 4:55.4
4 32 2.994693152044203e-01 2.1e+00 1.88e-01 1e-01 2e-01 8:22.6
5 40 2.831535970953004e-01 2.5e+00 1.45e-01 1e-01 1e-01 10:30.8
6 48 2.777015008778650e-01 2.9e+00 1.13e-01 8e-02 1e-01 11:11.2
7 56 2.795974730034391e-01 3.8e+00 8.62e-02 6e-02 8e-02 11:48.6
8 64 2.762298215542731e-01 4.8e+00 7.17e-02 5e-02 6e-02 12:11.4
9 72 2.792677320685371e-01 5.5e+00 6.98e-02 4e-02 6e-02 12:22.2
11 88 2.786148733186379e-01 7.3e+00 5.56e-02 4e-02 5e-02 22:34.7
13 104 2.781823559451252e-01 1.1e+01 5.00e-02 3e-02 5e-02 22:47.4
15 120 2.763868201286991e-01 1.8e+01 3.76e-02 2e-02 3e-02 22:59.5
19 152 2.761552350772394e-01 3.9e+01 1.50e-02 9e-03 1e-02 23:11.9
100 800 2.761423819153085e-01 3.8e+03 2.21e-04 2e-05 2e-04 23:19.5
162 1296 2.761423749159235e-01 1.0e+07 3.19e-05 4e-06 5e-05 23:19.6
termination on tolconditioncov=1e+14 (Fri Dec 22 02:48:27 2017)
final/bestever f-value = 2.761424e-01 2.761424e-01
incumbent solution: [0.71243544586483187, 0.28781754636901119, 0.81329427467477489, 0.18590743910051594]
std deviation: [7.158756607735055e-06, 4.2391213853207211e-06, 4.7847343335560514e-05, 1.4485113607324111e-05]
(array([ 0.71242457, 0.28781772, 0.81336893, 0.18592246]), 0.27614237491541527, 1277, 1297, 162, array([ 0.71243545, 0.28781755, 0.81329427, 0.18590744]), array([ 7.15875661e-06, 4.23912139e-06, 4.78473433e-05,
1.44851136e-05]), {'tolconditioncov': 100000000000000.0}, <cma.evolution_strategy.CMAEvolutionStrategy object at 0x10eb46b50>, <cma.evolution_strategy.CMADataLogger object at 0x10eb46e50>)
------------------------------------------------------------------------------------------------
sigma0=0.25, tol=0.0001
------------------------------------------------------------------------------------------------
sigma0=0.25**n, tol=0.01, n=2
(4_w,8)-aCMA-ES (mu_w=2.6,w_1=52%) in dimension 4 (seed=1051983, Fri Dec 22 13:43:27 2017)
Iterat #Fevals function value axis ratio sigma min&max std t[m:s]
1 8 4.038010610708111e-01 1.0e+00 8.94e-02 9e-02 1e-01 0:00.0
2 16 3.427123213193233e-01 1.3e+00 1.32e-01 1e-01 1e-01 0:00.3
3 24 2.786134629361713e-01 1.7e+00 1.64e-01 2e-01 2e-01 0:01.0
6 48 2.981298009839579e-01 1.8e+00 1.43e-01 1e-01 1e-01 0:04.1
100 800 2.761423760024840e-01 9.6e+04 3.85e-04 1e-04 9e-04 0:06.4
145 1160 2.761423749159837e-01 1.0e+07 8.46e-06 2e-06 1e-05 0:06.4
termination on tolconditioncov=1e+14 (Fri Dec 22 13:43:36 2017)
final/bestever f-value = 2.761424e-01 2.761424e-01
incumbent solution: [0.77174158900652357, 0.23065911472598921, 0.64925068780935169, 0.34888387436634782]
std deviation: [3.9008310881607348e-06, 2.0025632383392527e-06, 1.3210891062223753e-05, 5.0797039275258416e-06]
(array([ 0.77174248, 0.23065668, 0.64924469, 0.34888954]), 0.27614237491541588, 1147, 1161, 145, array([ 0.77174159, 0.23065911, 0.64925069, 0.34888387]), array([ 3.90083109e-06, 2.00256324e-06, 1.32108911e-05,
5.07970393e-06]), {'tolconditioncov': 100000000000000.0}, <cma.evolution_strategy.CMAEvolutionStrategy object at 0x10e8edb10>, <cma.evolution_strategy.CMADataLogger object at 0x10e8ede10>)
------------------------------------------------------------------------------------------------
sigma0=0.25**n, tol=0.001, n=2
(4_w,8)-aCMA-ES (mu_w=2.6,w_1=52%) in dimension 4 (seed=1091654, Fri Dec 22 13:44:10 2017)
Iterat #Fevals function value axis ratio sigma min&max std t[m:s]
1 8 4.124053155409786e-01 1.0e+00 7.69e-02 8e-02 8e-02 0:00.0
2 16 3.973644265757525e-01 1.1e+00 9.95e-02 9e-02 1e-01 0:38.7
3 24 3.868154138609138e-01 1.4e+00 1.09e-01 1e-01 1e-01 1:06.6
4 32 3.384587448612649e-01 1.6e+00 1.32e-01 1e-01 1e-01 1:53.0
5 40 2.819492028823583e-01 1.7e+00 1.62e-01 1e-01 2e-01 2:46.3
6 48 2.937679928830934e-01 1.8e+00 1.49e-01 1e-01 1e-01 3:32.1
7 56 2.947445131753135e-01 1.8e+00 1.26e-01 1e-01 1e-01 4:33.3
8 64 3.018569180172939e-01 2.0e+00 1.06e-01 8e-02 9e-02 5:04.9
9 72 2.832109030744352e-01 2.7e+00 9.27e-02 7e-02 8e-02 5:36.1
10 80 2.773848518099069e-01 2.9e+00 7.93e-02 6e-02 6e-02 5:57.8
11 88 2.863160348175768e-01 3.1e+00 6.15e-02 5e-02 5e-02 6:40.4
13 104 2.845677257057336e-01 3.9e+00 4.67e-02 4e-02 4e-02 6:55.2
15 120 2.775003402883366e-01 5.7e+00 5.99e-02 5e-02 5e-02 7:11.2
16 128 2.781717960486955e-01 6.2e+00 4.86e-02 4e-02 4e-02 7:29.3
19 152 2.772421011876767e-01 1.1e+01 2.79e-02 2e-02 2e-02 7:45.7
25 200 2.762117001820991e-01 3.3e+01 1.26e-02 9e-03 1e-02 8:00.8
100 800 2.761423922340056e-01 4.9e+02 2.55e-04 4e-05 1e-04 8:04.0
174 1392 2.761423749154884e-01 1.4e+06 1.02e-06 1e-07 3e-07 8:04.1
termination on tolfun=1e-11 (Fri Dec 22 13:54:56 2017)
final/bestever f-value = 2.761424e-01 2.761424e-01
incumbent solution: [0.75419352992560695, 0.24547484690698584, 0.69405372863506443, 0.30527086350445298]
std deviation: [1.0543526246316499e-07, 1.0258169479987852e-07, 3.0340553532847699e-07, 2.9452168628692865e-07]
(array([ 0.75419363, 0.24547492, 0.69405347, 0.30527068]), 0.27614237491539995, 1307, 1393, 174, array([ 0.75419353, 0.24547485, 0.69405373, 0.30527086]), array([ 1.05435262e-07, 1.02581695e-07, 3.03405535e-07,
2.94521686e-07]), {'tolfun': 1e-11}, <cma.evolution_strategy.CMAEvolutionStrategy object at 0x111b51b10>, <cma.evolution_strategy.CMADataLogger object at 0x111b51e10>)
------------------------------------------------------------------------------------------------
sigma0=0.25**n, tol=0.0001, n=2