Skip to content
This repository was archived by the owner on Jul 20, 2022. It is now read-only.

Commit

Permalink
Refactor neat initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
iver56 committed Apr 26, 2016
1 parent c3d73bd commit 525f7ea
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions neuroevolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ def __init__(self):

self.individual_fitness = {} # individual id => individual fitness

self.population = None
self.init_neat()

run_start_time = time.time()
self.run()
print("Run execution time: {0:.2f} seconds".format(time.time() - run_start_time))
Expand All @@ -227,7 +230,7 @@ def has_patience_ended(self, max_fitness, generation):
elif generation - self.last_fitness_improvement >= self.args.patience:
return True # Patience has ended. Stop evolving.

def run(self):
def init_neat(self):
params = NEAT.Parameters()
params.PopulationSize = self.args.population_size
params.AllowClones = self.args.allow_clones
Expand All @@ -249,20 +252,21 @@ def run(self):
0, # SeedType
params # Parameters
)
pop = NEAT.Population(
self.population = NEAT.Population(
genome,
params,
True, # whether the population should be randomized
2.0, # how much the population should be randomized,
settings.PRNG_SEED
)

def run(self):
for generation in range(1, self.args.num_generations + 1):
generation_start_time = time.time()
print('generation {}'.format(generation))

# Retrieve a list of all genomes in the population
genotypes = NEAT.GetGenomeList(pop)
genotypes = NEAT.GetGenomeList(self.population)

individuals = []
all_individuals = []
Expand Down Expand Up @@ -357,7 +361,7 @@ def run(self):
break

# advance to the next generation
pop.Epoch()
self.population.Epoch()
print("Generation execution time: {0:.2f} seconds".format(
time.time() - generation_start_time)
)
Expand Down

0 comments on commit 525f7ea

Please sign in to comment.