This module contains the GPopulation.GPopulation class, which is reponsible to keep the population and the statistics.
Sort Type
>>> Consts.sortType["scaled"]The scaled sort type
Minimax
>>> Consts.minimaxType["maximize"]Maximize the evaluation function
Scale Method
The Linear Scaling scheme
GPopulation Class - The container for the population
>>> pop = ga_engine.getPopulation()
>>> bestIndividual = pop.bestFitness()
>>> bestIndividual = pop.bestRaw()
>>> stats = pop.getStatistics()
>>> print stats["rawMax"]
10.4
>>> for ind in pop:
>>> print ind
(...)
>>> for i in xrange(len(pop)):
>>> print pop[i]
(...)
>>> pop[10] = newGenome
>>> pop[10].fitness
12.5
Parameters: | genome – the Sample genome, or a GPopulation object, when cloning. |
---|
Return the best scaled fitness individual of population
Parameters: | index – the index best individual |
---|---|
Return type: | the individual |
Return the best raw score individual of population
Parameters: | index – the index best raw individual |
---|---|
Return type: | the individual |
New in version 0.6: The parameter index.
Remove all individuals from population
Clear the sorted and statted internal flags
Return a brand-new cloned population
Copy current population to ‘pop’
Parameters: | pop – the destination population |
---|
Warning
this method do not copy the individuals, only the population logic
Clone the example genome to fill the population
Evaluate all individuals in population, calls the evaluate() method of individuals
Parameters: | args – this params are passed to the evaluation function |
---|
Gets an internal parameter
>>> population.getParam("tournamentPool")
5
Parameters: |
|
---|
Return a Statistics class for statistics
Return type: | the Statistics.Statistics instance |
---|
Initialize all individuals of population, this calls the initialize() of individuals
Print statistics of the current population
Scale the population using the scaling method
Parameters: | args – this parameter is passed to the scale method |
---|
Sets the population minimax
>>> pop.setMinimax(Consts.minimaxType["maximize"])
Parameters: | minimax – the minimax type |
---|
Sets the flag to enable/disable the use of python multiprocessing module. Use this option when you have more than one core on your CPU and when your evaluation function is very slow. The parameter “full_copy” defines where the individual data should be copied back after the evaluation or not. This parameter is useful when you change the individual in the evaluation function.
Parameters: |
|
---|
Warning
Use this option only when your evaluation function is slow, se you will get a good tradeoff between the process communication speed and the parallel evaluation.
New in version 0.6: The setMultiProcessing method.
Gets an internal parameter
>>> population.setParams(tournamentPool=5)
Parameters: | args – parameters to set |
---|
New in version 0.6: The setParams method.
Set the population size
Parameters: | size – the population size |
---|
Sets the sort type
>>> pop.setSortType(Consts.sortType["scaled"])
Parameters: | sort_type – the Sort Type |
---|
Sort the population
Do statistical analysis of population and set ‘statted’ to True
A key function to return fitness score, used by max()/min()
Parameters: | individual – the individual instance |
---|---|
Return type: | the individual fitness score |
Note
this function is used by the max()/min() python functions
A key function to return raw score
Parameters: | individual – the individual instance |
---|---|
Return type: | the individual raw score |
Note
this function is used by the max()/min() python functions
Internal used by the multiprocessing
Internal used by the multiprocessing (full copy)