Skip to content

Instantly share code, notes, and snippets.

@gsurma
Created December 23, 2018 10:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gsurma/95abf578406e3df58364173a5a7e139a to your computer and use it in GitHub Desktop.
Save gsurma/95abf578406e3df58364173a5a7e139a to your computer and use it in GitHub Desktop.
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