Skip to content

Commit

Permalink
Remove prefix category from each example filename.
Browse files Browse the repository at this point in the history
The examples that import other examples are also modified
to fit the new module name.

--HG--
branch : dev
rename : examples/coev/coev_coop_adapt.py => examples/coev/coop_adapt.py
rename : examples/coev/coev_coop_base.py => examples/coev/coop_base.py
rename : examples/coev/coev_coop_evol.py => examples/coev/coop_evol.py
rename : examples/coev/coev_coop_gen.py => examples/coev/coop_gen.py
rename : examples/coev/coev_coop_niche.py => examples/coev/coop_niche.py
rename : examples/coev/coev_hillis.py => examples/coev/hillis.py
rename : examples/coev/coev_symbreg.py => examples/coev/symbreg.py
rename : examples/de/de_basic.py => examples/de/basic.py
rename : examples/de/de_dynamic.py => examples/de/dynamic.py
rename : examples/de/de_sphere.py => examples/de/sphere.py
rename : examples/eda/eda_fctmin.py => examples/eda/fctmin.py
rename : examples/eda/eda_pbil.py => examples/eda/pbil.py
rename : examples/es/cmaes1pl_minfct.py => examples/es/cma_1+l_minfct.py
rename : examples/es/cmaes_bipop.py => examples/es/cma_bipop.py
rename : examples/es/cmaes_minfct.py => examples/es/cma_minfct.py
rename : examples/es/cmaes_plotting.py => examples/es/cma_plotting.py
rename : examples/es/es_fctmin.py => examples/es/fctmin.py
rename : examples/es/es_onefifth.py => examples/es/onefifth.py
rename : examples/ga/ga_knn.py => examples/ga/evoknn.py
rename : examples/ga/ga_knn_jmlr.py => examples/ga/evoknn_jmlr.py
rename : examples/ga/ga_evosn.py => examples/ga/evosn.py
rename : examples/ga/ga_knapsack.py => examples/ga/knapsack.py
rename : examples/ga/ga_kursawefct.py => examples/ga/kursawefct.py
rename : examples/ga/ga_nqueens.py => examples/ga/nqueens.py
rename : examples/ga/ga_nsga2.py => examples/ga/nsga2.py
rename : examples/ga/ga_onemax.py => examples/ga/onemax.py
rename : examples/ga/ga_onemax_island.py => examples/ga/onemax_island.py
rename : examples/ga/ga_onemax_mp.py => examples/ga/onemax_mp.py
rename : examples/ga/ga_onemax_multidemic.py => examples/ga/onemax_multidemic.py
rename : examples/ga/ga_onemax_numpy.py => examples/ga/onemax_numpy.py
rename : examples/ga/ga_onemax_short.py => examples/ga/onemax_short.py
rename : examples/ga/ga_tsp.py => examples/ga/tsp.py
rename : examples/gp/gp_adf_symbreg.py => examples/gp/adf_symbreg.py
rename : examples/gp/gp_ant.py => examples/gp/ant.py
rename : examples/gp/gp_multiplexer.py => examples/gp/multiplexer.py
rename : examples/gp/gp_parity.py => examples/gp/parity.py
rename : examples/gp/gp_spambase.py => examples/gp/spambase.py
rename : examples/gp/gp_symbreg.py => examples/gp/symbreg.py
rename : examples/gp/gp_symbreg_numpy.py => examples/gp/symbreg_numpy.py
rename : examples/pso/pso_basic.py => examples/pso/basic.py
rename : examples/pso/pso_multiswarm.py => examples/pso/multiswarm.py
rename : examples/pso/pso_speciation.py => examples/pso/speciation.py
  • Loading branch information
cmd-ntrf authored and felix.antoine.fortin committed Jun 10, 2013
1 parent 22f30e1 commit f5d5535
Show file tree
Hide file tree
Showing 43 changed files with 64 additions and 72 deletions.
10 changes: 5 additions & 5 deletions examples/coev/coev_coop_adapt.py → examples/coev/coop_adapt.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
from deap import algorithms
from deap import tools

import coev_coop_base
import coop_base

IND_SIZE = coev_coop_base.IND_SIZE
SPECIES_SIZE = coev_coop_base.SPECIES_SIZE
IND_SIZE = coop_base.IND_SIZE
SPECIES_SIZE = coop_base.SPECIES_SIZE
TARGET_SIZE = 30
NUM_SPECIES = 1

Expand All @@ -41,9 +41,9 @@
"1##1###1###11111##1##1000#0##0###0#0000##000000##0#00#0#00######",
"0##0###0###00000##0##0000#0##0###0#0000##001111##1#11#1#11######")

toolbox = coev_coop_base.toolbox
toolbox = coop_base.toolbox
if plt:
toolbox.register("evaluate_nonoise", coev_coop_base.matchSetStrengthNoNoise)
toolbox.register("evaluate_nonoise", coop_base.matchSetStrengthNoNoise)

def main(extended=True, verbose=True):
target_set = []
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions examples/coev/coev_coop_evol.py → examples/coev/coop_evol.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
from deap import algorithms
from deap import tools

import coev_coop_base
import coop_base

IND_SIZE = coev_coop_base.IND_SIZE
SPECIES_SIZE = coev_coop_base.SPECIES_SIZE
IND_SIZE = coop_base.IND_SIZE
SPECIES_SIZE = coop_base.SPECIES_SIZE
NUM_SPECIES = 1
TARGET_SIZE = 30
IMPROVMENT_TRESHOLD = 0.5
Expand All @@ -47,8 +47,8 @@
"1##1###1###11111##1##1000#0##0###0#0000##000000##0#00#0#00######",
"0##0###0###00000##0##0000#0##0###0#0000##001111##1#11#1#11######")

toolbox = coev_coop_base.toolbox
toolbox.register("evaluateContribution", coev_coop_base.matchSetContribution)
toolbox = coop_base.toolbox
toolbox.register("evaluateContribution", coop_base.matchSetContribution)

def main(extended=True, verbose=True):
target_set = []
Expand Down
10 changes: 5 additions & 5 deletions examples/coev/coev_coop_gen.py → examples/coev/coop_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
from deap import algorithms
from deap import tools

import coev_coop_base
import coop_base

IND_SIZE = coev_coop_base.IND_SIZE
SPECIES_SIZE = coev_coop_base.SPECIES_SIZE
IND_SIZE = coop_base.IND_SIZE
SPECIES_SIZE = coop_base.SPECIES_SIZE
NUM_SPECIES = 4
TARGET_SIZE = 30

Expand All @@ -42,10 +42,10 @@
"1##1###1###11111##1##1000#0##0###0#0000##000000##0#00#0#00######",
"0##0###0###00000##0##0000#0##0###0#0000##001111##1#11#1#11######")

toolbox = coev_coop_base.toolbox
toolbox = coop_base.toolbox
if plt:
# This will allow to plot the match strength of every target schemata
toolbox.register("evaluate_nonoise", coev_coop_base.matchSetStrengthNoNoise)
toolbox.register("evaluate_nonoise", coop_base.matchSetStrengthNoNoise)

def main(extended=True, verbose=True):
target_set = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
from deap import algorithms
from deap import tools

import coev_coop_base
import coop_base

IND_SIZE = coev_coop_base.IND_SIZE
SPECIES_SIZE = coev_coop_base.SPECIES_SIZE
IND_SIZE = coop_base.IND_SIZE
SPECIES_SIZE = coop_base.SPECIES_SIZE
TARGET_SIZE = 200
TARGET_TYPE = 2

Expand All @@ -41,7 +41,7 @@ def nicheSchematas(type, size):
rept = int(size/type)
return ["#" * (i*rept) + "1" * rept + "#" * ((type-i-1)*rept) for i in range(type)]

toolbox = coev_coop_base.toolbox
toolbox = coop_base.toolbox

def main(extended=True, verbose=True):
target_set = []
Expand Down
File renamed without changes.
77 changes: 28 additions & 49 deletions examples/coev/coev_symbreg.py → examples/coev/symbreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,17 @@

from deap import base
from deap import creator
from deap import gp
from deap import tools

sys.path.append("../gp")
from deap.gp import stringify

# gp_symbreg already defines some useful structures
import gp_symbreg
# GP example "symbreg.py" already defines some useful structures
sys.path.append("..")
import gp.symbreg as symbreg

creator.create("FitnessMax", base.Fitness, weights=(1.0,))
creator.create("IndGA", list, fitness=creator.FitnessMax)

def refFunc(x):
return x**4 + x**3 + x**2 + x

def evalSymbReg(expr, data):
# Transform the tree expression in a callable function
func = tools_gp.lambdify(expr=expr)
# Evaluate the sum of squared difference between the expression
# and the real function : x**4 + x**3 + x**2 + x
values = data
diff_func = lambda x: (func(x)-refFunc(x))**2
diff = sum(map(diff_func, values))
return diff,

toolbox_ga = base.Toolbox()

toolbox_ga.register("float", random.uniform, -1, 1)
Expand All @@ -54,47 +41,40 @@ def evalSymbReg(expr, data):
toolbox_ga.register("mate", tools.cxTwoPoints)
toolbox_ga.register("mutate", tools.mutGaussian, mu=0, sigma=0.01, indpb=0.05)

tools_gp = gp_symbreg.toolbox
toolbox_gp = symbreg.toolbox

def main():
pop_ga = toolbox_ga.population(n=200)
pop_gp = tools_gp.population(n=200)

stats_ga = tools.Statistics(lambda ind: ind.fitness.values)
stats_ga.register("avg", numpy.mean)
stats_ga.register("std", numpy.std)
stats_ga.register("min", numpy.min)
stats_ga.register("max", numpy.max)
pop_gp = toolbox_gp.population(n=200)

stats_gp = tools.Statistics(lambda ind: ind.fitness.values)
stats_gp.register("avg", numpy.mean)
stats_gp.register("std", numpy.std)
stats_gp.register("min", numpy.min)
stats_gp.register("max", numpy.max)
stats = tools.Statistics(lambda ind: ind.fitness.values)
stats.register("avg", numpy.mean)
stats.register("std", numpy.std)
stats.register("min", numpy.min)
stats.register("max", numpy.max)

best_ga = tools.selRandom(pop_ga, 1)[0]
best_gp = tools.selRandom(pop_gp, 1)[0]

for ind in pop_gp:
ind.fitness.values = evalSymbReg(ind, best_ga)
ind.fitness.values = toolbox_gp.evaluate(ind, points=best_ga)

for ind in pop_ga:
ind.fitness.values = evalSymbReg(best_gp, ind)
ind.fitness.values = toolbox_gp.evaluate(best_gp, points=ind)

stats_ga.record(pop_ga, gen=0, type='ga', evals=len(pop_ga))
stats_gp.record(pop_gp, gen=0, type='gp', evals=len(pop_gp))
print(stats_ga.stream)
print(stats_gp.stream)
stats.record(pop_ga, gen=0, type='ga', evals=len(pop_ga))
stats.record(pop_gp, gen=0, type='gp', evals=len(pop_gp))
print(stats.stream)

CXPB, MUTPB, NGEN = 0.5, 0.2, 50

# Begin the evolution
for g in range(1, NGEN):
# Select and clone the offspring
off_ga = toolbox_ga.select(pop_ga, len(pop_ga))
off_gp = tools_gp.select(pop_gp, len(pop_gp))
off_gp = toolbox_gp.select(pop_gp, len(pop_gp))
off_ga = [toolbox_ga.clone(ind) for ind in off_ga]
off_gp = [tools_gp.clone(ind) for ind in off_gp]
off_gp = [toolbox_gp.clone(ind) for ind in off_gp]


# Apply crossover and mutation
Expand All @@ -106,7 +86,7 @@ def main():

for ind1, ind2 in zip(off_gp[::2], off_gp[1::2]):
if random.random() < CXPB:
tools_gp.mate(ind1, ind2)
toolbox_gp.mate(ind1, ind2)
del ind1.fitness.values
del ind2.fitness.values

Expand All @@ -117,33 +97,32 @@ def main():

for ind in off_gp:
if random.random() < MUTPB:
tools_gp.mutate(ind)
toolbox_gp.mutate(ind)
del ind.fitness.values

# Evaluate the individuals with an invalid fitness
for ind in off_ga:
ind.fitness.values = evalSymbReg(best_gp, ind)
ind.fitness.values = toolbox_gp.evaluate(best_gp, points=ind)

for ind in off_gp:
ind.fitness.values = evalSymbReg(ind, best_ga)
ind.fitness.values = toolbox_gp.evaluate(ind, points=best_ga)

# Replace the old population by the offspring
pop_ga = off_ga
pop_gp = off_gp

stats_ga.record(pop_ga, gen=g, type='ga', evals=len(pop_ga))
stats_gp.record(pop_gp, gen=g, type='gp', evals=len(pop_gp))
print(stats_ga.stream)
print(stats_gp.stream)
stats.record(pop_ga, gen=g, type='ga', evals=len(pop_ga))
stats.record(pop_gp, gen=g, type='gp', evals=len(pop_gp))
print(stats.stream)

best_ga = tools.selBest(pop_ga, 1)[0]
best_gp = tools.selBest(pop_gp, 1)[0]
best_gp = tools.selBest(pop_gp, 1)[0]


print("Best individual GA is %s, %s" % (best_ga, best_ga.fitness.values))
print("Best individual GP is %s, %s" % (gp.stringify(best_gp), best_gp.fitness.values))
print("Best individual GP is %s, %s" % (stringify(best_gp), best_gp.fitness.values))

return pop_ga, pop_gp, stats_ga, stats_gp, best_ga, best_gp
return pop_ga, pop_gp, best_ga, best_gp, stats

if __name__ == "__main__":
main()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions examples/gp/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# This file is part of DEAP.
#
# DEAP is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
#
# DEAP is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with DEAP. If not, see <http://www.gnu.org/licenses/>.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 3 additions & 4 deletions examples/gp/gp_symbreg.py → examples/gp/symbreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,16 @@ def safeDiv(left, right):
toolbox.register("population", tools.initRepeat, list, toolbox.individual)
toolbox.register("lambdify", gp.lambdify, pset=pset)

def evalSymbReg(individual):
def evalSymbReg(individual, points):
# Transform the tree expression in a callable function
func = toolbox.lambdify(expr=individual)
# Evaluate the sum of squared difference between the expression
# and the real function : x**4 + x**3 + x**2 + x
values = (x/10. for x in range(-10,10))
diff_func = lambda x: (func(x)-(x**4 + x**3 + x**2 + x))**2
diff = sum(map(diff_func, values))
diff = sum(map(diff_func, points))
return diff,

toolbox.register("evaluate", evalSymbReg)
toolbox.register("evaluate", evalSymbReg, points=[x/10. for x in range(-10,10)])
toolbox.register("select", tools.selTournament, tournsize=3)
toolbox.register("mate", gp.cxOnePoint)
toolbox.register("expr_mut", gp.genFull, min_=0, max_=2)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit f5d5535

Please sign in to comment.