-
Notifications
You must be signed in to change notification settings - Fork 1
/
train.py
44 lines (36 loc) · 1.4 KB
/
train.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
"""Runs optimizer with selected parameters."""
from src.environment import Environment
from src.optimizer import EvolutionStrategy
from src.optimizer import GeneticOptimizer
from src.optimizer import ContinuousEvolutionStrategy
from src.trainer import Trainer
from src.utils.config import init_config
from src.utils.utils import set_random_seed
if __name__ == "__main__":
config = init_config(path="config.yml")
set_random_seed(seed=config.random_seed)
env = Environment(config=config)
if config.optimizer.name == "nes":
cfg = config.optimizer.nes
optimizer = EvolutionStrategy(
agents=env.drones, learning_rate=cfg.learning_rate, sigma=cfg.sigma
)
elif config.optimizer.name == "ces":
cfg = config.optimizer.ces
optimizer = ContinuousEvolutionStrategy(
agents=env.drones,
learning_rate=cfg.learning_rate,
sigma=cfg.sigma,
momentum=cfg.momentum,
)
elif config.optimizer.name == "evo":
cfg = config.optimizer.evo
optimizer = GeneticOptimizer(
agents=env.drones,
mutation_probability=cfg.mutation_probability,
mutation_rate=cfg.mutation_rate,
)
else:
raise NotImplementedError(f"Optimizer '{config.optimizer.name}' not implemented.")
trainer = Trainer(env=env, optimizer=optimizer, config=config)
trainer.run()