/usr/share/pyshared/pyevolve/Interaction.py is in python-pyevolve 0.6~rc1+svn398+dfsg-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | """
:mod:`Interaction` -- interaction module
==========================================================================
In this module, you will find the funcionality for the :term:`Interactive mode`.
When you enter in the Interactive Mode, Pyevolve will automatic import this module
and exposes to you in the name space called "it".
To use this mode, the parameter *interactiveMode* must be enabled in the
:class:`GSimpleGA.GSimpleGA`.
You can use the manual method to enter in the Interactive Mode at specific
generation using the :meth:`GSimpleGA.GSimpleGA.setInteractiveGeneration` method.
"""
import logging
try:
import pylab
except:
logging.debug("cannot import Matplotlib ! Plots will not be available !")
print "Warning: cannot import Matplotlib ! Plots will not be available !"
try:
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 !"
def getPopScores(population, fitness=False):
""" Returns a list of population scores
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
"""
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
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
"""
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()
|