From f5d5535452baf184327f089280c5ac9c87a0f16a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix-Antoine=20Fortin?= Date: Mon, 10 Jun 2013 10:28:32 -0400 Subject: [PATCH] Remove prefix category from each example filename. 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 --- .../{coev_coop_adapt.py => coop_adapt.py} | 10 +-- .../coev/{coev_coop_base.py => coop_base.py} | 0 .../coev/{coev_coop_evol.py => coop_evol.py} | 10 +-- .../coev/{coev_coop_gen.py => coop_gen.py} | 10 +-- .../{coev_coop_niche.py => coop_niche.py} | 8 +- examples/coev/{coev_hillis.py => hillis.py} | 0 examples/coev/{coev_symbreg.py => symbreg.py} | 77 +++++++------------ examples/de/{de_basic.py => basic.py} | 0 examples/de/{de_dynamic.py => dynamic.py} | 0 examples/de/{de_sphere.py => sphere.py} | 0 examples/eda/{eda_fctmin.py => fctmin.py} | 0 examples/eda/{eda_pbil.py => pbil.py} | 0 .../{cmaes1pl_minfct.py => cma_1+l_minfct.py} | 0 examples/es/{cmaes_bipop.py => cma_bipop.py} | 0 .../es/{cmaes_minfct.py => cma_minfct.py} | 0 .../es/{cmaes_plotting.py => cma_plotting.py} | 0 examples/es/{es_fctmin.py => fctmin.py} | 0 examples/es/{es_onefifth.py => onefifth.py} | 0 examples/ga/{ga_knn.py => evoknn.py} | 0 .../ga/{ga_knn_jmlr.py => evoknn_jmlr.py} | 0 examples/ga/{ga_evosn.py => evosn.py} | 0 examples/ga/{ga_knapsack.py => knapsack.py} | 0 .../ga/{ga_kursawefct.py => kursawefct.py} | 0 examples/ga/{ga_nqueens.py => nqueens.py} | 0 examples/ga/{ga_nsga2.py => nsga2.py} | 0 examples/ga/{ga_onemax.py => onemax.py} | 0 .../{ga_onemax_island.py => onemax_island.py} | 0 examples/ga/{ga_onemax_mp.py => onemax_mp.py} | 0 ...max_multidemic.py => onemax_multidemic.py} | 0 .../{ga_onemax_numpy.py => onemax_numpy.py} | 0 .../{ga_onemax_short.py => onemax_short.py} | 0 examples/ga/{ga_tsp.py => tsp.py} | 0 examples/gp/__init__.py | 14 ++++ .../gp/{gp_adf_symbreg.py => adf_symbreg.py} | 0 examples/gp/{gp_ant.py => ant.py} | 0 .../gp/{gp_multiplexer.py => multiplexer.py} | 0 examples/gp/{gp_parity.py => parity.py} | 0 examples/gp/{gp_spambase.py => spambase.py} | 0 examples/gp/{gp_symbreg.py => symbreg.py} | 7 +- .../{gp_symbreg_numpy.py => symbreg_numpy.py} | 0 examples/pso/{pso_basic.py => basic.py} | 0 .../pso/{pso_multiswarm.py => multiswarm.py} | 0 .../pso/{pso_speciation.py => speciation.py} | 0 43 files changed, 64 insertions(+), 72 deletions(-) rename examples/coev/{coev_coop_adapt.py => coop_adapt.py} (95%) rename examples/coev/{coev_coop_base.py => coop_base.py} (100%) rename examples/coev/{coev_coop_evol.py => coop_evol.py} (96%) rename examples/coev/{coev_coop_gen.py => coop_gen.py} (95%) rename examples/coev/{coev_coop_niche.py => coop_niche.py} (95%) rename examples/coev/{coev_hillis.py => hillis.py} (100%) rename examples/coev/{coev_symbreg.py => symbreg.py} (59%) rename examples/de/{de_basic.py => basic.py} (100%) rename examples/de/{de_dynamic.py => dynamic.py} (100%) rename examples/de/{de_sphere.py => sphere.py} (100%) rename examples/eda/{eda_fctmin.py => fctmin.py} (100%) rename examples/eda/{eda_pbil.py => pbil.py} (100%) rename examples/es/{cmaes1pl_minfct.py => cma_1+l_minfct.py} (100%) rename examples/es/{cmaes_bipop.py => cma_bipop.py} (100%) rename examples/es/{cmaes_minfct.py => cma_minfct.py} (100%) rename examples/es/{cmaes_plotting.py => cma_plotting.py} (100%) rename examples/es/{es_fctmin.py => fctmin.py} (100%) rename examples/es/{es_onefifth.py => onefifth.py} (100%) rename examples/ga/{ga_knn.py => evoknn.py} (100%) rename examples/ga/{ga_knn_jmlr.py => evoknn_jmlr.py} (100%) rename examples/ga/{ga_evosn.py => evosn.py} (100%) rename examples/ga/{ga_knapsack.py => knapsack.py} (100%) rename examples/ga/{ga_kursawefct.py => kursawefct.py} (100%) rename examples/ga/{ga_nqueens.py => nqueens.py} (100%) rename examples/ga/{ga_nsga2.py => nsga2.py} (100%) rename examples/ga/{ga_onemax.py => onemax.py} (100%) rename examples/ga/{ga_onemax_island.py => onemax_island.py} (100%) rename examples/ga/{ga_onemax_mp.py => onemax_mp.py} (100%) rename examples/ga/{ga_onemax_multidemic.py => onemax_multidemic.py} (100%) rename examples/ga/{ga_onemax_numpy.py => onemax_numpy.py} (100%) rename examples/ga/{ga_onemax_short.py => onemax_short.py} (100%) rename examples/ga/{ga_tsp.py => tsp.py} (100%) create mode 100644 examples/gp/__init__.py rename examples/gp/{gp_adf_symbreg.py => adf_symbreg.py} (100%) rename examples/gp/{gp_ant.py => ant.py} (100%) rename examples/gp/{gp_multiplexer.py => multiplexer.py} (100%) rename examples/gp/{gp_parity.py => parity.py} (100%) rename examples/gp/{gp_spambase.py => spambase.py} (100%) rename examples/gp/{gp_symbreg.py => symbreg.py} (95%) rename examples/gp/{gp_symbreg_numpy.py => symbreg_numpy.py} (100%) rename examples/pso/{pso_basic.py => basic.py} (100%) rename examples/pso/{pso_multiswarm.py => multiswarm.py} (100%) rename examples/pso/{pso_speciation.py => speciation.py} (100%) diff --git a/examples/coev/coev_coop_adapt.py b/examples/coev/coop_adapt.py similarity index 95% rename from examples/coev/coev_coop_adapt.py rename to examples/coev/coop_adapt.py index 5bf7add31..df0704ca1 100644 --- a/examples/coev/coev_coop_adapt.py +++ b/examples/coev/coop_adapt.py @@ -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 @@ -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 = [] diff --git a/examples/coev/coev_coop_base.py b/examples/coev/coop_base.py similarity index 100% rename from examples/coev/coev_coop_base.py rename to examples/coev/coop_base.py diff --git a/examples/coev/coev_coop_evol.py b/examples/coev/coop_evol.py similarity index 96% rename from examples/coev/coev_coop_evol.py rename to examples/coev/coop_evol.py index 2ddfb8739..584224c98 100644 --- a/examples/coev/coev_coop_evol.py +++ b/examples/coev/coop_evol.py @@ -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 @@ -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 = [] diff --git a/examples/coev/coev_coop_gen.py b/examples/coev/coop_gen.py similarity index 95% rename from examples/coev/coev_coop_gen.py rename to examples/coev/coop_gen.py index f71adb2b7..b1852d323 100644 --- a/examples/coev/coev_coop_gen.py +++ b/examples/coev/coop_gen.py @@ -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 @@ -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 = [] diff --git a/examples/coev/coev_coop_niche.py b/examples/coev/coop_niche.py similarity index 95% rename from examples/coev/coev_coop_niche.py rename to examples/coev/coop_niche.py index c735be39d..1ce7b46e1 100644 --- a/examples/coev/coev_coop_niche.py +++ b/examples/coev/coop_niche.py @@ -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 @@ -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 = [] diff --git a/examples/coev/coev_hillis.py b/examples/coev/hillis.py similarity index 100% rename from examples/coev/coev_hillis.py rename to examples/coev/hillis.py diff --git a/examples/coev/coev_symbreg.py b/examples/coev/symbreg.py similarity index 59% rename from examples/coev/coev_symbreg.py rename to examples/coev/symbreg.py index e816b7d8b..b720159ac 100644 --- a/examples/coev/coev_symbreg.py +++ b/examples/coev/symbreg.py @@ -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) @@ -54,37 +41,30 @@ 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 @@ -92,9 +72,9 @@ def main(): 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 @@ -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 @@ -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() diff --git a/examples/de/de_basic.py b/examples/de/basic.py similarity index 100% rename from examples/de/de_basic.py rename to examples/de/basic.py diff --git a/examples/de/de_dynamic.py b/examples/de/dynamic.py similarity index 100% rename from examples/de/de_dynamic.py rename to examples/de/dynamic.py diff --git a/examples/de/de_sphere.py b/examples/de/sphere.py similarity index 100% rename from examples/de/de_sphere.py rename to examples/de/sphere.py diff --git a/examples/eda/eda_fctmin.py b/examples/eda/fctmin.py similarity index 100% rename from examples/eda/eda_fctmin.py rename to examples/eda/fctmin.py diff --git a/examples/eda/eda_pbil.py b/examples/eda/pbil.py similarity index 100% rename from examples/eda/eda_pbil.py rename to examples/eda/pbil.py diff --git a/examples/es/cmaes1pl_minfct.py b/examples/es/cma_1+l_minfct.py similarity index 100% rename from examples/es/cmaes1pl_minfct.py rename to examples/es/cma_1+l_minfct.py diff --git a/examples/es/cmaes_bipop.py b/examples/es/cma_bipop.py similarity index 100% rename from examples/es/cmaes_bipop.py rename to examples/es/cma_bipop.py diff --git a/examples/es/cmaes_minfct.py b/examples/es/cma_minfct.py similarity index 100% rename from examples/es/cmaes_minfct.py rename to examples/es/cma_minfct.py diff --git a/examples/es/cmaes_plotting.py b/examples/es/cma_plotting.py similarity index 100% rename from examples/es/cmaes_plotting.py rename to examples/es/cma_plotting.py diff --git a/examples/es/es_fctmin.py b/examples/es/fctmin.py similarity index 100% rename from examples/es/es_fctmin.py rename to examples/es/fctmin.py diff --git a/examples/es/es_onefifth.py b/examples/es/onefifth.py similarity index 100% rename from examples/es/es_onefifth.py rename to examples/es/onefifth.py diff --git a/examples/ga/ga_knn.py b/examples/ga/evoknn.py similarity index 100% rename from examples/ga/ga_knn.py rename to examples/ga/evoknn.py diff --git a/examples/ga/ga_knn_jmlr.py b/examples/ga/evoknn_jmlr.py similarity index 100% rename from examples/ga/ga_knn_jmlr.py rename to examples/ga/evoknn_jmlr.py diff --git a/examples/ga/ga_evosn.py b/examples/ga/evosn.py similarity index 100% rename from examples/ga/ga_evosn.py rename to examples/ga/evosn.py diff --git a/examples/ga/ga_knapsack.py b/examples/ga/knapsack.py similarity index 100% rename from examples/ga/ga_knapsack.py rename to examples/ga/knapsack.py diff --git a/examples/ga/ga_kursawefct.py b/examples/ga/kursawefct.py similarity index 100% rename from examples/ga/ga_kursawefct.py rename to examples/ga/kursawefct.py diff --git a/examples/ga/ga_nqueens.py b/examples/ga/nqueens.py similarity index 100% rename from examples/ga/ga_nqueens.py rename to examples/ga/nqueens.py diff --git a/examples/ga/ga_nsga2.py b/examples/ga/nsga2.py similarity index 100% rename from examples/ga/ga_nsga2.py rename to examples/ga/nsga2.py diff --git a/examples/ga/ga_onemax.py b/examples/ga/onemax.py similarity index 100% rename from examples/ga/ga_onemax.py rename to examples/ga/onemax.py diff --git a/examples/ga/ga_onemax_island.py b/examples/ga/onemax_island.py similarity index 100% rename from examples/ga/ga_onemax_island.py rename to examples/ga/onemax_island.py diff --git a/examples/ga/ga_onemax_mp.py b/examples/ga/onemax_mp.py similarity index 100% rename from examples/ga/ga_onemax_mp.py rename to examples/ga/onemax_mp.py diff --git a/examples/ga/ga_onemax_multidemic.py b/examples/ga/onemax_multidemic.py similarity index 100% rename from examples/ga/ga_onemax_multidemic.py rename to examples/ga/onemax_multidemic.py diff --git a/examples/ga/ga_onemax_numpy.py b/examples/ga/onemax_numpy.py similarity index 100% rename from examples/ga/ga_onemax_numpy.py rename to examples/ga/onemax_numpy.py diff --git a/examples/ga/ga_onemax_short.py b/examples/ga/onemax_short.py similarity index 100% rename from examples/ga/ga_onemax_short.py rename to examples/ga/onemax_short.py diff --git a/examples/ga/ga_tsp.py b/examples/ga/tsp.py similarity index 100% rename from examples/ga/ga_tsp.py rename to examples/ga/tsp.py diff --git a/examples/gp/__init__.py b/examples/gp/__init__.py new file mode 100644 index 000000000..f13df46fc --- /dev/null +++ b/examples/gp/__init__.py @@ -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 . \ No newline at end of file diff --git a/examples/gp/gp_adf_symbreg.py b/examples/gp/adf_symbreg.py similarity index 100% rename from examples/gp/gp_adf_symbreg.py rename to examples/gp/adf_symbreg.py diff --git a/examples/gp/gp_ant.py b/examples/gp/ant.py similarity index 100% rename from examples/gp/gp_ant.py rename to examples/gp/ant.py diff --git a/examples/gp/gp_multiplexer.py b/examples/gp/multiplexer.py similarity index 100% rename from examples/gp/gp_multiplexer.py rename to examples/gp/multiplexer.py diff --git a/examples/gp/gp_parity.py b/examples/gp/parity.py similarity index 100% rename from examples/gp/gp_parity.py rename to examples/gp/parity.py diff --git a/examples/gp/gp_spambase.py b/examples/gp/spambase.py similarity index 100% rename from examples/gp/gp_spambase.py rename to examples/gp/spambase.py diff --git a/examples/gp/gp_symbreg.py b/examples/gp/symbreg.py similarity index 95% rename from examples/gp/gp_symbreg.py rename to examples/gp/symbreg.py index 3b9506669..845cd947a 100644 --- a/examples/gp/gp_symbreg.py +++ b/examples/gp/symbreg.py @@ -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) diff --git a/examples/gp/gp_symbreg_numpy.py b/examples/gp/symbreg_numpy.py similarity index 100% rename from examples/gp/gp_symbreg_numpy.py rename to examples/gp/symbreg_numpy.py diff --git a/examples/pso/pso_basic.py b/examples/pso/basic.py similarity index 100% rename from examples/pso/pso_basic.py rename to examples/pso/basic.py diff --git a/examples/pso/pso_multiswarm.py b/examples/pso/multiswarm.py similarity index 100% rename from examples/pso/pso_multiswarm.py rename to examples/pso/multiswarm.py diff --git a/examples/pso/pso_speciation.py b/examples/pso/speciation.py similarity index 100% rename from examples/pso/pso_speciation.py rename to examples/pso/speciation.py