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: |
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 Organism(): | |
# [Some code removed here] | |
def mate(self, other, mutate=True): | |
if self.use_bias != other.use_bias: | |
raise ValueError('Both parents must use bias or not use bias') | |
if not len(self.layers) == len(other.layers): | |
raise ValueError('Both parents must have same number of layers') | |
if not all(self.layers[x].shape == other.layers[x].shape for x in range(len(self.layers))): | |
raise ValueError('Both parents must have same shape') |
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 Organism(): | |
def __init__(self, dimensions, use_bias=True, output='softmax'): | |
self.layers = [] | |
self.biases = [] | |
self.use_bias = use_bias | |
self.output = self._activation(output) | |
for i in range(len(dimensions)-1): | |
shape = (dimensions[i], dimensions[i+1]) | |
std = np.sqrt(2 / sum(shape)) | |
layer = np.random.normal(0, std, shape) |
NewerOlder