June 2018
Intermediate to advanced
318 pages
9h 24m
English
Now we will solve the same taxi problem using SARSA:
import gymimport randomenv = gym.make('Taxi-v1')
Also, we will initialize the learning rate, gamma, and epsilon. Q table has a dictionary:
alpha = 0.85gamma = 0.90epsilon = 0.8Q = {}for s in range(env.observation_space.n): for a in range(env.action_space.n): Q[(s,a)] = 0.0
As usual, we define an epsilon_greedy policy for exploration:
def epsilon_greedy(state, epsilon): if random.uniform(0,1) < epsilon: return env.action_space.sample() else: return max(list(range(env.action_space.n)), key = lambda x: Q[(state,x)])
Now, the actual SARSA algorithm comes in:
for i in range(4000): #We store cumulative reward of each episodes in r r = 0 #Then for every iterations, ...
Read now
Unlock full access