DEAP / deap

Distributed Evolutionary Algorithms in Python
http://deap.readthedocs.org/
GNU Lesser General Public License v3.0
5.76k stars 1.12k forks source link

Range of individuals in CMA-ES #200

Closed osm3000 closed 7 years ago

osm3000 commented 7 years ago

Hi everyone,

I am new to DEAP. I've two quick questions about the CMA-ES example https://github.com/DEAP/deap/blob/759473d39dc307aa986f6035bbc5a8fd5e058db3/examples/es/cma_minfct.py

  1. How can I control the 'length' of the individual (the length of the list representing the individual?
  2. How can I control the range of individuals' values? (I want the genes of the individuals - the elements in the list - to be constrained in a certain range.

Thank you in advance

sarajcev commented 7 years ago

Example (where creator.Individual has been already created using creator.create):

toolbox.register("attribute", random.randint, 0, 100)
toolbox.register("individual", tools.initRepeat, creator.Individual, toolbox.attribute, n=3)

To answer you second question: The first line of code creates an "attribute" of the "individual", which is a random integer number bounded between 0 and 100. To answer your first question: While registering an "individual" you can pass the argument (n=3), which is the "length" of the individual. The "population" list of 100 "individuals" (each of length "n=3") can now be created as follows:

toolbox.register("population", tools.initRepeat, list, toolbox.individual)
population = toolbox.population(n=100)
osm3000 commented 7 years ago

Thank you @sarajcev for your reply. I understand what you said in case of evolutionary algorithms, but not in case of evolutionary strategies. In the examples provided, the population is not generated explicitly creator.create("Individual", list, fitness=creator.FitnessMin) then directly: strategy = cma.Strategy(centroid=[5.0]*N, sigma=5.0, lambda_=20*N) toolbox.register("generate", strategy.generate, creator.Individual) toolbox.register("update", strategy.update) So this explicit generation I didn't see in case of CMA-ES examples. Is my observation correct? or am I missing something?

sarajcev commented 7 years ago

It seems I've misunderstood your question.

I believe that the "N" in the code strategy = cma.Strategy(centroid=[5.0]*N, sigma=5.0, lambda_=20*N) is the size of the individual.

fmder commented 7 years ago

The reason for the discrepancy between the two type of algorithms is because evolution strategies generate the populations randomly while adjusting the distribution parameters. Evolutionary algorithms for their part modify (mate and mutate) actual individuals using natural selection.

In evolutionary computation in general, the number of generated individuals each generation is usually noted lambda while the number of selected individuals is mu.

Le 15 mai 2017 05:35, "sarajcev" notifications@github.com a écrit :

It seems I've misunderstood your question.

I believe that the "N" in the code strategy = cma.Strategy(centroid=[5.0]N, sigma=5.0, lambda_=20N) is the size of the individual.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/DEAP/deap/issues/200#issuecomment-301425525, or mute the thread https://github.com/notifications/unsubscribe-auth/AA6rwkSnHkPSHA-QePJryJbnOikyio4Xks5r6BxsgaJpZM4NagGq .

fmder commented 7 years ago

This is more an question than an issue, please use the mailing list for such conversations.