Last active
November 17, 2019 21:20
-
-
Save RileyLazarou/b1e462e6b9d6b3bacb6e0ee2b18681c1 to your computer and use it in GitHub Desktop.
Neural Network Organism Selection
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
class Ecosystem(): | |
# [Some code removed here] | |
def generation(self, repeats=1, keep_best=True): | |
rewards = rewards = [np.mean([self.scoring_function(x) for _ in range(repeats)]) for x in self.population] | |
self.population = [self.population[x] for x in np.argsort(rewards)[::-1]] | |
new_population = [] | |
for i in range(self.population_size): | |
parent_1_idx = i % self.holdout | |
if self.mating: | |
parent_2_idx = min(self.population_size - 1, int(np.random.exponential(self.holdout))) | |
else: | |
parent_2_idx = parent_1_idx | |
offspring = self.population[parent_1_idx].mate(self.population[parent_2_idx]) | |
new_population.append(offspring) | |
if keep_best: | |
new_population[-1] = self.population[0] # Ensure best organism survives | |
self.population = new_population |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment