Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The goal of this assignment is to implement QLearning method on Taxi - v 3 enviroment at openai gym framework. Your task in this enviroment
The goal of this assignment is to implement QLearning method on Taxiv enviroment at openai gym framework.
Your task in this enviroment is to pick up the passenger at one location and drop him off in another, located at possible locations labeled by different letters In the example given below, you are expected to pick him up at Y and drop him at G You receive points for a successful dropoff, and lose point for every timestep it takes. There is also a point penalty for illegal pickup and dropoff actions.
Note that dynamics of the model are assumed to be unknown.
below is the original code, impliment the QLearning method accordingly
import gymnasium as gym
import time
import numpy as np
import os
import random
def qLearningenv:
nS env.observationspace.n
nA env.actionspace.n
Q npzeros nS nA dtypenpint
alpha
gamma
epsilon
numiter
for i in range numiter:
s actions env. reset
for step in range :
action env.actionspace.sample
#action npargmaxQs
sp reward, done, info env.step action
Qs action Qsaction alpha reward gamma npmax Qsp: Qs action
S sp
if i :
print fEpisode i
return Q
def SARSA env:
nS env.observationspace.n
nA env.actionspace.n
Q npzeros nSnA dtypenp int
alpha
gamma
epsilon
numiter
for i in range numiter:
S actions env.reset
a env.actionspace.sample
for step in range :
sp reward, done, truncated, info env. stepa
ap npargmax Qsp
QS a QSa alpha reward gamma Qsp apQSa
S sp
a ap
if i :
printfEpisode i
return Q
env gym.makeTaxiv rendermode"human"
observation,info env.reset
Q SARSA env
observation env. reset
doneFalse
sumreward
while not done:
os systemcls
env. render
action npargmax Qobservation
observation, reward, done, truncated, info env. stepaction
sumreward reward
time.sleep
if done:
observation env. reset
print done with reward: reward
env. close
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started