GPopulation – the population module

This module contains the GPopulation.GPopulation class, which is reponsible to keep the population and the statistics.

class GPopulation.GPopulation(genome)

GPopulation Class - The container for the population

Examples
Get the population from the GSimpleGA.GSimpleGA (GA Engine) instance
>>> pop = ga_engine.getPopulation()
Get the best fitness individual
>>> bestIndividual = pop.bestFitness()
Get the best raw individual
>>> bestIndividual = pop.bestRaw()
Get the statistics from the Statistics.Statistics instance
>>> stats = pop.getStatistics()
>>> print stats["rawMax"]
10.4
Iterate, get/set individuals
>>> 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
bestFitness(index=0)

Return the best scaled fitness individual of population

Parameter:index – the index best individual
Return type:the individual
bestRaw()

Return the best raw score individual of population

Return type:the individual
clear()
Remove all individuals from population
clone()
Return a brand-new cloned population
copy(pop)

Copy current population to ‘pop’

Parameter:pop – the destination population

Warning

this method do not copy the individuals, only the population logic

create(**args)
Clone the example genome to fill the population
evaluate(**args)

Evaluate all individuals in population, calls the evaluate() method of individuals

Parameter:args – this params are passed to the evaluation function
getStatistics()

Return a Statistics class for statistics

Return type:the Statistics.Statistics instance
initialize()
Initialize all individuals of population, this calls the initialize() of individuals
printStats()
Print statistics of the current population
scale(**args)

Scale the population using the scaling method

Parameter:args – this parameter is passed to the scale method
setMinimax(minimax)

Sets the population minimax

Example:
>>> pop.setMinimax(Consts.minimaxType["maximize"])
Parameter:minimax – the minimax type
setPopulationSize(size)

Set the population size

Parameter:size – the population size
setSortType(sort_type)

Sets the sort type

Example:
>>> pop.setSortType(Consts.sortType["scaled"])
Parameter:sort_type – the Sort Type
sort()
Sort the population
statistics()
Do statistical analysis of population and set ‘statted’ to True
GPopulation.cmp_individual_raw(a, b)

Compares two individual raw scores

Example:
>>> GPopulation.cmp_individual_raw(a, b)
Parameters:
  • a – the A individual instance
  • b – the B individual instance
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

GPopulation.cmp_individual_scaled(a, b)

Compares two individual fitness scores, used for sorting population

Example:
>>> GPopulation.cmp_individual_scaled(a, b)
Parameters:
  • a – the A individual instance
  • b – the B individual instance
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

GPopulation.key_fitness_score(individual)

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

GPopulation.key_raw_score(individual)

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


Recent Blog Posts

Previous topic

GSimpleGA – the genetic algorithm by itself

Next topic

Mutators – mutation methods module

This Page