Skip to content

Instantly share code, notes, and snippets.

@gsurma
Last active December 23, 2018 09:50
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/4bb3f97c4d4456475a708393bae6c6ca to your computer and use it in GitHub Desktop.
Save gsurma/4bb3f97c4d4456475a708393bae6c6ca to your computer and use it in GitHub Desktop.
def _initial_population(self):
weights = self.model.get_weights()
chromosomes = []
for i in range(0, self.population_size):
chromosome = weights # 1 686 180 params
for a in range(0, len(chromosome)): # 10
a_layer = weights[a]
for b in range(0, len(a_layer)): # 8
b_layer = a_layer[b]
if not isinstance(b_layer, np.ndarray):
chromosome[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):
chromosome[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
chromosome[a][b][c][d][e] = self._random_weight()
chromosomes.append(chromosome)
return chromosomes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment