-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain_taxi.py
52 lines (31 loc) · 1.15 KB
/
main_taxi.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
import neat
import numpy as np
import run_neat_base
def eval_single_genome(genome, genome_config):
net = neat.nn.FeedForwardNetwork.create(genome, genome_config)
total_reward = 0.0
for i in range(run_neat_base.n):
# print("--> Starting new episode")
observation = run_neat_base.env.reset()
action = eval_network(net, observation)
done = False
while not done:
# env.render()
observation, reward, done, info = run_neat_base.env.step(action)
# print("\t Reward {}: {}".format(t, reward))
action = eval_network(net, observation)
total_reward += reward
if done:
# print("<-- Episode finished after {} timesteps".format(t + 1))
break
return total_reward / run_neat_base.n
def eval_network(net, net_input):
net_input_array = np.zeros(500)
net_input_array[net_input] = 1
return np.argmax(net.activate(net_input_array))
def main():
run_neat_base.run(eval_network,
eval_single_genome,
environment_name="Taxi-v2")
if __name__ == '__main__':
main()