pymoo 0.6.1.6__cp312-cp312-macosx_10_13_universal2.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (337) hide show
  1. pymoo/__init__.py +3 -0
  2. pymoo/algorithms/__init__.py +0 -0
  3. pymoo/algorithms/base/__init__.py +0 -0
  4. pymoo/algorithms/base/bracket.py +38 -0
  5. pymoo/algorithms/base/genetic.py +110 -0
  6. pymoo/algorithms/base/line.py +62 -0
  7. pymoo/algorithms/base/local.py +39 -0
  8. pymoo/algorithms/base/meta.py +79 -0
  9. pymoo/algorithms/hyperparameters.py +91 -0
  10. pymoo/algorithms/moo/__init__.py +0 -0
  11. pymoo/algorithms/moo/age.py +310 -0
  12. pymoo/algorithms/moo/age2.py +194 -0
  13. pymoo/algorithms/moo/cmopso.py +239 -0
  14. pymoo/algorithms/moo/ctaea.py +305 -0
  15. pymoo/algorithms/moo/dnsga2.py +80 -0
  16. pymoo/algorithms/moo/kgb.py +450 -0
  17. pymoo/algorithms/moo/moead.py +183 -0
  18. pymoo/algorithms/moo/mopso_cd.py +309 -0
  19. pymoo/algorithms/moo/nsga2.py +113 -0
  20. pymoo/algorithms/moo/nsga3.py +361 -0
  21. pymoo/algorithms/moo/pinsga2.py +370 -0
  22. pymoo/algorithms/moo/rnsga2.py +188 -0
  23. pymoo/algorithms/moo/rnsga3.py +246 -0
  24. pymoo/algorithms/moo/rvea.py +214 -0
  25. pymoo/algorithms/moo/sms.py +196 -0
  26. pymoo/algorithms/moo/spea2.py +191 -0
  27. pymoo/algorithms/moo/unsga3.py +49 -0
  28. pymoo/algorithms/soo/__init__.py +0 -0
  29. pymoo/algorithms/soo/convex/__init__.py +0 -0
  30. pymoo/algorithms/soo/nonconvex/__init__.py +0 -0
  31. pymoo/algorithms/soo/nonconvex/brkga.py +162 -0
  32. pymoo/algorithms/soo/nonconvex/cmaes.py +556 -0
  33. pymoo/algorithms/soo/nonconvex/de.py +283 -0
  34. pymoo/algorithms/soo/nonconvex/direct.py +148 -0
  35. pymoo/algorithms/soo/nonconvex/es.py +213 -0
  36. pymoo/algorithms/soo/nonconvex/g3pcx.py +94 -0
  37. pymoo/algorithms/soo/nonconvex/ga.py +95 -0
  38. pymoo/algorithms/soo/nonconvex/ga_niching.py +223 -0
  39. pymoo/algorithms/soo/nonconvex/isres.py +74 -0
  40. pymoo/algorithms/soo/nonconvex/nelder.py +251 -0
  41. pymoo/algorithms/soo/nonconvex/nrbo.py +191 -0
  42. pymoo/algorithms/soo/nonconvex/optuna.py +80 -0
  43. pymoo/algorithms/soo/nonconvex/pattern.py +185 -0
  44. pymoo/algorithms/soo/nonconvex/pso.py +337 -0
  45. pymoo/algorithms/soo/nonconvex/pso_ep.py +307 -0
  46. pymoo/algorithms/soo/nonconvex/random_search.py +25 -0
  47. pymoo/algorithms/soo/nonconvex/sres.py +56 -0
  48. pymoo/algorithms/soo/univariate/__init__.py +0 -0
  49. pymoo/algorithms/soo/univariate/exp.py +46 -0
  50. pymoo/algorithms/soo/univariate/golden.py +65 -0
  51. pymoo/algorithms/soo/univariate/quadr_interp.py +81 -0
  52. pymoo/algorithms/soo/univariate/wolfe.py +163 -0
  53. pymoo/config.py +33 -0
  54. pymoo/constraints/__init__.py +3 -0
  55. pymoo/constraints/adaptive.py +66 -0
  56. pymoo/constraints/as_obj.py +56 -0
  57. pymoo/constraints/as_penalty.py +41 -0
  58. pymoo/constraints/eps.py +34 -0
  59. pymoo/constraints/from_bounds.py +36 -0
  60. pymoo/core/__init__.py +0 -0
  61. pymoo/core/algorithm.py +408 -0
  62. pymoo/core/callback.py +38 -0
  63. pymoo/core/crossover.py +79 -0
  64. pymoo/core/decision_making.py +102 -0
  65. pymoo/core/decomposition.py +76 -0
  66. pymoo/core/duplicate.py +163 -0
  67. pymoo/core/evaluator.py +116 -0
  68. pymoo/core/indicator.py +34 -0
  69. pymoo/core/individual.py +784 -0
  70. pymoo/core/infill.py +65 -0
  71. pymoo/core/initialization.py +44 -0
  72. pymoo/core/mating.py +39 -0
  73. pymoo/core/meta.py +21 -0
  74. pymoo/core/mixed.py +164 -0
  75. pymoo/core/mutation.py +44 -0
  76. pymoo/core/operator.py +46 -0
  77. pymoo/core/parameters.py +134 -0
  78. pymoo/core/plot.py +208 -0
  79. pymoo/core/population.py +180 -0
  80. pymoo/core/problem.py +373 -0
  81. pymoo/core/recorder.py +99 -0
  82. pymoo/core/repair.py +23 -0
  83. pymoo/core/replacement.py +96 -0
  84. pymoo/core/result.py +52 -0
  85. pymoo/core/sampling.py +45 -0
  86. pymoo/core/selection.py +61 -0
  87. pymoo/core/solution.py +10 -0
  88. pymoo/core/survival.py +107 -0
  89. pymoo/core/termination.py +70 -0
  90. pymoo/core/variable.py +415 -0
  91. pymoo/decomposition/__init__.py +0 -0
  92. pymoo/decomposition/aasf.py +24 -0
  93. pymoo/decomposition/asf.py +10 -0
  94. pymoo/decomposition/pbi.py +13 -0
  95. pymoo/decomposition/perp_dist.py +13 -0
  96. pymoo/decomposition/tchebicheff.py +11 -0
  97. pymoo/decomposition/util.py +13 -0
  98. pymoo/decomposition/weighted_sum.py +8 -0
  99. pymoo/docs.py +187 -0
  100. pymoo/experimental/__init__.py +0 -0
  101. pymoo/experimental/algorithms/__init__.py +0 -0
  102. pymoo/experimental/algorithms/gde3.py +57 -0
  103. pymoo/functions/__init__.py +135 -0
  104. pymoo/functions/compiled/__init__.py +0 -0
  105. pymoo/functions/compiled/calc_perpendicular_distance.cpp +27464 -0
  106. pymoo/functions/compiled/calc_perpendicular_distance.cpython-312-darwin.so +0 -0
  107. pymoo/functions/compiled/decomposition.cpp +28853 -0
  108. pymoo/functions/compiled/decomposition.cpython-312-darwin.so +0 -0
  109. pymoo/functions/compiled/info.cpp +7058 -0
  110. pymoo/functions/compiled/info.cpython-312-darwin.so +0 -0
  111. pymoo/functions/compiled/mnn.cpp +30095 -0
  112. pymoo/functions/compiled/mnn.cpython-312-darwin.so +0 -0
  113. pymoo/functions/compiled/non_dominated_sorting.cpp +35692 -0
  114. pymoo/functions/compiled/non_dominated_sorting.cpython-312-darwin.so +0 -0
  115. pymoo/functions/compiled/pruning_cd.cpp +29248 -0
  116. pymoo/functions/compiled/pruning_cd.cpython-312-darwin.so +0 -0
  117. pymoo/functions/compiled/stochastic_ranking.cpp +28042 -0
  118. pymoo/functions/compiled/stochastic_ranking.cpython-312-darwin.so +0 -0
  119. pymoo/functions/standard/__init__.py +1 -0
  120. pymoo/functions/standard/calc_perpendicular_distance.py +20 -0
  121. pymoo/functions/standard/decomposition.py +18 -0
  122. pymoo/functions/standard/hv.py +5 -0
  123. pymoo/functions/standard/mnn.py +78 -0
  124. pymoo/functions/standard/non_dominated_sorting.py +474 -0
  125. pymoo/functions/standard/pruning_cd.py +93 -0
  126. pymoo/functions/standard/stochastic_ranking.py +42 -0
  127. pymoo/gradient/__init__.py +24 -0
  128. pymoo/gradient/automatic.py +85 -0
  129. pymoo/gradient/grad_autograd.py +105 -0
  130. pymoo/gradient/grad_complex.py +35 -0
  131. pymoo/gradient/grad_jax.py +51 -0
  132. pymoo/gradient/numpy.py +22 -0
  133. pymoo/gradient/toolbox/__init__.py +19 -0
  134. pymoo/indicators/__init__.py +0 -0
  135. pymoo/indicators/distance_indicator.py +55 -0
  136. pymoo/indicators/gd.py +7 -0
  137. pymoo/indicators/gd_plus.py +7 -0
  138. pymoo/indicators/hv/__init__.py +59 -0
  139. pymoo/indicators/hv/approximate.py +105 -0
  140. pymoo/indicators/hv/exact.py +68 -0
  141. pymoo/indicators/hv/exact_2d.py +102 -0
  142. pymoo/indicators/igd.py +7 -0
  143. pymoo/indicators/igd_plus.py +7 -0
  144. pymoo/indicators/kktpm.py +151 -0
  145. pymoo/indicators/migd.py +55 -0
  146. pymoo/indicators/rmetric.py +203 -0
  147. pymoo/indicators/spacing.py +52 -0
  148. pymoo/mcdm/__init__.py +0 -0
  149. pymoo/mcdm/compromise_programming.py +19 -0
  150. pymoo/mcdm/high_tradeoff.py +40 -0
  151. pymoo/mcdm/pseudo_weights.py +32 -0
  152. pymoo/operators/__init__.py +0 -0
  153. pymoo/operators/control.py +190 -0
  154. pymoo/operators/crossover/__init__.py +0 -0
  155. pymoo/operators/crossover/binx.py +47 -0
  156. pymoo/operators/crossover/dex.py +125 -0
  157. pymoo/operators/crossover/erx.py +164 -0
  158. pymoo/operators/crossover/expx.py +53 -0
  159. pymoo/operators/crossover/hux.py +37 -0
  160. pymoo/operators/crossover/nox.py +25 -0
  161. pymoo/operators/crossover/ox.py +88 -0
  162. pymoo/operators/crossover/pcx.py +84 -0
  163. pymoo/operators/crossover/pntx.py +49 -0
  164. pymoo/operators/crossover/sbx.py +137 -0
  165. pymoo/operators/crossover/spx.py +5 -0
  166. pymoo/operators/crossover/ux.py +20 -0
  167. pymoo/operators/mutation/__init__.py +0 -0
  168. pymoo/operators/mutation/bitflip.py +17 -0
  169. pymoo/operators/mutation/gauss.py +60 -0
  170. pymoo/operators/mutation/inversion.py +42 -0
  171. pymoo/operators/mutation/nom.py +7 -0
  172. pymoo/operators/mutation/pm.py +96 -0
  173. pymoo/operators/mutation/rm.py +23 -0
  174. pymoo/operators/repair/__init__.py +0 -0
  175. pymoo/operators/repair/bounce_back.py +32 -0
  176. pymoo/operators/repair/bounds_repair.py +97 -0
  177. pymoo/operators/repair/inverse_penalty.py +91 -0
  178. pymoo/operators/repair/rounding.py +18 -0
  179. pymoo/operators/repair/to_bound.py +31 -0
  180. pymoo/operators/repair/vtype.py +11 -0
  181. pymoo/operators/sampling/__init__.py +0 -0
  182. pymoo/operators/sampling/lhs.py +76 -0
  183. pymoo/operators/sampling/rnd.py +52 -0
  184. pymoo/operators/selection/__init__.py +0 -0
  185. pymoo/operators/selection/rnd.py +75 -0
  186. pymoo/operators/selection/tournament.py +78 -0
  187. pymoo/operators/survival/__init__.py +0 -0
  188. pymoo/operators/survival/rank_and_crowding/__init__.py +1 -0
  189. pymoo/operators/survival/rank_and_crowding/classes.py +212 -0
  190. pymoo/operators/survival/rank_and_crowding/metrics.py +208 -0
  191. pymoo/optimize.py +72 -0
  192. pymoo/parallelization/__init__.py +15 -0
  193. pymoo/parallelization/dask.py +25 -0
  194. pymoo/parallelization/joblib.py +28 -0
  195. pymoo/parallelization/ray.py +31 -0
  196. pymoo/parallelization/starmap.py +24 -0
  197. pymoo/problems/__init__.py +157 -0
  198. pymoo/problems/dyn.py +47 -0
  199. pymoo/problems/dynamic/__init__.py +0 -0
  200. pymoo/problems/dynamic/cec2015.py +108 -0
  201. pymoo/problems/dynamic/df.py +451 -0
  202. pymoo/problems/dynamic/misc.py +167 -0
  203. pymoo/problems/functional.py +48 -0
  204. pymoo/problems/many/__init__.py +5 -0
  205. pymoo/problems/many/cdtlz.py +159 -0
  206. pymoo/problems/many/dcdtlz.py +88 -0
  207. pymoo/problems/many/dtlz.py +264 -0
  208. pymoo/problems/many/wfg.py +553 -0
  209. pymoo/problems/multi/__init__.py +14 -0
  210. pymoo/problems/multi/bnh.py +34 -0
  211. pymoo/problems/multi/carside.py +48 -0
  212. pymoo/problems/multi/clutch.py +104 -0
  213. pymoo/problems/multi/csi.py +55 -0
  214. pymoo/problems/multi/ctp.py +198 -0
  215. pymoo/problems/multi/dascmop.py +213 -0
  216. pymoo/problems/multi/kursawe.py +25 -0
  217. pymoo/problems/multi/modact.py +68 -0
  218. pymoo/problems/multi/mw.py +400 -0
  219. pymoo/problems/multi/omnitest.py +48 -0
  220. pymoo/problems/multi/osy.py +32 -0
  221. pymoo/problems/multi/srn.py +28 -0
  222. pymoo/problems/multi/sympart.py +94 -0
  223. pymoo/problems/multi/tnk.py +24 -0
  224. pymoo/problems/multi/truss2d.py +83 -0
  225. pymoo/problems/multi/welded_beam.py +41 -0
  226. pymoo/problems/multi/wrm.py +36 -0
  227. pymoo/problems/multi/zdt.py +151 -0
  228. pymoo/problems/multi_to_single.py +22 -0
  229. pymoo/problems/single/__init__.py +12 -0
  230. pymoo/problems/single/ackley.py +24 -0
  231. pymoo/problems/single/cantilevered_beam.py +34 -0
  232. pymoo/problems/single/flowshop_scheduling.py +113 -0
  233. pymoo/problems/single/g.py +874 -0
  234. pymoo/problems/single/griewank.py +18 -0
  235. pymoo/problems/single/himmelblau.py +15 -0
  236. pymoo/problems/single/knapsack.py +49 -0
  237. pymoo/problems/single/mopta08.py +26 -0
  238. pymoo/problems/single/multimodal.py +20 -0
  239. pymoo/problems/single/pressure_vessel.py +30 -0
  240. pymoo/problems/single/rastrigin.py +20 -0
  241. pymoo/problems/single/rosenbrock.py +22 -0
  242. pymoo/problems/single/schwefel.py +18 -0
  243. pymoo/problems/single/simple.py +13 -0
  244. pymoo/problems/single/sphere.py +19 -0
  245. pymoo/problems/single/traveling_salesman.py +79 -0
  246. pymoo/problems/single/zakharov.py +19 -0
  247. pymoo/problems/static.py +14 -0
  248. pymoo/problems/util.py +42 -0
  249. pymoo/problems/zero_to_one.py +27 -0
  250. pymoo/termination/__init__.py +23 -0
  251. pymoo/termination/collection.py +12 -0
  252. pymoo/termination/cv.py +48 -0
  253. pymoo/termination/default.py +45 -0
  254. pymoo/termination/delta.py +64 -0
  255. pymoo/termination/fmin.py +16 -0
  256. pymoo/termination/ftol.py +144 -0
  257. pymoo/termination/indicator.py +49 -0
  258. pymoo/termination/max_eval.py +14 -0
  259. pymoo/termination/max_gen.py +15 -0
  260. pymoo/termination/max_time.py +20 -0
  261. pymoo/termination/robust.py +34 -0
  262. pymoo/termination/xtol.py +33 -0
  263. pymoo/util/__init__.py +33 -0
  264. pymoo/util/archive.py +152 -0
  265. pymoo/util/cache.py +29 -0
  266. pymoo/util/clearing.py +82 -0
  267. pymoo/util/display/__init__.py +0 -0
  268. pymoo/util/display/column.py +52 -0
  269. pymoo/util/display/display.py +34 -0
  270. pymoo/util/display/multi.py +100 -0
  271. pymoo/util/display/output.py +53 -0
  272. pymoo/util/display/progress.py +54 -0
  273. pymoo/util/display/single.py +67 -0
  274. pymoo/util/dominator.py +67 -0
  275. pymoo/util/hv.py +21 -0
  276. pymoo/util/matlab_engine.py +39 -0
  277. pymoo/util/misc.py +447 -0
  278. pymoo/util/nds/__init__.py +0 -0
  279. pymoo/util/nds/dominance_degree_non_dominated_sort.py +159 -0
  280. pymoo/util/nds/efficient_non_dominated_sort.py +152 -0
  281. pymoo/util/nds/fast_non_dominated_sort.py +70 -0
  282. pymoo/util/nds/find_non_dominated.py +54 -0
  283. pymoo/util/nds/naive_non_dominated_sort.py +36 -0
  284. pymoo/util/nds/non_dominated_sorting.py +94 -0
  285. pymoo/util/nds/tree_based_non_dominated_sort.py +133 -0
  286. pymoo/util/normalization.py +312 -0
  287. pymoo/util/optimum.py +42 -0
  288. pymoo/util/randomized_argsort.py +63 -0
  289. pymoo/util/ref_dirs/__init__.py +24 -0
  290. pymoo/util/ref_dirs/construction.py +89 -0
  291. pymoo/util/ref_dirs/das_dennis.py +52 -0
  292. pymoo/util/ref_dirs/energy.py +317 -0
  293. pymoo/util/ref_dirs/energy_layer.py +119 -0
  294. pymoo/util/ref_dirs/genetic_algorithm.py +64 -0
  295. pymoo/util/ref_dirs/incremental.py +69 -0
  296. pymoo/util/ref_dirs/misc.py +128 -0
  297. pymoo/util/ref_dirs/optimizer.py +59 -0
  298. pymoo/util/ref_dirs/performance.py +162 -0
  299. pymoo/util/ref_dirs/reduction.py +85 -0
  300. pymoo/util/ref_dirs/sample_and_map.py +24 -0
  301. pymoo/util/reference_direction.py +258 -0
  302. pymoo/util/remote.py +55 -0
  303. pymoo/util/roulette.py +29 -0
  304. pymoo/util/running_metric.py +128 -0
  305. pymoo/util/sliding_window.py +25 -0
  306. pymoo/util/value_functions.py +720 -0
  307. pymoo/util/vectors.py +40 -0
  308. pymoo/util/vf_dominator.py +102 -0
  309. pymoo/vendor/__init__.py +0 -0
  310. pymoo/vendor/cec2018.py +398 -0
  311. pymoo/vendor/gta.py +617 -0
  312. pymoo/vendor/vendor_cmaes.py +421 -0
  313. pymoo/vendor/vendor_coco.py +81 -0
  314. pymoo/vendor/vendor_scipy.py +232 -0
  315. pymoo/version.py +1 -0
  316. pymoo/visualization/__init__.py +21 -0
  317. pymoo/visualization/app/__init__.py +0 -0
  318. pymoo/visualization/app/pso.py +61 -0
  319. pymoo/visualization/fitness_landscape.py +128 -0
  320. pymoo/visualization/heatmap.py +123 -0
  321. pymoo/visualization/matplotlib.py +61 -0
  322. pymoo/visualization/pcp.py +121 -0
  323. pymoo/visualization/petal.py +91 -0
  324. pymoo/visualization/radar.py +108 -0
  325. pymoo/visualization/radviz.py +68 -0
  326. pymoo/visualization/scatter.py +150 -0
  327. pymoo/visualization/star_coordinate.py +75 -0
  328. pymoo/visualization/util.py +296 -0
  329. pymoo/visualization/video/__init__.py +0 -0
  330. pymoo/visualization/video/callback_video.py +82 -0
  331. pymoo/visualization/video/one_var_one_obj.py +57 -0
  332. pymoo/visualization/video/two_var_one_obj.py +62 -0
  333. pymoo-0.6.1.6.dist-info/METADATA +209 -0
  334. pymoo-0.6.1.6.dist-info/RECORD +337 -0
  335. pymoo-0.6.1.6.dist-info/WHEEL +6 -0
  336. pymoo-0.6.1.6.dist-info/licenses/LICENSE +191 -0
  337. pymoo-0.6.1.6.dist-info/top_level.txt +1 -0
@@ -0,0 +1,556 @@
1
+ import cma
2
+ import numpy as np
3
+
4
+ from pymoo.algorithms.base.local import LocalSearch
5
+ from pymoo.core.population import Population
6
+ from pymoo.core.termination import NoTermination
7
+ from pymoo.docs import parse_doc_string
8
+ from pymoo.termination.max_eval import MaximumFunctionCallTermination
9
+ from pymoo.termination.max_gen import MaximumGenerationTermination
10
+ from pymoo.util.display.column import Column
11
+ from pymoo.util.display.single import SingleObjectiveOutput
12
+ from pymoo.util.normalization import ZeroToOneNormalization, NoNormalization
13
+ from pymoo.util.optimum import filter_optimum
14
+ from pymoo.vendor.vendor_cmaes import my_fmin
15
+
16
+
17
+ # =========================================================================================================
18
+ # Implementation
19
+ # =========================================================================================================
20
+
21
+
22
+ class CMAESOutput(SingleObjectiveOutput):
23
+
24
+ def __init__(self):
25
+ super().__init__()
26
+
27
+ self.sigma = Column("sigma")
28
+ self.min_std = Column("min_std", width=8)
29
+ self.max_std = Column("max_std", width=8)
30
+ self.axis = Column("axis", width=8)
31
+
32
+ self.run = Column("run", width=4)
33
+ self.fpop = Column("fpop", width=8)
34
+ self.n_pop = Column("n_pop", width=5)
35
+
36
+ def initialize(self, algorithm):
37
+ super().initialize(algorithm)
38
+
39
+ if algorithm.restarts > 0:
40
+ self.columns += [self.run, self.fpop, self.n_pop]
41
+
42
+ self.columns += [self.sigma, self.min_std, self.max_std, self.axis]
43
+
44
+ def update(self, algorithm):
45
+ super().update(algorithm)
46
+
47
+ if not algorithm.es.gi_frame:
48
+ return
49
+
50
+ fmin = algorithm.es.gi_frame.f_locals
51
+ cma = fmin["es"]
52
+
53
+ self.sigma.set(cma.sigma)
54
+
55
+ val = cma.sigma_vec * cma.dC ** 0.5
56
+ self.min_std.set((cma.sigma * min(val)))
57
+ self.max_std.set((cma.sigma * max(val)))
58
+
59
+ if algorithm.restarts > 0:
60
+ self.run.set(int(fmin["irun"] - fmin["runs_with_small"]) + 1)
61
+ self.fpop.set(algorithm.pop.get("F").min())
62
+ self.n_pop.set(int(cma.opts['popsize']))
63
+
64
+ axis = (cma.D.max() / cma.D.min()
65
+ if not cma.opts['CMA_diagonal'] or cma.countiter > cma.opts['CMA_diagonal']
66
+ else max(cma.sigma_vec * 1) / min(cma.sigma_vec * 1))
67
+ self.axis.set(axis)
68
+
69
+
70
+ class CMAES(LocalSearch):
71
+
72
+ def __init__(self,
73
+ x0=None,
74
+ sigma=0.1,
75
+ normalize=True,
76
+ parallelize=True,
77
+ maxfevals=np.inf,
78
+ tolfun=1e-11,
79
+ tolx=1e-11,
80
+ restarts=0,
81
+ restart_from_best='False',
82
+ incpopsize=2,
83
+ eval_initial_x=False,
84
+ noise_handler=None,
85
+ noise_change_sigma_exponent=1,
86
+ noise_kappa_exponent=0,
87
+ bipop=False,
88
+ cmaes_verbose=-9,
89
+ verb_log=0,
90
+ output=CMAESOutput(),
91
+ pop_size=None,
92
+ **kwargs
93
+ ):
94
+ """
95
+
96
+
97
+ Parameters
98
+ ----------
99
+
100
+ x0 : list or `numpy.ndarray`
101
+ initial guess of minimum solution
102
+ before the application of the geno-phenotype transformation
103
+ according to the ``transformation`` option. It can also be
104
+ a string holding a Python expression that is evaluated
105
+ to yield the initial guess - this is important in case
106
+ restarts are performed so that they start from different
107
+ places. Otherwise ``x0`` can also be a `cma.CMAEvolutionStrategy`
108
+ object instance, in that case ``sigma0`` can be ``None``.
109
+
110
+ sigma : float
111
+ Initial standard deviation in each coordinate.
112
+ ``sigma0`` should be about 1/4th of the search domain width
113
+ (where the optimum is to be expected). The variables in
114
+ ``objective_function`` should be scaled such that they
115
+ presumably have similar sensitivity.
116
+ See also `ScaleCoordinates`.
117
+
118
+ parallelize : bool
119
+ Whether the objective function should be called for each single evaluation or batch wise.
120
+
121
+ restarts : int, default 0
122
+ Number of restarts with increasing population size, see also
123
+ parameter ``incpopsize``, implementing the IPOP-CMA-ES restart
124
+ strategy, see also parameter ``bipop``; to restart from
125
+ different points (recommended), pass ``x0`` as a string.
126
+
127
+ restart_from_best : bool, default false
128
+ Which point to restart from
129
+
130
+ incpopsize : int
131
+ Multiplier for increasing the population size ``popsize`` before each restart
132
+
133
+ eval_initial_x : bool
134
+ Evaluate initial solution, for ``None`` only with elitist option
135
+
136
+ noise_handler : class
137
+ A ``NoiseHandler`` class or instance or ``None``. Example:
138
+ ``cma.fmin(f, 6 * [1], 1, noise_handler=cma.NoiseHandler(6))``
139
+ see ``help(cma.NoiseHandler)``.
140
+
141
+ noise_change_sigma_exponent : int
142
+ Exponent for the sigma increment provided by the noise handler for
143
+ additional noise treatment. 0 means no sigma change.
144
+
145
+ noise_kappa_exponent : int
146
+ Instead of applying reevaluations, the "number of evaluations"
147
+ is (ab)used as init_simplex_scale factor kappa (experimental).
148
+
149
+ bipop : bool
150
+ If `True`, run as BIPOP-CMA-ES; BIPOP is a special restart
151
+ strategy switching between two population sizings - small
152
+ (like the default CMA, but with more focused search) and
153
+ large (progressively increased as in IPOP). This makes the
154
+ algorithm perform well both on functions with many regularly
155
+ or irregularly arranged local optima (the latter by frequently
156
+ restarting with small populations). For the `bipop` parameter
157
+ to actually take effect, also select non-zero number of
158
+ (IPOP) restarts; the recommended setting is ``restarts<=9``
159
+ and `x0` passed as a string using `numpy.rand` to generate
160
+ initial solutions. Note that small-population restarts
161
+ do not count into the total restart count.
162
+
163
+ AdaptSigma : True
164
+ Or False or any CMAAdaptSigmaBase class e.g. CMAAdaptSigmaTPA, CMAAdaptSigmaCSA
165
+
166
+ CMA_active : True
167
+ Negative update, conducted after the original update
168
+
169
+ CMA_activefac : 1
170
+ Learning rate multiplier for active update
171
+
172
+ CMA_cmean : 1
173
+ Learning rate for the mean value
174
+
175
+ CMA_const_trace : False
176
+ Normalize trace, 1, True, "arithm", "geom", "aeig", "geig" are valid
177
+
178
+ CMA_diagonal : 0*100*N/popsize**0.5
179
+ Number of iterations with diagonal covariance matrix, True for always
180
+
181
+ CMA_eigenmethod : np.linalg.eigh or cma.utilities.math.eig or pygsl.eigen.eigenvectors
182
+
183
+ CMA_elitist : False or "initial" or True
184
+ Elitism likely impairs global search performance
185
+
186
+ CMA_injections_threshold_keep_len : 0
187
+ Keep length if Mahalanobis length is below the given relative threshold
188
+
189
+ CMA_mirrors : popsize < 6
190
+ Values <0.5 are interpreted as fraction, values >1 as numbers (rounded), otherwise about 0.16 is used
191
+
192
+ CMA_mirrormethod : int, default 2, 0=unconditional, 1=selective, 2=selective with delay
193
+
194
+ CMA_mu : None
195
+ Parents selection parameter, default is popsize // 2
196
+
197
+ CMA_on : 1
198
+ Multiplier for all covariance matrix updates
199
+
200
+ CMA_sampler : None
201
+ A class or instance that implements the interface of
202
+ `cma.interfaces.StatisticalModelSamplerWithZeroMeanBaseClass`
203
+
204
+ CMA_sampler_options : dict
205
+ Options passed to `CMA_sampler` class init as keyword arguments
206
+
207
+ CMA_rankmu : 1.0
208
+ Multiplier for rank-mu update learning rate of covariance matrix
209
+
210
+ CMA_rankone : 1.0
211
+ Multiplier for rank-one update learning rate of covariance matrix
212
+
213
+ CMA_recombination_weights : None
214
+ A list, see class RecombinationWeights, overwrites CMA_mu and popsize options
215
+
216
+ CMA_dampsvec_fac : np.Inf
217
+ Tentative and subject to changes, 0.5 would be a "default" damping for sigma vector update
218
+
219
+ CMA_dampsvec_fade : 0.1
220
+ Tentative fading out parameter for sigma vector update
221
+
222
+ CMA_teststds : None
223
+ Factors for non-isotropic initial distr. of C, mainly for test purpose, see CMA_stds for production
224
+
225
+ CMA_stds : None
226
+ Multipliers for sigma0 in each coordinate, not represented in C,
227
+ makes scaling_of_variables obsolete
228
+
229
+ CSA_dampfac : 1
230
+ Positive multiplier for step-size damping, 0.3 is close to optimal on the sphere
231
+
232
+ CSA_damp_mueff_exponent : 0.5
233
+ Zero would mean no dependency of damping on mueff, useful with CSA_disregard_length option
234
+
235
+ CSA_disregard_length : False
236
+ True is untested, also changes respective parameters
237
+
238
+ CSA_clip_length_value : None
239
+ Poorly tested, [0, 0] means const length N**0.5, [-1, 1] allows a variation of +- N/(N+2), etc.
240
+
241
+ CSA_squared : False
242
+ Use squared length for sigma-adaptation ',
243
+
244
+ BoundaryHandler : BoundTransform or BoundPenalty, unused when ``bounds in (None, [None, None])``
245
+
246
+ conditioncov_alleviate : [1e8, 1e12]
247
+ When to alleviate the condition in the coordinates and in main axes
248
+
249
+ eval_final_mean : True
250
+ Evaluate the final mean, which is a favorite return candidate
251
+
252
+ fixed_variables : None
253
+ Dictionary with index-value pairs like dict(0=1.1, 2=0.1) that are not optimized
254
+
255
+ ftarget : -inf
256
+ Target function value, minimization
257
+
258
+ integer_variables : []
259
+ Index list, invokes basic integer handling: prevent std dev to become too small in the given variables
260
+
261
+ maxfevals : inf
262
+ Maximum number of function evaluations
263
+
264
+ maxiter : 100 + 150 * (N+3)**2 // popsize**0.5
265
+ Maximum number of iterations
266
+
267
+ mean_shift_line_samples : False
268
+ Sample two new solutions colinear to previous mean shift
269
+
270
+ mindx : 0
271
+ Minimal std in any arbitrary direction, cave interference with tol
272
+
273
+ minstd : 0
274
+ Minimal std (scalar or vector) in any coordinate direction, cave interference with tol
275
+
276
+ maxstd : inf
277
+ Maximal std in any coordinate direction
278
+
279
+ pc_line_samples : False
280
+ One line sample along the evolution path pc
281
+
282
+ popsize : 4+int(3*np.log(N))
283
+ Population size, AKA lambda, number of new solution per iteration
284
+
285
+ randn
286
+ Randn(lam, N) must return an np.array of shape (lam, N), see also cma.utilities.math.randhss
287
+
288
+ signals_filename : None
289
+ cma_signals.in # read versatile options from this file which contains a single options dict,
290
+ e.g. ``dict("timeout"=0)`` to stop, string-values are evaluated, e.g. "np.inf" is valid
291
+
292
+ termination_callback : None
293
+ A function returning True for termination, called in `stop` with `self` as argument, could be abused
294
+ for side effects
295
+
296
+ timeout : inf
297
+ Stop if timeout seconds are exceeded, the string "2.5 * 60**2" evaluates to 2 hours and 30 minutes
298
+
299
+ tolconditioncov : 1e14
300
+ Stop if the condition of the covariance matrix is above `tolconditioncov`
301
+
302
+ tolfacupx : 1e3
303
+ Termination when step-size increases by tolfacupx (diverges). That is, the initial step-size was chosen
304
+ far too small and better solutions were found far away from the initial solution x0
305
+
306
+ tolupsigma : 1e20
307
+ Sigma/sigma0 > tolupsigma * max(eivenvals(C)**0.5) indicates "creeping behavior" with usually minor
308
+ improvements
309
+
310
+ tolfun : 1e-11
311
+ Termination criterion: tolerance in function value, quite useful
312
+
313
+ tolfunhist : 1e-12
314
+ Termination criterion: tolerance in function value history
315
+
316
+ tolstagnation : int(100 + 100 * N**1.5 / popsize)
317
+ Termination if no improvement over tolstagnation iterations
318
+
319
+ tolx : 1e-11
320
+ Termination criterion: tolerance in x-changes
321
+
322
+ typical_x : None
323
+ Used with scaling_of_variables',
324
+
325
+ updatecovwait : None
326
+ Number of iterations without distribution update, name is subject to future changes
327
+
328
+ cmaes_verbose : 3
329
+ Verbosity e.g. of initial/final message, -1 is very quiet, -9 maximally quiet, may not be fully implemented
330
+
331
+ verb_append : 0
332
+ Initial evaluation counter, if append, do not overwrite output files
333
+
334
+ verb_disp : 100
335
+ Verbosity: display console output every verb_disp iteration
336
+
337
+ verb_filenameprefix : str
338
+ CMADataLogger.default_prefix + Output path and filenames prefix
339
+
340
+ verb_log : 1
341
+ Verbosity: write data to files every verb_log iteration, writing can be time critical on fast to
342
+ evaluate functions
343
+
344
+ verb_plot : 0
345
+ In fmin(): plot() is called every verb_plot iteration
346
+
347
+ verb_time : True
348
+ Output timings on console
349
+
350
+ vv : dict
351
+ Versatile set or dictionary for hacking purposes, value found in self.opts["vv"]
352
+
353
+ kwargs : dict
354
+ A dictionary with additional options passed to the constructor
355
+ of class ``CMAEvolutionStrategy``, see ``cma.CMAOptions`` ()
356
+ for a list of available options.
357
+
358
+ """
359
+ if pop_size is not None:
360
+ parallelize = True
361
+ kwargs["popsize"] = pop_size
362
+
363
+ super().__init__(x0=x0, output=output, **kwargs)
364
+
365
+ self.termination = NoTermination()
366
+
367
+ self.es = None
368
+ self.cma = None
369
+
370
+ self.normalize = normalize
371
+ self.norm = None
372
+
373
+ self.sigma = sigma
374
+ self.restarts = restarts
375
+ self.restart_from_best = restart_from_best
376
+ self.incpopsize = incpopsize
377
+ self.eval_initial_x = eval_initial_x
378
+ self.noise_handler = noise_handler
379
+ self.noise_change_sigma_exponent = noise_change_sigma_exponent
380
+ self.noise_kappa_exponent = noise_kappa_exponent
381
+ self.bipop = bipop
382
+
383
+ self.options = dict(
384
+ verbose=cmaes_verbose,
385
+ verb_log=verb_log,
386
+ maxfevals=maxfevals,
387
+ tolfun=tolfun,
388
+ tolx=tolx,
389
+ **kwargs
390
+ )
391
+
392
+ self.send_array_to_yield = True
393
+ self.parallelize = parallelize
394
+ self.al = None
395
+
396
+ def _setup(self, problem, **kwargs):
397
+
398
+ xl, xu = problem.bounds()
399
+ if self.normalize:
400
+ self.norm, self.options['bounds'] = bounds_if_normalize(xl, xu)
401
+ else:
402
+ self.norm = NoNormalization()
403
+ self.options['bounds'] = [xl, xu]
404
+
405
+ seed = kwargs.get('seed', self.seed)
406
+ self.options['seed'] = seed
407
+
408
+ if isinstance(self.termination, MaximumGenerationTermination):
409
+ self.options['maxiter'] = self.termination.n_max_gen
410
+ elif isinstance(self.termination, MaximumFunctionCallTermination):
411
+ self.options['maxfevals'] = self.termination.n_max_evals
412
+
413
+ def _initialize_advance(self, **kwargs):
414
+ super()._initialize_advance(**kwargs)
415
+
416
+ kwargs = dict(
417
+ options=self.options,
418
+ parallel_objective=self.parallelize,
419
+ restarts=self.restarts,
420
+ restart_from_best=self.restart_from_best,
421
+ incpopsize=self.incpopsize,
422
+ eval_initial_x=self.eval_initial_x,
423
+ noise_handler=self.noise_handler,
424
+ noise_change_sigma_exponent=self.noise_change_sigma_exponent,
425
+ noise_kappa_exponent=self.noise_kappa_exponent,
426
+ bipop=self.bipop,
427
+ random_state=self.random_state)
428
+
429
+ x0 = self.norm.forward(self.x0.X)
430
+ self.es = my_fmin(x0, self.sigma, **kwargs)
431
+
432
+ # do this to allow the printout in the first generation
433
+ self.next_X = next(self.es)
434
+
435
+ def _infill(self):
436
+
437
+ X = np.array(self.next_X)
438
+ self.send_array_to_yield = X.ndim > 1
439
+ X = np.atleast_2d(X)
440
+
441
+ # evaluate the population
442
+ self.pop = Population.new("X", self.norm.backward(X))
443
+
444
+ return self.pop
445
+
446
+ def _advance(self, infills=None, **kwargs):
447
+
448
+ if infills is None:
449
+ self.termination.force_termination = True
450
+
451
+ else:
452
+
453
+ # set infeasible individual's objective values to np.nan - then CMAES can handle it
454
+ for ind in infills:
455
+ if not ind.feas:
456
+ ind.F[:] = np.inf
457
+
458
+ F = infills.get("f").tolist()
459
+ if not self.send_array_to_yield:
460
+ F = F[0]
461
+
462
+ try:
463
+ self.next_X = self.es.send(F)
464
+ except:
465
+ self.next_X = None
466
+
467
+ if self.next_X is None:
468
+ self.termination.force_termination = True
469
+
470
+ def _set_optimum(self):
471
+ pop = self.pop if self.opt is None else Population.merge(self.opt, self.pop)
472
+ self.opt = filter_optimum(pop, least_infeasible=True)
473
+
474
+ def __getstate__(self):
475
+ state = self.__dict__.copy()
476
+ state.pop("es", None)
477
+ return state
478
+
479
+ def __setstate__(self, state):
480
+ self.__dict__.update(state)
481
+ self.ers = None
482
+
483
+
484
+ class SimpleCMAES(LocalSearch):
485
+
486
+ def __init__(self, sigma=0.1, opts=None, normalize=True, **kwargs):
487
+ super().__init__(**kwargs)
488
+ self.termination = NoTermination()
489
+ self.es = None
490
+ self.sigma = sigma
491
+ self.normalize = normalize
492
+ self.norm = None
493
+
494
+ DEFAULTS = {"verb_disp": 0}
495
+
496
+ if opts is None:
497
+ opts = {}
498
+
499
+ for k, v in DEFAULTS.items():
500
+ if k not in kwargs:
501
+ opts[k] = v
502
+
503
+ self.opts = opts
504
+
505
+ def _setup(self, problem, **kwargs):
506
+ xl, xu = problem.bounds()
507
+ if self.normalize:
508
+ self.norm, self.opts['bounds'] = bounds_if_normalize(xl, xu)
509
+ else:
510
+ self.norm = NoNormalization()
511
+ self.opts['bounds'] = [xl, xu]
512
+ self.opts['seed'] = self.seed
513
+
514
+ def _initialize_advance(self, infills=None, **kwargs):
515
+ super()._initialize_advance(infills, **kwargs)
516
+ x = self.norm.forward(self.x0.X)
517
+ self.es = cma.CMAEvolutionStrategy(x, self.sigma, inopts=self.opts)
518
+
519
+ def _infill(self):
520
+ X = self.norm.backward(np.array(self.es.ask()))
521
+ return Population.new("X", X)
522
+
523
+ def _advance(self, infills=None, **kwargs):
524
+ X, F = infills.get("X", "F")
525
+ X = self.norm.forward(X)
526
+
527
+ self.es.tell(X, F[:, 0])
528
+ self.pop = infills
529
+
530
+ if self.es.stop():
531
+ self.termination.force_termination = True
532
+
533
+ def _set_optimum(self):
534
+ pop = self.pop if self.opt is None else Population.merge(self.opt, self.pop)
535
+ self.opt = filter_optimum(pop, least_infeasible=True)
536
+
537
+
538
+ class BIPOPCMAES(CMAES):
539
+
540
+ def __init__(self, restarts=4, **kwargs):
541
+ super().__init__(restarts=restarts, bipop=True, **kwargs)
542
+
543
+
544
+ def bounds_if_normalize(xl, xu):
545
+ norm = ZeroToOneNormalization(xl=xl, xu=xu)
546
+
547
+ _xl, _xu = np.zeros_like(xl), np.ones_like(xu)
548
+ if xl is not None:
549
+ _xl[np.isnan(xl)] = np.nan
550
+ if xu is not None:
551
+ _xu[np.isnan(xu)] = np.nan
552
+
553
+ return norm, [_xl, _xu]
554
+
555
+
556
+ parse_doc_string(CMAES.__init__)