Python CMA-ES Custom Function and Constraint Algorithm

I am trying to create a simple example of a CMA-ES optimization algorithm in python. What is the most optimized way to optimize a function x**2 + 2*y**2 -4*x*y - 0.5*y, taking into account the limitations -2<x<2and -1<2*(x**2)*y<1using the CMA-ES algorithm?

I looked into the DEAP library, but could not develop a focused attempt. I found my documentation less intuitive. I also looked at the cma package , but it is not clear to me how I can implement the restrictions.

+4
source share
2 answers

I see your struggle with DEAP documents. However, I wrote my own Evolutionary Computing library, and lately I have been using DEAP for many proofs of concepts, and I think they did a good job of this.

Next, let's look at a complete example . If you read the documents, it will be more convenient for you to look at the code. The size of the problem is the number of variables, so in your case, if I understand correctly, you will have N = 2(x and y).

And you need your custom fitness function instead of benchamrks.rastrigin:

toolbox.register("evaluate", myownfunction)

Limitations are not implemented, but are an easy task. In the fitness function, you can nullify people who violate restrictions (for example, by assigning a very high physical shape if minimized), and for several generations your population should be free from disabilities.

DEAP, deap.cma.Strategy class , / , instance, generate, .

+2

Python cma :

import cma
opts = cma.CMAOptions()
opts.set("bounds", [[-2, None], [2, None]])
cma.fmin(cost_function, x_start, sigma_start, opts)

, , , - . cost_function . (, ) .

. ( ) .

0

All Articles