cma 4.4.2__tar.gz → 4.4.4__tar.gz

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 (41) hide show
  1. {cma-4.4.2 → cma-4.4.4}/PKG-INFO +28 -17
  2. {cma-4.4.2 → cma-4.4.4}/README.rst +29 -20
  3. {cma-4.4.2 → cma-4.4.4}/pyproject.toml +7 -5
  4. {cma-4.4.2 → cma-4.4.4/src}/cma/__init__.py +3 -2
  5. {cma-4.4.2 → cma-4.4.4/src}/cma/evolution_strategy.py +40 -15
  6. cma-4.4.4/src/cma/experimentation.py +821 -0
  7. {cma-4.4.2 → cma-4.4.4/src}/cma/logger.py +27 -25
  8. cma-4.4.4/src/cma/more_algorithms/__init__.py +8 -0
  9. cma-4.4.4/src/cma/more_algorithms/compact_ga.py +110 -0
  10. {cma-4.4.2/cma → cma-4.4.4/src/cma/more_algorithms}/purecma.py +12 -11
  11. {cma-4.4.2 → cma-4.4.4/src}/cma/options_parameters.py +1 -0
  12. {cma-4.4.2 → cma-4.4.4/src}/cma/s.py +18 -6
  13. {cma-4.4.2 → cma-4.4.4/src}/cma/sigma_adaptation.py +74 -30
  14. {cma-4.4.2 → cma-4.4.4/src}/cma/test.py +12 -1
  15. {cma-4.4.2 → cma-4.4.4/src}/cma/utilities/math.py +131 -10
  16. {cma-4.4.2 → cma-4.4.4/src}/cma/utilities/utils.py +5 -0
  17. cma-4.4.4/src/cma/warnings_and_exceptions.py +16 -0
  18. {cma-4.4.2 → cma-4.4.4/src}/cma.egg-info/PKG-INFO +28 -17
  19. cma-4.4.4/src/cma.egg-info/SOURCES.txt +38 -0
  20. {cma-4.4.2 → cma-4.4.4/src}/cma.egg-info/requires.txt +3 -0
  21. cma-4.4.2/cma.egg-info/SOURCES.txt +0 -34
  22. {cma-4.4.2 → cma-4.4.4}/LICENSE +0 -0
  23. {cma-4.4.2 → cma-4.4.4}/setup.cfg +0 -0
  24. {cma-4.4.2 → cma-4.4.4/src}/cma/bbobbenchmarks.py +0 -0
  25. {cma-4.4.2 → cma-4.4.4/src}/cma/boundary_handler.py +0 -0
  26. {cma-4.4.2 → cma-4.4.4/src}/cma/constraints_handler.py +0 -0
  27. {cma-4.4.2 → cma-4.4.4/src}/cma/fitness_functions.py +0 -0
  28. {cma-4.4.2 → cma-4.4.4/src}/cma/fitness_models.py +0 -0
  29. {cma-4.4.2 → cma-4.4.4/src}/cma/fitness_transformations.py +0 -0
  30. {cma-4.4.2 → cma-4.4.4/src}/cma/integer_centering.py +0 -0
  31. {cma-4.4.2 → cma-4.4.4/src}/cma/interfaces.py +0 -0
  32. {cma-4.4.2 → cma-4.4.4/src}/cma/optimization_tools.py +0 -0
  33. {cma-4.4.2 → cma-4.4.4/src}/cma/recombination_weights.py +0 -0
  34. {cma-4.4.2 → cma-4.4.4/src}/cma/restricted_gaussian_sampler.py +0 -0
  35. {cma-4.4.2 → cma-4.4.4/src}/cma/sampler.py +0 -0
  36. {cma-4.4.2 → cma-4.4.4/src}/cma/transformations.py +0 -0
  37. {cma-4.4.2 → cma-4.4.4/src}/cma/utilities/__init__.py +0 -0
  38. {cma-4.4.2 → cma-4.4.4/src}/cma/utilities/python3for2.py +0 -0
  39. {cma-4.4.2 → cma-4.4.4/src}/cma/wrapper.py +0 -0
  40. {cma-4.4.2 → cma-4.4.4/src}/cma.egg-info/dependency_links.txt +0 -0
  41. {cma-4.4.2 → cma-4.4.4/src}/cma.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cma
3
- Version: 4.4.2
3
+ Version: 4.4.4
4
4
  Summary: CMA-ES, Covariance Matrix Adaptation Evolution Strategy for non-linear numerical optimization in Python
5
5
  Author: Nikolaus Hansen, Youhei Akimoto, Petr Baudis
6
6
  Maintainer-email: Nikolaus Hansen <authors_firstname.lastname@inria.fr>
@@ -29,31 +29,42 @@ Provides-Extra: plotting
29
29
  Requires-Dist: matplotlib; extra == "plotting"
30
30
  Provides-Extra: constrained-solution-tracking
31
31
  Requires-Dist: moarchiving; extra == "constrained-solution-tracking"
32
+ Provides-Extra: statistical-tests
33
+ Requires-Dist: scipy; extra == "statistical-tests"
32
34
  Dynamic: license-file
33
35
 
34
36
  CMA-ES Covariance Matrix Adaptation Evolution Strategy
35
37
  ======================================================
36
38
 
37
- A stochastic numerical optimization algorithm for difficult (non-convex,
38
- ill-conditioned, multi-modal, rugged, noisy) optimization problems in
39
- continuous or mixed-integer search spaces, implemented in Python.
39
+ The CMA-ES is a randomized derivative-free numerical optimization algorithm for
40
+ difficult (non-convex, ill-conditioned, multi-modal, rugged, noisy) optimization
41
+ problems in continuous or mixed-integer search spaces, implemented in Python.
40
42
 
41
- Typical domain of application are unconstrained or bound-constrained
42
- objective functions with:
43
+ The typical domain of application are objective functions with:
43
44
 
44
- * search space dimension between, say, five and a few hundred,
45
- * no gradients available,
46
- * at least, say, 100 times dimension function evaluations needed
47
- to get satisfactory solutions,
48
- * non-separable, ill-conditioned, or rugged/multi-modal landscapes.
45
+ * search space dimension between five and a few hundred,
46
+ * dependent decision variables (non-separable)
47
+ * gradients not being available or useful,
48
+ * at least, say, 100 times dimension function evaluations possible and
49
+ needed to get a satisfactory solution,
50
+ * ill-conditioned or rugged or multi-modal landscapes.
49
51
 
50
- Nonlinear constraints handling is available too.
51
- The CMA-ES is quite reliable, however for small budgets (fewer function
52
- evaluations than, say, 100 times dimension) or in very small dimensions
53
- faster methods are available.
52
+ The handling of
54
53
 
55
- The ``pycma`` module provides two independent implementations of the
56
- CMA-ES algorithm in the classes `cma.CMAEvolutionStrategy`_ and
54
+ * bound constraints via the ``'bounds' = [lower, upper]`` option or the
55
+ `cma.BoundDomainTransform` wrapper
56
+ * linear and nonlinear constraints via the ``constraints`` argument to `fmin2`
57
+ or `fmin_con2`
58
+ * noise via ``noise_handler=True`` as argument to `fmin2`
59
+ * integer variables for mixed-integer problems via the
60
+ ``'integer_variables'=index_list`` option
61
+
62
+ is available too. The CMA-ES is quite reliable, however for small budgets
63
+ (fewer function evaluations than 100 times dimension) or in very small
64
+ dimensions faster methods are available.
65
+
66
+ The ``pycma`` module provides two independent implementations of the CMA-ES
67
+ algorithm in the classes `cma.CMAEvolutionStrategy`_ and a basic implementation
57
68
  `cma.purecma.CMAES`_.
58
69
 
59
70
  Installation
@@ -1,26 +1,35 @@
1
1
  CMA-ES Covariance Matrix Adaptation Evolution Strategy
2
2
  ======================================================
3
3
 
4
- A stochastic numerical optimization algorithm for difficult (non-convex,
5
- ill-conditioned, multi-modal, rugged, noisy) optimization problems in
6
- continuous or mixed-integer search spaces, implemented in Python.
7
-
8
- Typical domain of application are unconstrained or bound-constrained
9
- objective functions with:
10
-
11
- * search space dimension between, say, five and a few hundred,
12
- * no gradients available,
13
- * at least, say, 100 times dimension function evaluations needed
14
- to get satisfactory solutions,
15
- * non-separable, ill-conditioned, or rugged/multi-modal landscapes.
16
-
17
- Nonlinear constraints handling is available too.
18
- The CMA-ES is quite reliable, however for small budgets (fewer function
19
- evaluations than, say, 100 times dimension) or in very small dimensions
20
- faster methods are available.
21
-
22
- The ``pycma`` module provides two independent implementations of the
23
- CMA-ES algorithm in the classes `cma.CMAEvolutionStrategy`_ and
4
+ The CMA-ES is a randomized derivative-free numerical optimization algorithm for
5
+ difficult (non-convex, ill-conditioned, multi-modal, rugged, noisy) optimization
6
+ problems in continuous or mixed-integer search spaces, implemented in Python.
7
+
8
+ The typical domain of application are objective functions with:
9
+
10
+ * search space dimension between five and a few hundred,
11
+ * dependent decision variables (non-separable)
12
+ * gradients not being available or useful,
13
+ * at least, say, 100 times dimension function evaluations possible and
14
+ needed to get a satisfactory solution,
15
+ * ill-conditioned or rugged or multi-modal landscapes.
16
+
17
+ The handling of
18
+
19
+ * bound constraints via the ``'bounds' = [lower, upper]`` option or the
20
+ `cma.BoundDomainTransform` wrapper
21
+ * linear and nonlinear constraints via the ``constraints`` argument to `fmin2`
22
+ or `fmin_con2`
23
+ * noise via ``noise_handler=True`` as argument to `fmin2`
24
+ * integer variables for mixed-integer problems via the
25
+ ``'integer_variables'=index_list`` option
26
+
27
+ is available too. The CMA-ES is quite reliable, however for small budgets
28
+ (fewer function evaluations than 100 times dimension) or in very small
29
+ dimensions faster methods are available.
30
+
31
+ The ``pycma`` module provides two independent implementations of the CMA-ES
32
+ algorithm in the classes `cma.CMAEvolutionStrategy`_ and a basic implementation
24
33
  `cma.purecma.CMAES`_.
25
34
 
26
35
  Installation
@@ -9,7 +9,7 @@
9
9
  requires = [
10
10
  "setuptools >=79",
11
11
  # "setuptools-scm", # if we want to use git versions for versioning
12
- "wheel", # setuptools doesn't need wheel anymore, see https://pypi.org/project/wheel/
12
+ # "wheel", # setuptools doesn't need wheel anymore, see https://pypi.org/project/wheel/
13
13
  ]
14
14
  build-backend = "setuptools.build_meta"
15
15
 
@@ -60,16 +60,18 @@ classifiers = [
60
60
  # packages = ["cma", "cma.utilities"] # fails when they are in an src/ folder
61
61
  include-package-data = false # true is default, false doesn't change anything
62
62
 
63
- [tool.setuptools.packages.find] # for where=. works only in a clean folder
64
- # where = ["src"] # this doesn't work, it always takes the root too?
65
- include = ["cma*"]
66
- exclude = ["notebooks*"]
63
+ # [tool.setuptools.packages.find] # for where=. works only in a clean folder
64
+ # without any directives: finds src folder implying a standard (nonflat) layout
65
+ # # where = ["src"] # this doesn't work, it always takes the root too?
66
+ # include = ["cma*"] # cma/* ?
67
+ # exclude = ["notebooks*"] # , "cma_*" ?
67
68
 
68
69
  # namespaces = false
69
70
 
70
71
  [project.optional-dependencies]
71
72
  plotting = ["matplotlib"]
72
73
  constrained-solution-tracking = ["moarchiving"]
74
+ statistical-tests = ["scipy"]
73
75
 
74
76
  [project.urls]
75
77
  Homepage = "https://github.com/CMA-ES/pycma"
@@ -103,14 +103,15 @@ del _ab, _di, _pr
103
103
 
104
104
  ___author__ = "Nikolaus Hansen and Petr Baudis and Youhei Akimoto"
105
105
  __license__ = "BSD 3-clause"
106
- __version__ = "4.4.2"
106
+ __version__ = "4.4.4"
107
+ '''version 4.4.4''' # allows the apidocs to "pick up" the version number
107
108
 
108
109
 
109
110
  import collections as _collections
110
111
  import warnings as _warnings
111
112
 
112
113
  # __package__ = 'cma'
113
- from . import purecma
114
+ from .more_algorithms import purecma
114
115
  try:
115
116
  import numpy as _np
116
117
  except ImportError:
@@ -202,6 +202,7 @@ from . import optimization_tools as ot
202
202
  from . import sampler
203
203
  from .utilities import utils
204
204
  from .options_parameters import CMAOptions, cma_default_options
205
+ from . import warnings_and_exceptions as _cma_warnings
205
206
  from . import constraints_handler as _constraints_handler
206
207
  from cma import fitness_models as _fitness_models
207
208
  from .boundary_handler import BoundNone, BoundPenalty, BoundTransform
@@ -1045,6 +1046,8 @@ class CMAEvolutionStrategy(interfaces.OOOptimizer):
1045
1046
  `options` is for consistency with `fmin2` options and is only
1046
1047
  in effect if ``inopts is None``.
1047
1048
  """
1049
+ _cma_warnings.filterwarning('once',
1050
+ category=_cma_warnings.NeverTestedWarning)
1048
1051
  if options and inopts is None:
1049
1052
  inopts = options
1050
1053
  del options
@@ -1374,6 +1377,10 @@ class CMAEvolutionStrategy(interfaces.OOOptimizer):
1374
1377
  self.noiseS = 0 # noise "signal"
1375
1378
  self.hsiglist = []
1376
1379
 
1380
+ try: # prevent that late initialization overwrites values during first update call
1381
+ self.adapt_sigma.initialize(self)
1382
+ except Exception:
1383
+ pass
1377
1384
  self.sent_solutions = get_CMASolutionDict(archive_sent_solutions)()
1378
1385
  '''archive solutions close to the end of `ask`, this archive is
1379
1386
  passed to ``gp.geno`` to bypass calling the inverse geno-pheno
@@ -1400,10 +1407,10 @@ class CMAEvolutionStrategy(interfaces.OOOptimizer):
1400
1407
  expensive_modulo=opts['verb_log_expensive']).register(self)
1401
1408
 
1402
1409
  self._stopdict = _CMAStopDict()
1403
- " attribute for stopping criteria in function stop"
1410
+ '''attribute for stopping criteria in function stop'''
1404
1411
  self._stoptolxstagnation = _StopTolXStagnation(self.mean)
1405
1412
  self.callbackstop = ()
1406
- " return values of callbacks, used like ``if any(callbackstop)``"
1413
+ '''return values of callbacks, used like ``if any(callbackstop)``'''
1407
1414
  self.fit = _BlancClass()
1408
1415
  self.fit.fit = None # objective function values sorted
1409
1416
  self.fit.bndpen = None # boundary penalty values
@@ -1679,6 +1686,10 @@ class CMAEvolutionStrategy(interfaces.OOOptimizer):
1679
1686
  "sampler attributes `B` and `D` are not present",
1680
1687
  "ask", "CMAEvolutionStrategy",
1681
1688
  self.countiter, maxwarns=1)
1689
+ warnings.warn("the `gradf` argument to `ask` has not been thoroughly tested,"
1690
+ "\n consider to use ``es.inject(es.mean - delta * gradf(es.mean)``"
1691
+ " with a large value for delta.",
1692
+ category=_cma_warnings.NeverTestedWarning)
1682
1693
  try:
1683
1694
  # see Hansen (2011), Injecting external solutions into CMA-ES
1684
1695
  if not self.gp.islinear:
@@ -1687,12 +1698,18 @@ class CMAEvolutionStrategy(interfaces.OOOptimizer):
1687
1698
  coordinate-wise transformation (option ``transformation``)
1688
1699
  has never been tested.""")
1689
1700
  # TODO: check this out
1701
+ def _rm_fixed(y):
1702
+ """return y unchanged or a copy of y without fixed variables"""
1703
+ if not self.opts['fixed_variables']:
1704
+ return y
1705
+ return np.asarray([y[i] for i in range(len(y))
1706
+ if i not in self.opts['fixed_variables']])
1690
1707
  def grad_numerical_of_coordinate_map(x, map, epsilon=None):
1691
1708
  """map is a coordinate-wise independent map, return
1692
1709
  the estimated diagonal of the Jacobian.
1693
1710
  """
1694
1711
  eps = 1e-8 * (1 + abs(x)) if epsilon is None else epsilon
1695
- return (map(x + eps) - map(x - eps)) / (2 * eps)
1712
+ return _rm_fixed(map(x + eps) - map(x - eps)) / (2 * eps)
1696
1713
  def grad_numerical_sym(x, func, epsilon=None):
1697
1714
  """return symmetric numerical gradient of func : R^n -> R.
1698
1715
  """
@@ -1722,7 +1739,7 @@ class CMAEvolutionStrategy(interfaces.OOOptimizer):
1722
1739
  xmean = self.mean
1723
1740
  xpheno = self.gp.pheno(xmean, copy=True,
1724
1741
  into_bounds=self.boundary_handler.repair)
1725
- grad_at_mean = gradf(xpheno, *args)
1742
+ grad_at_mean = _rm_fixed(gradf(xpheno, *args))
1726
1743
  # lift gradient into geno-space
1727
1744
  if not self.gp.isidentity or (self.boundary_handler is not None
1728
1745
  and self.boundary_handler.has_bounds()):
@@ -1735,8 +1752,7 @@ class CMAEvolutionStrategy(interfaces.OOOptimizer):
1735
1752
  def fpenalty(x):
1736
1753
  return self.boundary_handler.__call__(
1737
1754
  x, _SolutionDict({tuple(x): {'geno': x}}), self.gp)
1738
- gradpen = grad_numerical_sym(
1739
- xmean, fpenalty)
1755
+ gradpen = _rm_fixed(grad_numerical_sym(xmean, fpenalty))
1740
1756
  elif self.boundary_handler is None or \
1741
1757
  isinstance(self.boundary_handler,
1742
1758
  BoundNone):
@@ -1751,11 +1767,16 @@ class CMAEvolutionStrategy(interfaces.OOOptimizer):
1751
1767
  gradgp = grad_numerical_of_coordinate_map(xmean, _gp_for_num_grad)
1752
1768
  grad_at_mean = grad_at_mean * gradgp + gradpen
1753
1769
 
1754
- # TODO: frozen variables brake the code (e.g. at grad of map)
1755
- if len(grad_at_mean) != self.N or self.opts['fixed_variables']:
1756
- NotImplementedError("""
1757
- gradient with fixed variables is not (yet) implemented,
1758
- implement a simple transformation of the objective instead""")
1770
+ # DONE: frozen variables break the code (e.g. at grad of map)
1771
+ if self.opts['fixed_variables']:
1772
+ warnings.warn("gradient with fixed variables was never tested, consider"
1773
+ "\n to implement a simple transformation of the objective instead"
1774
+ "\n see `cma.fitness_transformations.FixVariables`",
1775
+ category=_cma_warnings.NeverTestedWarning)
1776
+ if len(grad_at_mean) != self.N:
1777
+ warnings.warn("gradient dimension={0}!={1}=genotype dimension."
1778
+ "This will lead to an exception soon."
1779
+ .format(len(grad_at_mean), self.N))
1759
1780
  v = self.sm.D * np.dot(self.sm.B.T, self.sigma_vec * grad_at_mean)
1760
1781
  # newton_direction = sv * B * D * D * B^T * sv * gradient = sv * B * D * v
1761
1782
  # v = D^-1 * B^T * sv^-1 * newton_direction = D * B^T * sv * gradient
@@ -4680,8 +4701,10 @@ def fmin2(objective_function, x0, sigma0,
4680
4701
 
4681
4702
  We can use the gradient like
4682
4703
 
4683
- >>> import cma
4684
- >>> x, es = cma.fmin2(cma.ff.rosen, np.zeros(10), 0.1,
4704
+ >>> import cma, warnings
4705
+ >>> with warnings.catch_warnings():
4706
+ ... warnings.simplefilter('ignore', category=cma.warnings_and_exceptions.NeverTestedWarning)
4707
+ ... x, es = cma.fmin2(cma.ff.rosen, np.zeros(10), 0.1,
4685
4708
  ... options = {'ftarget':1e-8,},
4686
4709
  ... gradf=cma.ff.grad_rosen,
4687
4710
  ... ) #doctest: +ELLIPSIS
@@ -4830,8 +4853,10 @@ def fmin(objective_function, x0, sigma0, *posargs, **kwargs):
4830
4853
 
4831
4854
  We can use the gradient like
4832
4855
 
4833
- >>> import cma
4834
- >>> res = cma.fmin(cma.ff.rosen, np.zeros(10), 0.1,
4856
+ >>> import cma, warnings
4857
+ >>> with warnings.catch_warnings():
4858
+ ... warnings.simplefilter('ignore', category=cma.warnings_and_exceptions.NeverTestedWarning)
4859
+ ... res = cma.fmin(cma.ff.rosen, np.zeros(10), 0.1,
4835
4860
  ... options = {'ftarget':1e-8,},
4836
4861
  ... gradf=cma.ff.grad_rosen,
4837
4862
  ... ) #doctest: +ELLIPSIS