(self, N, random_state=None)
| 79 | self.eps = 0.05 |
| 80 | |
| 81 | def _do(self, N, random_state=None): |
| 82 | params = self.params |
| 83 | pop = self.data.get("pop") |
| 84 | |
| 85 | # make sure that for each parameter a value exists - if not simply set it randomly |
| 86 | for name, param in params.items(): |
| 87 | is_none = np.where(pop.get(name) == None)[0] # noqa: E711 |
| 88 | if len(is_none) > 0: |
| 89 | pop[is_none].set( |
| 90 | name, param.sample(len(is_none), random_state=random_state) |
| 91 | ) |
| 92 | |
| 93 | selection = AgeBasedTournamentSelection() |
| 94 | |
| 95 | crossover = { |
| 96 | Binary: UX(), |
| 97 | Real: SBX(), |
| 98 | Integer: SBX(vtype=float, repair=RoundingRepair()), |
| 99 | Choice: UX(), |
| 100 | } |
| 101 | |
| 102 | mutation = { |
| 103 | Binary: BFM(), |
| 104 | Real: PM(), |
| 105 | Integer: PM(vtype=float, repair=RoundingRepair()), |
| 106 | Choice: ChoiceRandomMutation(), |
| 107 | } |
| 108 | |
| 109 | mating = MixedVariableMating( |
| 110 | crossover=crossover, |
| 111 | mutation=mutation, |
| 112 | eliminate_duplicates=NoDuplicateElimination(), |
| 113 | ) |
| 114 | |
| 115 | problem = Problem(vars=params) |
| 116 | |
| 117 | parents = selection(problem, pop, N, n_parents=2, random_state=random_state) |
| 118 | parents = [ |
| 119 | [ |
| 120 | Individual(X={key: parent.get(key) for key in params}) |
| 121 | for parent in mating |
| 122 | ] |
| 123 | for mating in parents |
| 124 | ] |
| 125 | |
| 126 | off = mating(problem, parents, N, parents=True, random_state=random_state) |
| 127 | |
| 128 | Xp = off.get("X") |
| 129 | ret = { |
| 130 | param: np.array([Xp[i][param] for i in range(len(Xp))]) for param in params |
| 131 | } |
| 132 | |
| 133 | return ret |
| 134 | |
| 135 | |
| 136 | class AgeBasedTournamentSelection(TournamentSelection): |
nothing calls this directly
no test coverage detected