Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Show your goal searching process with step - to - go curve, sum of squared error and / or theoretical value table with diagrams and
Show your goal searching process with steptogo curve, sum of squared error andor theoretical value table with diagrams and graphs and table for the following below code
import numpy as np
import random
# Define the grid world
GRIDSIZE
STARTSTATE
GOALSTATE
OBSTACLES
# Qlearning parameters
LEARNINGRATE
DISCOUNTFACTOR
EPISODES
# Initialize Qtable
qtable npzerosGRIDSIZE GRIDSIZE # actions: up down, left, right
# Define actions
ACTIONS UP "DOWN", "LEFT", "RIGHT"
# Function to choose an action using epsilongreedy strategy
def chooseactionstate epsilon:
if random.uniform epsilon:
return random.choicerange # choose a random action
else:
return npargmaxqtablestate state
# Function to perform Qlearning
def qlearning:
for episode in rangeEPISODES:
state STARTSTATE
while state GOALSTATE:
action chooseactionstate epsilon
nextstate takeactionstate action
reward calculaterewardnextstate
updateqtablestate action, reward, nextstate
state nextstate
# Function to take an action and return the next state
def takeactionstate action:
if action : # UP
return max state state
elif action : # DOWN
return minGRIDSIZE state state
elif action : # LEFT
return state max state
elif action : # RIGHT
return state minGRIDSIZE state
# Function to calculate the reward for a given state
def calculaterewardstate:
if state GOALSTATE:
return
elif state in OBSTACLES:
return
else:
return
# Function to update the Qtable based on the Qlearning update rule
def updateqtablestate action, reward, nextstate:
bestfuturevalue npmaxqtablenextstate nextstate
currentvalue qtablestate state action
newvalue LEARNINGRATE currentvalue LEARNINGRATE reward DISCOUNTFACTOR bestfuturevalue
qtablestate state action newvalue
# Run Qlearning algorithm
qlearning
# Print the learned Qtable
printLearned Qtable:"
printqtable
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