Skip to content

Instantly share code, notes, and snippets.

View RileyLazarou's full-sized avatar

Riley Lazarou RileyLazarou

  • Flatland Data Solutions
  • Saskatoon, Canada
View GitHub Profile
@RileyLazarou
RileyLazarou / connga_ecosystem_1.py
Last active November 17, 2019 21:20
Neural Network Organism Selection
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:
@RileyLazarou
RileyLazarou / connga_organism_2.py
Last active November 10, 2019 22:01
Neural Network Organism Reproduction
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')
@RileyLazarou
RileyLazarou / connga_organism_1.py
Last active November 10, 2019 17:47
Neural Network Organism
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)