-
-
Save gsurma/95abf578406e3df58364173a5a7e139a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _mutation(self, base_offsprings): | |
offsprings = [] | |
for offspring in base_offsprings: | |
offspring_mutation = copy.deepcopy(offspring) | |
for a in range(0, len(offspring_mutation)): # 10 | |
a_layer = offspring_mutation[a] | |
for b in range(0, len(a_layer)): # 8 | |
b_layer = a_layer[b] | |
if not isinstance(b_layer, np.ndarray): | |
if np.random.choice([True, False], p=[self.mutation_rate, 1 - self.mutation_rate]): | |
offspring_mutation[a][b] = self._random_weight() | |
continue | |
for c in range(0, len(b_layer)): # 8 | |
c_layer = b_layer[c] | |
if not isinstance(c_layer, np.ndarray): | |
if np.random.choice([True, False], p=[self.mutation_rate, 1 - self.mutation_rate]): | |
offspring_mutation[a][b][c] = self._random_weight() | |
continue | |
for d in range(0, len(c_layer)): # 4 | |
d_layer = c_layer[d] | |
for e in range(0, len(d_layer)): # 32 | |
if np.random.choice([True, False], p=[self.mutation_rate, 1 - self.mutation_rate]): | |
offspring_mutation[a][b][c][d][e] = self._random_weight() | |
offsprings.append(offspring_mutation) | |
return offsprings |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment