-
-
Save gsurma/e133626f494409ea3f60590383f530c9 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 genetic_evolution(self, env): | |
print "population_size: " + str(self.population_size) +\ | |
", mutation_rate: " + str(self.mutation_rate) +\ | |
", selection_rate: " + str(self.selection_rate) +\ | |
", random_weight_range: " + str(self.random_weight_range) | |
population = None | |
while True: | |
print('{{"metric": "generation", "value": {}}}'.format(self.generation)) | |
# 1. Selection | |
parents = self._strongest_parents(population, env) | |
self._save_model(parents) # Saving main model based on the current best two chromosomes | |
# 2. Crossover (Roulette selection) | |
pairs = [] | |
while len(pairs) != self.population_size: | |
pairs.append(self._pair(parents)) | |
base_offsprings = [] | |
for pair in pairs: | |
offsprings = self._crossover(pair[0][0], pair[1][0]) | |
base_offsprings.append(offsprings[-1]) | |
# 3. Mutation | |
new_population = self._mutation(base_offsprings) | |
population = new_population | |
self.generation += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment