Code Duplication    Length = 29-35 lines in 3 locations

src/gradient_free_optimizers/optimizers/pop_opt/genetic_algorithm.py 1 location

@@ 20-54 (lines=35) @@
17
    optimizer_type = "population"
18
    computationally_expensive = False
19
20
    def __init__(
21
        self,
22
        search_space,
23
        initialize={"grid": 4, "random": 2, "vertices": 4},
24
        constraints=[],
25
        random_state=None,
26
        rand_rest_p=0,
27
        nth_process=None,
28
        population=10,
29
        offspring=10,
30
        crossover="discrete-recombination",
31
        n_parents=2,
32
        mutation_rate=0.5,
33
        crossover_rate=0.5,
34
    ):
35
        super().__init__(
36
            search_space=search_space,
37
            initialize=initialize,
38
            constraints=constraints,
39
            random_state=random_state,
40
            rand_rest_p=rand_rest_p,
41
            nth_process=nth_process,
42
        )
43
44
        self.population = population
45
        self.offspring = offspring
46
        self.crossover = crossover
47
        self.n_parents = n_parents
48
        self.mutation_rate = mutation_rate
49
        self.crossover_rate = crossover_rate
50
51
        self.individuals = self._create_population(Individual)
52
        self.optimizers = self.individuals
53
54
        self.offspring_l = []
55
56
    def fittest_parents(self):
57
        fittest_parents_f = 0.5

src/gradient_free_optimizers/optimizers/pop_opt/evolution_strategy.py 1 location

@@ 20-50 (lines=31) @@
17
    optimizer_type = "population"
18
    computationally_expensive = False
19
20
    def __init__(
21
        self,
22
        search_space,
23
        initialize={"grid": 4, "random": 2, "vertices": 4},
24
        constraints=[],
25
        random_state=None,
26
        rand_rest_p=0,
27
        nth_process=None,
28
        population=10,
29
        offspring=20,
30
        replace_parents=False,
31
        mutation_rate=0.7,
32
        crossover_rate=0.3,
33
    ):
34
        super().__init__(
35
            search_space=search_space,
36
            initialize=initialize,
37
            constraints=constraints,
38
            random_state=random_state,
39
            rand_rest_p=rand_rest_p,
40
            nth_process=nth_process,
41
        )
42
43
        self.population = population
44
        self.offspring = offspring
45
        self.replace_parents = replace_parents
46
        self.mutation_rate = mutation_rate
47
        self.crossover_rate = crossover_rate
48
49
        self.individuals = self._create_population(Individual)
50
        self.optimizers = self.individuals
51
52
    def _cross(self):
53
        while True:

src/gradient_free_optimizers/optimizers/pop_opt/differential_evolution.py 1 location

@@ 20-48 (lines=29) @@
17
    optimizer_type = "population"
18
    computationally_expensive = False
19
20
    def __init__(
21
        self,
22
        search_space,
23
        initialize={"grid": 4, "random": 2, "vertices": 4},
24
        constraints=[],
25
        random_state=None,
26
        rand_rest_p=0,
27
        nth_process=None,
28
        population=10,
29
        mutation_rate=0.9,
30
        crossover_rate=0.9,
31
    ):
32
        super().__init__(
33
            search_space=search_space,
34
            initialize=initialize,
35
            constraints=constraints,
36
            random_state=random_state,
37
            rand_rest_p=rand_rest_p,
38
            nth_process=nth_process,
39
        )
40
41
        self.population = population
42
        self.mutation_rate = mutation_rate
43
        self.crossover_rate = crossover_rate
44
45
        self.individuals = self._create_population(Individual)
46
        self.optimizers = self.individuals
47
48
        self.offspring_l = []
49
50
    def mutation(self, f=1):
51
        ind_selected = random.sample(self.individuals, 3)