Does that behavior of the agent match what you expect? This will invoke the crawling robot from class using your Q-learner. Note that the step delay is a parameter of the simulation, whereas the learning rate and epsilon are parameters of your learning algorithm, and the discount factor is a property of the environment.
First, train a completely random Q-learner with the default learning rate on the noiseless BridgeGrid for 50 episodes and observe whether it finds the optimal policy.
Now try the same experiment with an epsilon of 0. Epsilon is controlled by -e , learning rate by -l. Note: Your response should be not depend on the exact tie-breaking mechanism used to choose actions. This means your answer should be correct even if for instance we rotated the entire bridge grid world 90 degrees. Time to play some Pacman! Pacman will play games in two phases. In the first phase, training , Pacman will begin to learn about the values of positions and actions.
Test games are shown in the GUI by default. Without any code changes you should be able to run Q-learning Pacman for very tiny grids as follows:. The autograder will run test games after the training games. Hint: If your QLearningAgent works for gridworld.
In particular, because unseen actions have by definition a Q-value of zero, if all of the actions that have been seen have negative Q-values, an unseen action may be optimal. Beware of the argmax function from util. These values will then be accessible as self. Note: While a total of games will be played, the first games will not be displayed because of the option -x , which designates the first games for training no output.
Thus, you will only see Pacman play the last 10 of these games. The number of training games is also passed to your agent as the option numTraining.
During training, you will see output every games with statistics about how Pacman is faring. Epsilon is positive during training, so Pacman will play poorly even after having learned a good policy: this is because he occasionally makes a random exploratory move into a ghost. By the end of training, it should remain positive and be fairly high between and Make sure you understand what is happening here: the MDP state is the exact board configuration facing Pacman, with the now complex transitions describing an entire ply of change to that state.
The intermediate game configurations in which Pacman has moved but the ghosts have not replied are not MDP states, but are bundled in to the transitions. However, you will find that training the same agent on the seemingly simple mediumGrid does not work well. At test time, he plays badly, probably losing all of his test games. Training will also take a long time, despite its ineffectiveness.
Pacman fails to win on larger layouts because each board configuration is a separate state with separate Q-values. He has no way to generalize that running into a ghost is bad for all positions. Obviously, this approach will not scale. Implement an approximate Q-learning agent that learns weights for features of states, where many states might share the same features.
Write your implementation in ApproximateQAgent class in qlearningAgents. We provide feature functions for you in featureExtractors. Feature vectors are util. Counter like a dictionary objects containing the non-zero pairs of features and values; all omitted features have value zero. In your code, you should implement the weight vector as a dictionary mapping features which the feature extractors will return to weight values.
You will update your weight vectors similarly to how you updated Q-values:. By default, ApproximateQAgent uses the IdentityExtractor , which assigns a single feature to every state,action pair. With this feature extractor, your approximate Q-learning agent should work identically to PacmanQAgent. You can test this with the following command:. Make sure that your methods in QLearningAgent call getQValue instead of accessing Q-values directly, so that when you override getQValue in your approximate agent, the new approximate q-values are used to compute actions.
Even much larger layouts should be no problem for your ApproximateQAgent warning : this may take a few minutes to train :. If you have no errors, your approximate Q-learning agent should win almost every time with these simple features, even with only 50 training games. Grading: We will run your approximate Q-learning agent and check that it learns the same Q-values and feature weights as our reference implementation when each is presented with the same set of examples.
Submit reinforcement. Please specify any partner you may have worked with and verify that both you and your partner are associated with the submission after submitting.
Project 3: Reinforcement Learning Version 1. This can be run on all questions with the command: python autograder. Classes for extracting features on state, action pairs.
Used for the approximate Q-learning agent in qlearningAgents. If you're not sure which to choose, learn more about installing packages. Warning Some features may not work without JavaScript. Please try enabling it if you encounter problems.
Search PyPI Search. Latest version Released: Feb 9, Gridworlds environments for OpenAI gym. Navigation Project description Release history Download files. Project links Homepage. Maintainers podondra. Gridworld-v0 Gridworld is simple 4 times 4 gridworld from example 4. WindyGridworld-v0 Windy gridworld is from example 6. Cliff-v0 Cliff walking is a gridworld example 6.
As before, we use a negative because the priority queue is a min heap, but we want to prioritize updating states that have a higher error. A couple of important notes on implementation: When you compute predecessors of a state, make sure to store them in a set, not a list, to avoid duplicates. Please use util.
PriorityQueue in your implementation. The update method in this class will likely be useful; look at its documentation. It should take about 1 second to run. Grading: Your prioritized sweeping value iteration agent will be graded on a new grid. Question 6 4 points : Q-Learning Note that your value iteration agent does not actually learn from experience. Rather, it ponders its MDP model to arrive at a complete policy before ever interacting with a real environment. When it does interact with the environment, it simply follows the precomputed policy e.
This distinction may be subtle in a simulated environment like a Gridword, but it's very important in the real world, where the real MDP is not available. You will now write a Q-learning agent, which does very little on construction, but instead learns by trial and error from interactions with the environment through its update state, action, nextState, reward method. The random. In a particular state, actions that your agent hasn't seen before still have a Q-value, specifically a Q-value of zero, and if all of the actions that your agent has seen before have a negative Q-value, an unseen action may be optimal.
This abstraction will be useful for question 10 when you override getQValue to use features of state-action pairs rather than state-action pairs directly. With the Q-learning update in place, you can watch your Q-learner learn under manual control, using the keyboard: python gridworld. Watch how the agent learns about the state it was just in, not the one it moves to, and "leaves learning in its wake.
If you manually steer Pacman north and then east along the optimal path for four episodes, you should see the following Q-values: Grading: We will run your Q-learning agent and check that it learns the same Q-values and policy as our reference implementation when each is presented with the same set of examples.
To grade your implementation, run the autograder: Question 7 2 points : Epsilon Greedy Complete your Q-learning agent by implementing epsilon-greedy action selection in getAction , meaning it chooses random actions an epsilon fraction of the time, and follows its current best Q-values otherwise. Note that choosing a random action may result in choosing the best action - that is, you should not choose a random sub-optimal action, but rather any random legal action.
You can choose an element from a list uniformly at random by calling the random. You can simulate a binary variable with probability p of success by using util. However, your average returns will be lower than the Q-values predict because of the random actions and the initial learning phase. You can also observe the following simulations for different epsilon values. Does that behavior of the agent match what you expect? To test your implementation, run the autograder: With no additional code, you should now be able to run a Q-learning crawler robot: If this doesn't work, you've probably written some code too specific to the GridWorld problem and you should make it more general to all MDPs.
This will invoke the crawling robot from class using your Q-learner. Play around with the various learning parameters to see how they affect the agent's policies and actions.
Note that the step delay is a parameter of the simulation, whereas the learning rate and epsilon are parameters of your learning algorithm, and the discount factor is a property of the environment. Question 8 1 point : Bridge Crossing Revisited First, train a completely random Q-learner with the default learning rate on the noiseless BridgeGrid for 50 episodes and observe whether it finds the optimal policy.
Now try the same experiment with an epsilon of 0. Epsilon is controlled by -e , learning rate by -l. This means your answer should be correct even if for instance we rotated the entire bridge grid world 90 degrees. Pacman will play games in two phases. In the first phase, training, Pacman will begin to learn about the values of positions and actions. Because it takes a very long time to learn accurate Q-values even for tiny grids, Pacman's training games run in quiet mode by default, with no GUI or console display.
Once Pacman's training is complete, he will enter testing mode. When testing, Pacman's self. Test games are shown in the GUI by default. Without any code changes you should be able to run Q-learning Pacman for very tiny grids as follows: Note that PacmanQAgent is already defined for you in terms of the QLearningAgent you've already written.
The autograder will run test games after the training games. Hint: If your QLearningAgent works for gridworld. In particular, because unseen actions have by definition a Q- value of zero, if all of the actions that have been seen have negative Q-values, an unseen action may be optimal. Beware of the argmax function from util. These values will then be accessible as self.
Thus, you will only see Pacman play the last 10 of these games. The number of training games is also passed to your agent as the option numTraining. Note: If you want to watch 10 training games to see what's going on, use the command: During training, you will see output every games with statistics about how Pacman is faring. Epsilon is positive during training, so Pacman will play poorly even after having learned a good policy: this is because he occasionally makes a random exploratory move into a ghost.
As a benchmark, it should take between 1, and games before Pacman's rewards for a episode segment becomes positive, reflecting that he's started winning more than losing. By the end of training, it should remain positive and be fairly high between and Make sure you understand what is happening here: the MDP state is the exact board configuration facing Pacman, with the now complex transitions describing an entire ply of change to that state.
The intermediate game configurations in which Pacman has moved but the ghosts have not replied are not MDP states, but are bundled in to the transitions. However, you will find that training the same agent on the seemingly simple mediumGrid does not work well. In our implementation, Pacman's average training rewards remain negative throughout training. At test time, he plays badly, probably losing all of his test games. Training will also take a long time, despite its ineffectiveness.
Pacman fails to win on larger layouts because each board configuration is a separate state with separate Q-values. He has no way to generalize that running into a ghost is bad for all positions. Obviously, this approach will not scale.
Question 10 3 points : Approximate Q-Learning Implement an approximate Q-learning agent that learns weights for features of states, where many states might share the same features. Write your implementation in ApproximateQAgent class in qlearningAgents. Note: Approximate Q-learning assumes the existence of a feature function f s,a over state and action pairs, which yields a vector f1 s,a.. We provide feature functions for you in featureExtractors. Feature vectors are util.
Counter like a dictionary objects containing the non-zero pairs of features and values; all omitted features have value zero. In your code, you should implement the weight vector as a dictionary mapping features which the feature extractors will return to weight values. You will update your weight vectors similarly to how you updated Q-values: Note that the term is the same as in normal Q-learning, and is the experienced reward.
By default, ApproximateQAgent uses the IdentityExtractor , which assigns a single feature to every state,action pair. With this feature extractor, your approximate Q- learning agent should work identically to PacmanQAgent. You can test this with the following command: Important: ApproximateQAgent is a subclass of QLearningAgent , and it therefore shares several methods like getAction.
Make sure that your methods in QLearningAgent call getQValue instead of accessing Q-values directly, so that when you override getQValue in your approximate agent, the new approximate q-values are used to compute actions.
0コメント