Documentation Status

Cannot load information on name: deap, distro: electric, which means that it is not yet in our index. Please see this page for information on how to submit your repository to our index.
Cannot load information on name: deap, distro: fuerte, which means that it is not yet in our index. Please see this page for information on how to submit your repository to our index.
Cannot load information on name: deap, distro: groovy, which means that it is not yet in our index. Please see this page for information on how to submit your repository to our index.
Cannot load information on name: deap, distro: hydro, which means that it is not yet in our index. Please see this page for information on how to submit your repository to our index.

Installation

DEAP is in the ROS dependency system (rosdep). On Ubuntu, simply add

   1     <rosdep name="python-deap-pip"/>

this will install the latest version of DEAP in the system python. For any other configuration use pip directly.

pip install deap

Or refer to DEAP's homepage for more information.

DEAP

This is the ROS documentation for DEAP a distributed evolutionary algorithm written in Python. As DEAP is completly independent of ROS we suggest to install the latest version in your python directory either by downloading the latest version or the mercurial tip or using pip. The complete API documentation is available here.

Using DEAP as a Node

DEAP is used with ROS as independent as any other python package would be. The only difference is that the optimizer will probably call some ROS service. Here is a brief example of how to optimize the position of some robot according to a some fitness function.

   1 import roslib; roslib.load_manifest('my_optimization_package')
   2 import random, math
   3 from deap import creator, base, tools, algorithms
   4 
   5 creator.create("FitnessMax", base.Fitness, weights=(1.0,))
   6 creator.create("Individual", list, fitness=creator.FitnessMax)
   7 
   8 toolbox = base.Toolbox()
   9 
  10 # Helper function to generate pose 3-tuple
  11 def poseGenerator(icls, xmin, xmax, ymin, ymax):
  12     """Simple function to generate a random robot position and fill the
  13     *icls* class with it, *icls* must be initializable from an iterable.
  14     The robot position is generated in 2D (x, y, theta) with 
  15     *xmin* <= x <= *xmax*, *ymin* <= y <= ymax and 0 <= theta <= pi."""
  16     return icls([random.uniform(xmin, xmax),
  17                  random.uniform(ymin, ymax),
  18                  random.uniform(0, 2*math.pi)])
  19 
  20 
  21 # Structure initializers
  22 toolbox.register("individual", poseGenerator, creator.Individual,
  23                  xmin=-2, xmax=2, ymin=-2, ymax=2)
  24 toolbox.register("population", tools.initRepeat, list, toolbox.individual)
  25 
  26 def evalPose(individual):
  27     """Function that evaluates the fitness (goodness) of a pose."""
  28     # Usualy the calls to ROS will be here
  29 
  30 toolbox.register("evaluate", evalPose)
  31 toolbox.register("mate", tools.cxTwoPoints)
  32 toolbox.register("mutate", tools.mutGaussian, mu=0, sigma=1.0, indpb=0.05)
  33 toolbox.register("select", tools.selTournament, tournsize=3)
  34 
  35 def main():
  36     # Create a population of 300 individuals
  37     population = toolbox.population(n=300)
  38     CXPB, MUTPB, NGEN = 0.6, 0.4, 50
  39 
  40     population = algorithms.eaSimple(population, toolbox, cxpb=CXPB,
  41         mutpb=MUTPB, ngen=NGEN)
  42     
  43     # Find the best individual(s) in the resulting population
  44     # This returns a list
  45     bests = tools.selBest(population, k=1)
  46     
  47     # An individual is a complex object containing a fitness,
  48     # This will return only a three-tuple position (x, y, theta)
  49     return tuple(bests[0])
  50 
  51 if __name__ == "__main__":
  52     pose = main()
  53     
  54     # Send that pose to some other ROS node.
  55     # ...

For more example see DEAP's http://readthedocs.org/docs/deap/en/latest/.

Wiki: deap (last edited 2012-08-14 16:01:17 by Francois-Michel De Rainville)