Skip to content

Commit

Permalink
Moves saving of best agent per gen to right after sort
Browse files Browse the repository at this point in the history
  • Loading branch information
runeharlyk committed Jan 18, 2024
1 parent 52f58bd commit ec79f7b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion train_GeneticAgent.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def train():
scores = np.array(list(tqdm(pool.imap_unordered(agent.get_fitness, args), desc='Population done', leave=False)))

agent.weights = agent.weights[scores.argsort()[::-1]]
best_per_gen[gen] = agent.weights[0]

all_scores[gen] = scores
survivors = int(np.ceil(elite_pct * population_size))
Expand All @@ -55,7 +56,6 @@ def train():
idx = np.random.randint(0, len(parents), size=2)
parent1, parent2 = parents[idx, :]

best_per_gen[gen] = agent.weights[scores.argmax()]
if np.random.random() < crossover_rate:
child1, child2 = agent.breed(parent1, parent2)

Expand Down

0 comments on commit ec79f7b

Please sign in to comment.