Skip to content

Commit

Permalink
Provide default value to tournament size
Browse files Browse the repository at this point in the history
  • Loading branch information
HenrikMettler committed Jan 6, 2021
1 parent e2c36fe commit ecfb817
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 8 deletions.
9 changes: 6 additions & 3 deletions cgp/ea/mu_plus_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class MuPlusLambda:
def __init__(
self,
n_offsprings: int,
tournament_size: int,
*,
tournament_size: Union[None, int] = None,
n_processes: int = 1,
local_search: Callable[[IndividualBase], None] = lambda combined: None,
k_local_search: Union[int, None] = None,
Expand All @@ -34,8 +34,8 @@ def __init__(
----------
n_offsprings : int
Number of offspring in each iteration.
tournament_size : int
Tournament size in each iteration.
tournament_size : int, optional
Tournament size in each iteration. Defaults to the number of parents in the population
n_processes : int, optional
Number of parallel processes to be used. If greater than 1,
parallel evaluation of the objective is supported. Defaults to 1.
Expand Down Expand Up @@ -160,6 +160,9 @@ def _create_new_offspring_generation(self, pop: Population) -> List[IndividualBa
# use tournament selection to randomly select individuals from
# parent population

if self.tournament_size is None:
self.tournament_size = pop.n_parents

if self.tournament_size > pop.n_parents:
raise ValueError("tournament_size must be less or equal n_parents")

Expand Down
1 change: 0 additions & 1 deletion examples/example_hurdles.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ def objective_two(individual):
# the (n+1)th objective by a list of numbers between 0 and 1.
ea_params = {
"n_offsprings": 4,
"tournament_size": 2,
"n_processes": 1,
"hurdle_percentile": [0.5, 0.0],
}
Expand Down
2 changes: 1 addition & 1 deletion examples/example_minimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def objective(individual):
"primitives": (cgp.Add, cgp.Sub, cgp.Mul, cgp.ConstantFloat),
}

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

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

Expand Down
2 changes: 1 addition & 1 deletion examples/example_multi_genome.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def objective(individual):
}
genome_params = [single_genome_params, single_genome_params]

ea_params = {"n_offsprings": 4, "tournament_size": 2, "n_processes": 1}
ea_params = {"n_offsprings": 4, "n_processes": 1}

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

Expand Down
2 changes: 1 addition & 1 deletion examples/example_piecewise_target_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def objective(individual, rng):
"primitives": (cgp.IfElse, cgp.Mul, cgp.Add, cgp.Sub, cgp.ConstantFloat,),
}

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

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

Expand Down
2 changes: 1 addition & 1 deletion examples/example_reorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def objective(individual):
"primitives": (cgp.Add, cgp.Sub, cgp.Mul, cgp.ConstantFloat),
}

ea_params = {"n_offsprings": 4, "tournament_size": 2, "n_processes": 2}
ea_params = {"n_offsprings": 4, "n_processes": 2}
ea_params_with_reorder = {
"n_offsprings": 4,
"tournament_size": 2,
Expand Down

0 comments on commit ecfb817

Please sign in to comment.