Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 51 additions & 50 deletions pyevolve/Interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,69 +17,70 @@
import logging

try:
import pylab
import pylab
except:
logging.debug("cannot import Matplotlib ! Plots will not be available !")
print "Warning: cannot import Matplotlib ! Plots will not be available !"
logging.debug("cannot import Matplotlib ! Plots will not be available !")
print "Warning: cannot import Matplotlib ! Plots will not be available !"

try:
import numpy
import numpy
except:
logging.debug("cannot import Numpy ! Some functions will not be available !")
print "Warning: cannot import Numpy ! Some functions will not be available !"
logging.debug("cannot import Numpy ! Some functions will not be available !")
print "Warning: cannot import Numpy ! Some functions will not be available !"

def getPopScores(population, fitness=False):
""" Returns a list of population scores
""" Returns a list of population scores

Example:
>>> lst = Interaction.getPopScores(population)
Example:
>>> lst = Interaction.getPopScores(population)

:param population: population object (:class:`GPopulation.GPopulation`)
:param fitness: if is True, the fitness score will be used, otherwise, the raw.
:rtype: list of population scores
:param population: population object (:class:`GPopulation.GPopulation`)
:param fitness: if is True, the fitness score will be used, otherwise, the raw.
:rtype: list of population scores

"""
score_list = []
for individual in population:
score_list.append(individual.fitness if fitness else individual.score)
return score_list

"""
score_list = []
for individual in population:
score_list.append(individual.fitness if fitness else individual.score)
return score_list

def plotPopScore(population, fitness=False):
""" Plot the population score distribution
""" Plot the population score distribution

Example:
>>> Interaction.plotPopScore(population)
Example:
>>> Interaction.plotPopScore(population)

:param population: population object (:class:`GPopulation.GPopulation`)
:param fitness: if is True, the fitness score will be used, otherwise, the raw.
:rtype: None
:param population: population object (:class:`GPopulation.GPopulation`)
:param fitness: if is True, the fitness score will be used, otherwise, the raw.
:rtype: None

"""
score_list = getPopScores(population, fitness)
pylab.plot(score_list, 'o')
pylab.title("Plot of population score distribution")
pylab.xlabel('Individual')
pylab.ylabel('Score')
pylab.grid(True)
pylab.show()
"""
score_list = getPopScores(population, fitness)
pylab.plot(score_list, 'o')
pylab.title("Plot of population score distribution")
pylab.xlabel('Individual')
pylab.ylabel('Score')
pylab.grid(True)
pylab.show()

def plotHistPopScore(population, fitness=False):
""" Population score distribution histogram

Example:
>>> Interaction.plotHistPopScore(population)

:param population: population object (:class:`GPopulation.GPopulation`)
:param fitness: if is True, the fitness score will be used, otherwise, the raw.
:rtype: None

"""
score_list = getPopScores(population, fitness)
n, bins, patches = pylab.hist(score_list, 50, facecolor='green', alpha=0.75, normed=1)
pylab.plot(bins, pylab.normpdf(bins, numpy.mean(score_list), numpy.std(score_list)), 'r--')
pylab.xlabel('Score')
pylab.ylabel('Frequency')
pylab.grid(True)
pylab.title("Plot of population score distribution")
pylab.show()

def plotHistPopScore(population, fitness=False):
""" Population score distribution histogram

Example:
>>> Interaction.plotHistPopScore(population)

:param population: population object (:class:`GPopulation.GPopulation`)
:param fitness: if is True, the fitness score will be used, otherwise, the raw.
:rtype: None

"""
score_list = getPopScores(population, fitness)
n, bins, patches = pylab.hist(score_list, 50, facecolor='green', alpha=0.75, normed=1)
pylab.plot(bins, pylab.normpdf(bins, numpy.mean(score_list), numpy.std(score_list)), 'r--')
pylab.xlabel('Score')
pylab.ylabel('Frequency')
pylab.grid(True)
pylab.title("Plot of population score distribution")
pylab.show()
Loading