-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_select_mutation.py
47 lines (37 loc) · 1.5 KB
/
run_select_mutation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from genetic_algo import GeneticAlgorithm
from training import evaluate_generation, setup_run, get_seeds, select_mutate
from pymunk.vec2d import Vec2d
from models.FeedForwardDNN import FeedForwardDNN, breed
from tqdm import trange
def main():
run_seed = 1
num_agents = 1000
num_generations = 100
log_dir = "./runs/rsm/"
agent_class = FeedForwardDNN
agent_args = {
'view_size': Vec2d(15, 15),
'layer_config': [
# ('conv', 3, (5, 5)), ('act', 'relu'),
('linear', 16), ('act', 'sigmoid'),
('linear', 16), ('act', 'sigmoid'),
],
}
game_args = {
'num_chunks': 10,
'seed': 144,
}
# Get everything needed for the run: RNG, the agents, the genetic algorithm class, and the logger
master_rng, agents, gen_algo, logger = setup_run(run_seed, agent_class, agent_args, num_agents, log_dir)
for i in trange(num_generations):
fitnesses, death_types = evaluate_generation(agents, game_args)
# Print generation stats, dump best to disk, top 2 automatically pass into next generation
logger.log_generation(agents, fitnesses, death_types, game_args)
best = logger.copy_topn(agents, fitnesses, 1)[0]
# Create new generation from best of previous
select_mutate(best, agents, master_rng)
# Change level every 10 generations
# if (i + 1) % 10 == 0:
# game_args['seed'] = get_seeds(master_rng)
if __name__ == "__main__":
main()