~ubuntu-branches/ubuntu/utopic/deap/utopic-proposed

« back to all changes in this revision

Viewing changes to examples/ga_onemax_numpy.py

  • Committer: Package Import Robot
  • Author(s): Daniel Stender, Miriam Ruiz, Daniel Stender, Jakub Wilk
  • Date: 2014-07-06 00:03:41 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20140706000341-s7gij1ki3d8xz6t9
Tags: 1.0.1-1
[ Miriam Ruiz ]
* New Upstream Release. Closes: #675200
* Upgraded Standards-Version from 3.9.2 to 3.9.5
* Switched to dh_python2
* Upgraded debian/compat to 9
* Added build-arch and build-indep targets to debian/rules
* Using awk to remove connection from the documentation to google analytics
* Using jquery.js and underscore.js from libjs-jquery and libjs-underscore
* Added patches/doc.patch

[ Daniel Stender ]
* deb/control:
  + Added myself to Uploaders.
  + Added version to b-p on python-all.
  + Updated Homepage.
  + Wrapped and sorted.
* deb/copyright:
  + Changed copyright file towards DEP-5.
  + Updated Source URI (project source moved to Github).
  + Added email addresses for copyright holders.
  + Dropped license for eap/toolbox.py (not included anymore).
  + Extended copyrights to 2014.
  + Added myself to copyrights for deb/*.
  + Specified license location.
* Added watch file [initial version by Jackson Doak].

[ Jakub Wilk ]
* Use canonical URIs for Vcs-* fields.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#    This file is part of DEAP.
2
 
#
3
 
#    DEAP is free software: you can redistribute it and/or modify
4
 
#    it under the terms of the GNU Lesser General Public License as
5
 
#    published by the Free Software Foundation, either version 3 of
6
 
#    the License, or (at your option) any later version.
7
 
#
8
 
#    DEAP is distributed in the hope that it will be useful,
9
 
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
 
#    GNU Lesser General Public License for more details.
12
 
#
13
 
#    You should have received a copy of the GNU Lesser General Public
14
 
#    License along with DEAP. If not, see <http://www.gnu.org/licenses/>.
15
 
 
16
 
import numpy
17
 
import sys
18
 
import random
19
 
import logging
20
 
 
21
 
logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)
22
 
 
23
 
from deap import algorithms
24
 
from deap import base
25
 
from deap import creator
26
 
from deap import tools
27
 
 
28
 
creator.create("FitnessMax", base.Fitness, weights=(1.0,))
29
 
creator.create("Individual", numpy.ndarray, fitness=creator.FitnessMax)
30
 
 
31
 
toolbox = base.Toolbox()
32
 
 
33
 
toolbox.register("attr_bool", random.randint, 0, 1)
34
 
toolbox.register("individual", tools.initRepeat, creator.Individual, toolbox.attr_bool, n=100)
35
 
toolbox.register("population", tools.initRepeat, list, toolbox.individual)
36
 
 
37
 
def evalOneMax(individual):
38
 
    return numpy.sum(individual),
39
 
 
40
 
toolbox.register("evaluate", evalOneMax)
41
 
toolbox.register("mate", tools.cxTwoPoints)
42
 
toolbox.register("mutate", tools.mutFlipBit, indpb=0.05)
43
 
toolbox.register("select", tools.selTournament, tournsize=3)
44
 
 
45
 
def main():
46
 
    random.seed(64)
47
 
    
48
 
    pop = toolbox.population(n=300)
49
 
    hof = tools.HallOfFame(1)
50
 
    stats = tools.Statistics(lambda ind: ind.fitness.values)
51
 
    stats.register("Avg", tools.mean)
52
 
    stats.register("Std", tools.std)
53
 
    stats.register("Min", min)
54
 
    stats.register("Max", max)
55
 
    
56
 
    algorithms.eaSimple(toolbox, pop, cxpb=0.5, mutpb=0.2, ngen=40, stats=stats, halloffame=hof)
57
 
    
58
 
    return pop, stats, hof
59
 
 
60
 
if __name__ == "__main__":
61
 
    main()