Skip to content

Commit

Permalink
Fix example parameterisation, clean up docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
HenrikMettler committed Nov 5, 2020
1 parent 0f44a01 commit 5fff500
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions examples/example_reorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def objective(individual):

# %%
# Next, we set up the evolutionary search. We first define the
# parameters for the population, the genome of individuals, and the
# evolutionary algorithm.
# parameters for the population, the genome of individuals, and two
# evolutionary algorithms without (default) and with genome reordering.


population_params = {"n_parents": 1, "mutation_rate": 0.03, "seed": 818821}
Expand All @@ -86,6 +86,12 @@ def objective(individual):
}

ea_params = {"n_offsprings": 4, "tournament_size": 2, "n_processes": 2}
ea_params_with_reorder = {
"n_offsprings": 4,
"tournament_size": 2,
"n_processes": 2,
"reorder_genome": True,
}

evolve_params = {"max_generations": int(args["--max-generations"]), "min_fitness": 0.0}

Expand All @@ -95,8 +101,9 @@ def objective(individual):
pop_with_reorder = cgp.Population(**population_params, genome_params=genome_params)

# %%
# and an instance of the (mu + lambda) evolutionary algorithm
# and two instances of the (mu + lambda) evolutionary algorithm
ea = cgp.ea.MuPlusLambda(**ea_params)
ea_with_reorder = cgp.ea.MuPlusLambda(**ea_params_with_reorder)

# %%
# We define two callbacks for recording of fitness over generations
Expand Down Expand Up @@ -125,17 +132,16 @@ def recording_callback_with_reorder(pop):
cgp.evolve(
pop_with_reorder,
objective,
ea,
ea_with_reorder,
**evolve_params,
print_progress=True,
callback=recording_callback_with_reorder,
reorder_genome=True,
)


# %%
# After finishing the evolution, we plot the result and log the final
# evolved expression.
# After finishing the evolution, we plot the evolution of the fittest individual
# with and without genome reordering


width = 9.0
Expand Down

0 comments on commit 5fff500

Please sign in to comment.