Skip to content

Commit

Permalink
Merge branch 'master' into mo-cma-es
Browse files Browse the repository at this point in the history
Conflicts:
	setup.py
  • Loading branch information
fmder committed May 25, 2014
2 parents ab6c4ed + 965eba4 commit a6c2447
Show file tree
Hide file tree
Showing 12 changed files with 173 additions and 92 deletions.
3 changes: 0 additions & 3 deletions .hgignore → .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# use glob syntax
syntax: glob

# folders to ignore
build/
dist/
Expand Down
54 changes: 0 additions & 54 deletions .hgtags

This file was deleted.

2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include *.txt
recursive-include deap *.cpp
recursive-include examples *.py *.csv *.json
recursive-include examples *.py *.csv *.json *.txt *.cpp *.hpp
recursive-include doc *
prune doc/_build
global-exclude .DS_Store
Expand Down
131 changes: 131 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# DEAP

DEAP is a novel evolutionary computation framework for rapid prototyping and testing of
ideas. It seeks to make algorithms explicit and data structures transparent. It works in perfect harmony with parallelisation mechanism such as multiprocessing and [SCOOP](http://scoop.googlecode.com).

DEAP includes the following features:
* Genetic algorithm using any imaginable representation
* List, Array, Set, Dictionary, Tree, Numpy Array, etc.
* Genetic programing using prefix trees
* Loosely typed, Strongly typed
* Automatically defined functions
* Evolution strategies (including CMA-ES)
* Multi-objective optimisation (NSGA-II, SPEA-II)
* Co-evolution (cooperative and competitive) of multiple populations
* Parallelization of the evaluations (and more)
* Hall of Fame of the best individuals that lived in the population
* Checkpoints that take snapshots of a system regularly
* Benchmarks module containing most common test functions
* Genealogy of an evolution (that is compatible with [NetworkX](http://networkx.lanl.gov))
* Examples of alternative algorithms : Particle Swarm Optimization, Differential Evolution, Estimation of Distribution Algorithm

## Downloads

Following acceptation of [PEP 438](http://www.python.org/dev/peps/pep-0438/) by the Python community, we have moved DEAP's source releases on [PyPI](https://pypi.python.org).

You can find the most recent releases at: https://pypi.python.org/pypi/deap/.

## Documentation
See the [DEAP User's Guide](http://deap.gel.ulaval.ca/doc/default/index.html) for DEAP documentation.

In order to get the tip documentation, change directory to the `doc` subfolder and type in `make html`, the documentation will be under `_build/html`. You will need [Sphinx](http://sphinx.pocoo.org) to build the documentation.

### Notebooks
Also checkout our new [notebook examples](https://github.com/DEAP/notebook). Using [IPython's](http://ipython.org/) notebook feature you'll be able to navigate and execute each block of code individually and fell what every line is doing. Either, look at the notebooks online using the notebook viewer links at the botom of the page or download the notebooks, navigate to the you download directory and run

```bash
ipython notebook --pylab inline
```

## Installation
We encourage you to use easy_install or pip to install DEAP on your system. Other installation procedure like apt-get, yum, etc. usually provide an outdated version.

```bash
pip install deap
```

If you wish to build from sources, download or clone the repository and type

```bash
python setup.py install
```

## Requirements
The most basic features of DEAP requires Python2.6. In order to combine the toolbox and the multiprocessing module Python2.7 is needed for its support to pickle partial functions. CMA-ES requires Numpy, and we recommend matplotlib for visualization of results as it is fully compatible with DEAP's API.

Since version 0.8, DEAP is compatible out of the box with Python 3. The installation procedure automatically translates the source to Python 3 with 2to3.

## Example

The following code gives a quick overview how simple it is to implement the Onemax problem optimization with genetic algorithm using DEAP. More examples are provided [here](http://deap.gel.ulaval.ca/doc/default/examples/index.html).

```python
import array, random
from deap import creator, base, tools, algorithms

creator.create("FitnessMax", base.Fitness, weights=(1.0,))
creator.create("Individual", array.array, typecode='b', fitness=creator.FitnessMax)

toolbox = base.Toolbox()

toolbox.register("attr_bool", random.randint, 0, 1)
toolbox.register("individual", tools.initRepeat, creator.Individual, toolbox.attr_bool, 100)
toolbox.register("population", tools.initRepeat, list, toolbox.individual)

def evalOneMax(individual):
return sum(individual),

toolbox.register("evaluate", evalOneMax)
toolbox.register("mate", tools.cxTwoPoint)
toolbox.register("mutate", tools.mutFlipBit, indpb=0.05)
toolbox.register("select", tools.selTournament, tournsize=3)

population = toolbox.population(n=300)

NGEN=40
for gen in range(NGEN):
offspring = algorithms.varAnd(population, toolbox, cxpb=0.5, mutpb=0.1)
fits = toolbox.map(toolbox.evaluate, offspring)
for fit, ind in zip(fits, offspring):
ind.fitness.values = fit
population = offspring
```

## How to cite DEAP
Authors of scientific papers including results generated using DEAP are encouraged to cite the following paper.

```xml
@article{DEAP_JMLR2012,
author = " F\'elix-Antoine Fortin and Fran\c{c}ois-Michel {De Rainville} and Marc-Andr\'e Gardner and Marc Parizeau and Christian Gagn\'e ",
title = { {DEAP}: Evolutionary Algorithms Made Easy },
pages = { 2171--2175 },
volume = { 13 },
month = { jul },
year = { 2012 },
journal = { Journal of Machine Learning Research }
}
```

## Publications on DEAP

* François-Michel De Rainville, Félix-Antoine Fortin, Marc-André Gardner, Marc Parizeau and Christian Gagné, "DEAP -- Enabling Nimbler Evolutions", SIGEVOlution, vol. 6, no 2, pp. 17-26, February 2014. [Paper](http://goo.gl/tOrXTp)
* Félix-Antoine Fortin, François-Michel De Rainville, Marc-André Gardner, Marc Parizeau and Christian Gagné, "DEAP: Evolutionary Algorithms Made Easy", Journal of Machine Learning Research, vol. 13, pp. 2171-2175, jul 2012. [Paper](http://goo.gl/amJ3x)
* François-Michel De Rainville, Félix-Antoine Fortin, Marc-André Gardner, Marc Parizeau and Christian Gagné, "DEAP: A Python Framework for Evolutionary Algorithms", in !EvoSoft Workshop, Companion proc. of the Genetic and Evolutionary Computation Conference (GECCO 2012), July 07-11 2012. [Paper](http://goo.gl/pXXug)

## Projects using DEAP
* Macret, M. and Pasquier, P. (2013). Automatic Tuning of the OP-1 Synthesizer Using a Multi-objective Genetic Algorithm. In Proceedings of the 10th Sound and Music Computing Conference (SMC). (pp 614-621).
* Fortin, F. A., Grenier, S., & Parizeau, M. (2013, July). Generalizing the improved run-time complexity algorithm for non-dominated sorting. In Proceeding of the fifteenth annual conference on Genetic and evolutionary computation conference (pp. 615-622). ACM.
* Fortin, F. A., & Parizeau, M. (2013, July). Revisiting the NSGA-II crowding-distance computation. In Proceeding of the fifteenth annual conference on Genetic and evolutionary computation conference (pp. 623-630). ACM.
* Marc-André Gardner, Christian Gagné, and Marc Parizeau. Estimation of Distribution Algorithm based on Hidden Markov Models for Combinatorial Optimization. in Comp. Proc. Genetic and Evolutionary Computation Conference (GECCO 2013), July 2013.
* J. T. Zhai, M. A. Bamakhrama, and T. Stefanov. "Exploiting Just-enough Parallelism when Mapping Streaming Applications in Hard Real-time Systems". Design Automation Conference (DAC 2013), 2013.
* V. Akbarzadeh, C. Gagné, M. Parizeau, M. Argany, M. A Mostafavi, "Probabilistic Sensing Model for Sensor Placement Optimization Based on Line-of-Sight Coverage", Accepted in IEEE Transactions on Instrumentation and Measurement, 2012.
* M. Reif, F. Shafait, and A. Dengel. "Dataset Generation for Meta-Learning". Proceedings of the German Conference on Artificial Intelligence (KI'12). 2012.
* M. T. Ribeiro, A. Lacerda, A. Veloso, and N. Ziviani. "Pareto-Efficient Hybridization for Multi-Objective Recommender Systems". Proceedings of the Conference on Recommanders Systems (!RecSys'12). 2012.
* M. Pérez-Ortiz, A. Arauzo-Azofra, C. Hervás-Martínez, L. García-Hernández and L. Salas-Morera. "A system learning user preferences for multiobjective optimization of facility layouts". Pr,oceedings on the Int. Conference on Soft Computing Models in Industrial and Environmental Applications (SOCO'12). 2012.
* Lévesque, J.C., Durand, A., Gagné, C., and Sabourin, R., Multi-Objective Evolutionary Optimization for Generating Ensembles of Classifiers in the ROC Space, Genetic and Evolutionary Computation Conference (GECCO 2012), 2012.
* Marc-André Gardner, Christian Gagné, and Marc Parizeau, "Bloat Control in Genetic Programming with Histogram-based Accept-Reject Method", in Proc. Genetic and Evolutionary Computation Conference (GECCO 2011), 2011.
* Vahab Akbarzadeh, Albert Ko, Christian Gagné, and Marc Parizeau, "Topography-Aware Sensor Deployment Optimization with CMA-ES", in Proc. of Parallel Problem Solving from Nature (PPSN 2010), Springer, 2010.
* DEAP is also used in ROS as an optimization package http://www.ros.org/wiki/deap.
* DEAP is an optional dependency for [PyXRD](https://github.com/mathijs-dumon/PyXRD), a Python implementation of the matrix algorithm developed for the X-ray diffraction analysis of disordered lamellar structures.

If you want your project listed here, send us a link and a brief description and we'll be glad to add it.
9 changes: 0 additions & 9 deletions README.txt

This file was deleted.

24 changes: 12 additions & 12 deletions deap/creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ def __reduce__(self):
return (self.__class__, (list(self),), self.__dict__)
class_replacers[array.array] = _array

def create(classname, baseclass, **kargs):
"""Creates a new class named *classname* inheriting from *baseclass* in the
def create(name, base, **kargs):
"""Creates a new class named *name* inheriting from *base* in the
:mod:`~deap.creator` module. The new class can have attributes defined by
the subsequent keyword arguments passed to the function create. If the
argument is a class (without the parenthesis), the __init__ function is
Expand All @@ -101,8 +101,8 @@ def create(classname, baseclass, **kargs):
Otherwise, if the argument is not a class, (for example an :class:`int`),
it is added as a "static" attribute of the class.
:param classname: The name of the class to create.
:param baseclass: A base class from which to inherit.
:param name: The name of the class to create.
:param base: A base class from which to inherit.
:param attribute: One or more attributes to add on instanciation of this
class, optional.
Expand All @@ -125,10 +125,10 @@ def __init__(self):
usage.
"""

if classname in globals():
if name in globals():
warnings.warn("A class named '{0}' has already been created and it "
"will be overwritten. Consider deleting previous "
"creation of that class or rename it.".format(classname),
"creation of that class or rename it.".format(name),
RuntimeWarning)

dict_inst = {}
Expand All @@ -140,8 +140,8 @@ def __init__(self):
dict_cls[obj_name] = obj

# Check if the base class has to be replaced
if baseclass in class_replacers:
baseclass = class_replacers[baseclass]
if base in class_replacers:
base = class_replacers[base]

# A DeprecationWarning is raised when the object inherits from the
# class "object" which leave the option of passing arguments, but
Expand All @@ -154,9 +154,9 @@ def initType(self, *args, **kargs):
"""
for obj_name, obj in dict_inst.iteritems():
setattr(self, obj_name, obj())
if baseclass.__init__ is not object.__init__:
baseclass.__init__(self, *args, **kargs)
if base.__init__ is not object.__init__:
base.__init__(self, *args, **kargs)

objtype = type(str(classname), (baseclass,), dict_cls)
objtype = type(str(name), (base,), dict_cls)
objtype.__init__ = initType
globals()[classname] = objtype
globals()[name] = objtype
24 changes: 15 additions & 9 deletions deap/gp.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,31 +487,33 @@ def compileADF(expr, psets):
######################################
# GP Program generation functions #
######################################
def genFull(pset, min_, max_, type_=__type__):
def genFull(pset, min_, max_, type_=None):
"""Generate an expression where each leaf has a the same depth
between *min* and *max*.
:param pset: Primitive set from which primitives are selected.
:param min_: Minimum height of the produced trees.
:param max_: Maximum Height of the produced trees.
:param type_: The type that should return the tree when called, when
:obj:`None` (default) no return type is enforced.
:obj:`None` (default) the type of :pset: (pset.ret)
is assumed.
:returns: A full tree with all leaves at the same depth.
"""
def condition(height, depth):
"""Expression generation stops when the depth is equal to height."""
return depth == height
return generate(pset, min_, max_, condition, type_)

def genGrow(pset, min_, max_, type_=__type__):
def genGrow(pset, min_, max_, type_=None):
"""Generate an expression where each leaf might have a different depth
between *min* and *max*.
:param pset: Primitive set from which primitives are selected.
:param min_: Minimum height of the produced trees.
:param max_: Maximum Height of the produced trees.
:param type_: The type that should return the tree when called, when
:obj:`None` (default) no return type is enforced.
:obj:`None` (default) the type of :pset: (pset.ret)
is assumed.
:returns: A grown tree with leaves at possibly different depths.
"""
def condition(height, depth):
Expand All @@ -522,7 +524,7 @@ def condition(height, depth):
(depth >= min_ and random.random() < pset.terminalRatio)
return generate(pset, min_, max_, condition, type_)

def genHalfAndHalf(pset, min_, max_, type_=__type__):
def genHalfAndHalf(pset, min_, max_, type_=None):
"""Generate an expression with a PrimitiveSet *pset*.
Half the time, the expression is generated with :func:`~deap.gp.genGrow`,
the other half, the expression is generated with :func:`~deap.gp.genFull`.
Expand All @@ -531,13 +533,14 @@ def genHalfAndHalf(pset, min_, max_, type_=__type__):
:param min_: Minimum height of the produced trees.
:param max_: Maximum Height of the produced trees.
:param type_: The type that should return the tree when called, when
:obj:`None` (default) no return type is enforced.
:obj:`None` (default) the type of :pset: (pset.ret)
is assumed.
:returns: Either, a full or a grown tree.
"""
method = random.choice((genGrow, genFull))
return method(pset, min_, max_, type_)

def genRamped(pset, min_, max_, type_=__type__):
def genRamped(pset, min_, max_, type_=None):
"""
.. deprecated:: 1.0
The function has been renamed. Use :func:`~deap.gp.genHalfAndHalf` instead.
Expand All @@ -546,7 +549,7 @@ def genRamped(pset, min_, max_, type_=__type__):
FutureWarning)
return genHalfAndHalf(pset, min_, max_, type_)

def generate(pset, min_, max_, condition, type_=__type__):
def generate(pset, min_, max_, condition, type_=None):
"""Generate a Tree as a list of list. The tree is build
from the root to the leaves, and it stop growing when the
condition is fulfilled.
Expand All @@ -558,10 +561,13 @@ def generate(pset, min_, max_, condition, type_=__type__):
the height of the tree to build and the current
depth in the tree.
:param type_: The type that should return the tree when called, when
:obj:`None` (default) no return type is enforced.
:obj:`None` (default) the type of :pset: (pset.ret)
is assumed.
:returns: A grown tree with leaves at possibly different depths
dependending on the condition function.
"""
if type_ is None:
type_ = pset.ret
expr = []
height = random.randint(min_, max_)
stack = [(0, type_)]
Expand Down
2 changes: 1 addition & 1 deletion deap/tools/emo.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def selNSGA2(individuals, k, nd='standard'):
size of *individuals* will be larger than *k* because any individual
present in *individuals* will appear in the returned list at most once.
Having the size of *individuals* equals to *k* will have no effect other
than sorting the population according according to their front rank. The
than sorting the population according to their front rank. The
list returned contains references to the input *individuals*. For more
details on the NSGA-II operator see [Deb2002]_.
Expand Down
Loading

0 comments on commit a6c2447

Please sign in to comment.