Skip to content

Commit

Permalink
Add the option to provide an initial covariance matrix to a CMA-ES St…
Browse files Browse the repository at this point in the history
…rategy.

--HG--
branch : dev
  • Loading branch information
felix.antoine.fortin committed Aug 15, 2012
1 parent 9a41f01 commit 6eaf41b
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions deap/cma.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ class Strategy(object):
| | | keep from the |
| | | lambda children (integer). |
+----------------+---------------------------+----------------------------+
| ``cmatrix`` | ``identity(N)`` | The initial covariance |
| | | matrix of the distribution |
| | | that will be sampled. |
+----------------+---------------------------+----------------------------+
| ``weights`` | ``"superlinear"`` | Decrease speed, can be |
| | | ``"superlinear"``, |
| | | ``"linear"`` or |
Expand Down Expand Up @@ -84,12 +88,16 @@ def __init__(self, centroid, sigma, **kargs):
self.chiN = sqrt(self.dim) * (1 - 1. / (4. * self.dim) + \
1. / (21. * self.dim**2))

self.B = numpy.identity(self.dim)
self.C = numpy.identity(self.dim)
self.diagD = numpy.ones(self.dim)
self.C = self.params.get("cmatrix", numpy.identity(self.dim))
self.diagD, self.B = numpy.linalg.eigh(self.C)

indx = numpy.argsort(self.diagD)
self.diagD = self.diagD[indx]**0.5
self.B = self.B[:, indx]
self.BD = self.B * self.diagD

self.cond = 1
self.cond = self.diagD[indx[-1]]/self.diagD[indx[0]]

self.lambda_ = self.params.get("lambda_", int(4 + 3 * log(self.dim)))
self.update_count = 0
self.computeParams(self.params)
Expand Down

0 comments on commit 6eaf41b

Please sign in to comment.