rtcus_cognitive: deap | ghmm | ros_soar | rtcus_kinect_gestures | soar
Package Summary
This package is a wrapper of the "Distributed evolutionary algorithms in python" designed and developed by François-Michel De Rainville, Félix-Antoine Fortin and Marc-André Gardner. It is useful to research about evolutive robotics or as a mechanism to solve optimization problems.
- Author: Pablo Iñigo Blasco
- License: LGPL
- Repository: rtc-us-ros-pkg
- Source: svn https://rtc-us-ros-pkg.svn.sourceforge.net/svnroot/rtc-us-ros-pkg/trunk/rtcus_cognitive/deap
Contents
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 if __name__ == "__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 algorithms.eaSimple(population, cxpb=CXPB, mutpb=MUTPB,
41 ngen=NGEN)
42 # Find the best individual in the resulting population
43 population.sort(key=lambda ind: ind.fitness, reverse=True)
44
45 # Do something with that individual
46 # ...
For more example see DEAP's http://readthedocs.org/docs/deap/en/latest/.






