This module contains the GPopulation.GPopulation class, which is reponsible to keep the population and the statistics.
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
Parameter: | genome – the Sample genome |
---|
Return the best scaled fitness individual of population
Parameter: | index – the index best individual |
---|---|
Return type: | the individual |
Return the best raw score individual of population
Return type: | the individual |
---|
Copy current population to ‘pop’
Parameter: | pop – the destination population |
---|
Warning
this method do not copy the individuals, only the population logic
Evaluate all individuals in population, calls the evaluate() method of individuals
Parameter: | args – this params are passed to the evaluation function |
---|
Return a Statistics class for statistics
Return type: | the Statistics.Statistics instance |
---|
Scale the population using the scaling method
Parameter: | args – this parameter is passed to the scale method |
---|
Sets the population minimax
>>> pop.setMinimax(Consts.minimaxType["maximize"])
Parameter: | minimax – the minimax type |
---|
Set the population size
Parameter: | size – the population size |
---|
Sets the sort type
>>> pop.setSortType(Consts.sortType["scaled"])
Parameter: | sort_type – the Sort Type |
---|
Compares two individual raw scores
>>> GPopulation.cmp_individual_raw(a, b)
Parameters: |
|
---|---|
Return type: | 0 if the two individuals raw score are the same, -1 if the B individual raw score is greater than A and 1 if the A individual raw score is greater than B. |
Note
this function is used to sorte the population individuals
Compares two individual fitness scores, used for sorting population
>>> GPopulation.cmp_individual_scaled(a, b)
Parameters: |
|
---|---|
Return type: | 0 if the two individuals fitness score are the same, -1 if the B individual fitness score is greater than A and 1 if the A individual fitness score is greater than B. |
Note
this function is used to sorte the population individuals
A key function to return fitness score, used by max()/min()
Parameter: | 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
Parameter: | individual – the individual instance |
---|---|
Return type: | the individual raw score |
Note
this function is used by the max()/min() python functions