AI python


IntroductionIn this project, you will implement value
iteration and Q-learning. You will test your agents first on Gridworld
(from class), then apply them to a simulated robot controller (Crawler)
and Pacman.
As in previous projects, this project includes an
autograder for you to grade your solutions on your machine. This can be
run on all questions with the command:
python autograder.py
It can be run for one particular question, such as q2, by:
python autograder.py -q q2
It can be run for one particular test by commands of the form:
python autograder.py -t test_cases/q2/1-bridge-grid
The code for this project contains the following files, available as a zip archiveDownload zip archive.
Files you’ll edit:valueIterationAgents.pyA value iteration agent for solving known MDPs.qlearningAgents.pyQ-learning agents for Gridworld, Crawler and Pacman.analysis.pyA file to put your answers to questions given in the project.Files you should read but NOT edit:mdp.pyDefines methods on general MDPs.learningAgents.pyDefines the base classes ValueEstimationAgent and QLearningAgent, which your agents will extend.util.pyUtilities, including util.Counter, which is particularly useful for Q-learners.gridworld.pyThe Gridworld implementation.featureExtractors.pyClasses for extracting features on (state, action) pairs. Used for the approximate Q-learning agent (in qlearningAgents.py).Files you can ignore:environment.pyAbstract class for general reinforcement learning environments. Used by gridworld.py.graphicsGridworldDisplay.pyGridworld graphical display.graphicsUtils.pyGraphics utilities.textGridworldDisplay.pyPlug-in for the Gridworld text interface.crawler.pyThe crawler code and test harness. You will run this but not edit it.graphicsCrawlerDisplay.pyGUI for the crawler robot.autograder.pyProject autogradertestParser.pyParses autograder test and solution filestestClasses.pyGeneral autograding test classestest_cases/Directory containing the test cases for each questionreinforcementTestClasses.pyProject 3 specific autograding test classesFiles to Edit and Submit: You will fill in portions of valueIterationAgents.py, qlearningAgents.py, and analysis.py during the assignment. Please do not change the other files in this distribution or submit any of our original files other than these files.
Evaluation: Your code will be autograded for technical correctness. Please do not
change the names of any provided functions or classes within the code,
or you will wreak havoc on the autograder (to the detriment of your
score). However, the correctness of your implementation – not the
autograder’s judgments – will be the final judge of your score. If
necessary, we will review and grade assignments individually to ensure
that you receive due credit for your work.
Academic Dishonesty:
We will be checking your code against other submissions in the class
for logical redundancy. If you copy someone else’s code and submit it
with minor changes, we will know. These cheat detectors are quite hard
to fool, so please don’t try. We trust you all to submit your own work
only; please don’t let us down. If you do, we will pursue the strongest consequences available to us.
Getting Help:
You are not alone! If you find yourself stuck on something, contact the
course staff for help. Office hours are there for your support; please
use them. If you can’t make our office hours, let us know and we will
schedule more. We want these projects to be rewarding and instructional,
not frustrating and demoralizing. But, we don’t know when or how to
help unless you ask.
MDPsTo get started, run Gridworld in manual control mode, which uses the arrow keys:
python gridworld.py -m
You will see the two-exit layout from class. The blue dot is the agent. Note that when you press up, the agent only actually moves north 80% of the time. Such is the life of a Gridworld agent!
You can control many aspects of the simulation. A full list of options is available by running:
python gridworld.py -h
The default agent moves randomly
python gridworld.py -g MazeGrid
You should see the random agent bounce around the grid until it happens upon an exit. Not the finest hour for an AI agent.
Note:
The Gridworld MDP is such that you first must enter a pre-terminal
state (the double boxes shown in the GUI) and then take the special
‘exit’ action before the episode actually ends (in the true terminal
state called TERMINAL_STATE, which is not shown in the
GUI). If you run an episode manually, your total return may be less than
you expected, due to the discount rate (-d to change; 0.9 by default).
Look at the console output that accompanies the graphical output (or use -t for all text). You will be told about each transition the agent experiences (to turn this off, use -q).
As in Pacman, positions are represented by (x,y) Cartesian coordinates and any arrays are indexed by [x][y], with ‘north’ being the direction of increasing y, etc. By default, most transitions will receive a reward of zero, though you can change this with the living reward option (-r).
Question 1 (4 points): Value IterationRecall the value iteration state update equation:

Write a value iteration agent in ValueIterationAgent, which has been partially specified for you in valueIterationAgents.py.
Your value iteration agent is an offline planner, not a reinforcement
learning agent, and so the relevant training option is the number of
iterations of value iteration it should run (option -i) in its initial planning phase. ValueIterationAgent takes an MDP on construction and runs value iteration for the specified number of iterations before the constructor returns.
Value iteration computes k-step estimates of the optimal values, Vk. In addition to runValueIteration, implement the following methods for ValueIterationAgent using Vk.
computeActionFromValues(state) computes the best action according to the value function given by self.values.
computeQValueFromValues(state, action) returns the Q-value of the (state, action) pair given by the value function given by self.values.
These
quantities are all displayed in the GUI: values are numbers in squares,
Q-values are numbers in square quarters, and policies are arrows out
from each square.
Important: Use the “batch” version of value iteration where each vector Vk is computed from a fixed vector Vk−1
(like in lecture), not the “online” version where one single weight
vector is updated in place. This means that when a state’s value is
updated in iteration
k based on the values of its successor states, the successor state values
used in the value update computation should be those from iteration k−1 (even if some of the successor states had already been updated in iteration k). The difference is discussed in Sutton