-
Notifications
You must be signed in to change notification settings - Fork 0
/
builder.py
69 lines (61 loc) · 1.77 KB
/
builder.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from envs import *
from networks.neat.network import NeatNetwork
from learning_strategies import *
from loops.loops import ESLoop
def build_env(config, unity_worker_id):
if config["name"] in ["simple_spread", "waterworld", "multiwalker"]:
return PettingzooWrapper(config["name"], config["max_step"])
elif "Unity" in config["name"]:
if "CollectApple" in config["name"]:
return UnityCollectAppleWrapper(config["name"], unity_worker_id, config["max_step"])
elif config["name"] in ["AndOps"]:
return AndOps()
else:
return GymWrapper(config["name"], config["max_step"], config["pomdp"])
def build_network(config):
if config["name"] == "NeatNetwork":
return NeatNetwork(
config["num_state"],
config["num_action"],
config["discrete_action"],
config["init_mu"],
config["init_std"],
config["mutate_std"],
config["max_weight"],
config["min_weight"],
config["probs"],
)
def build_loop(
config,
network,
agent_ids,
env_name,
gen_num,
n_workers,
eval_ep_num,
log,
save_model_period,
):
strategy_cfg = config["strategy"]
if strategy_cfg["name"] == "neat":
strategy = Neat(
strategy_cfg["offspring_num"],
strategy_cfg["crossover_ratio"],
strategy_cfg["champions_num"],
strategy_cfg["survival_ratio"],
strategy_cfg["c1"],
strategy_cfg["c3"],
strategy_cfg["delta_threshold"],
)
return ESLoop(
config,
strategy,
agent_ids,
env_name,
network,
gen_num,
n_workers,
eval_ep_num,
log,
save_model_period,
)