DS/CS 442 Spring 2021 Project 4: Ghostbusters Due: Sunday 4/25 at 11:59 pm I can hear you, ghost. Running won't save you from my Particle filter! Introduction Pacman spends his life running from...

1 answer below »
Python assignment : Do only question 1,2 ,3,4,5


DS/CS 442 Spring 2021 Project 4: Ghostbusters Due: Sunday 4/25 at 11:59 pm I can hear you, ghost. Running won't save you from my Particle filter! Introduction Pacman spends his life running from ghosts, but things were not always so. Legend has it that many years ago, Pacman’s great grandfather Grandpac learned to hunt ghosts for sport. However, he was blinded by his power and could only track ghosts by their banging and clanging. In this project, you will design Pacman agents that use sensors to locate and eat invisible ghosts. You’ll advance from locating single, stationary ghosts to hunting packs of multiple moving ghosts with ruthless efficiency. The code for this project contains the following files, available as a zip archive. Note: In this project you only need to submit the token generated by submission_autograder.py . See Submission for details. Files you'll edit: bustersAgents.py Agents for playing the Ghostbusters variant of Pacman. inference.py Code for tracking ghosts over time using their sounds. Files you will not edit: busters.py The main entry to Ghostbusters (replacing Pacman.py) bustersGhostAgents.py New ghost agents for Ghostbusters distanceCalculator.py Computes maze distances game.py Inner workings and helper classes for Pacman ghostAgents.py Agents to control ghosts graphicsDisplay.py Graphics for Pacman graphicsUtils.py Support for Pacman graphics keyboardAgents.py Keyboard interfaces to control Pacman layout.py Code for reading layout files and storing their contents util.py Utility functions Files to Edit and Submit: You will fill in portions of bustersAgents.py and inference.py during the assignment. Please do not change the other files in this distribution. Note: You only need to submit tracking.token , generated by running submission_autograder.py . It contains the evaluation results from your local autograder, and a copy of all your code. You do not need to submit any other files. https://inst.eecs.berkeley.edu/~cs188/fa19/assets/files/tracking.zip javascript: Amulya Yadav 2022 Amulya Yadav 4/23 at 11:59 PM 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. However, the correctness of your implementation – not the autograder’s judgements – 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, section, and the discussion forum 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. Discussion: Please be careful not to post spoilers. Ghostbusters and BNs In the DS/CS 442 version of Ghostbusters, the goal is to hunt down scared but invisible ghosts. Pacman, ever resourceful, is equipped with sonar (ears) that provides noisy readings of the Manhattan distance to each ghost. The game ends when Pacman has eaten all the ghosts. To start, try playing a game yourself using the keyboard. The blocks of color indicate where the each ghost could possibly be, given the noisy distance readings provided to Pacman. The noisy distances at the bottom of the display are always non-negative, and always within 7 of the true distance. The probability of a distance reading decreases exponentially with its difference from the true distance. Your primary task in this project is to implement inference to track the ghosts. For the keyboard based game above, a crude form of inference was implemented for you by default: all squares in which a ghost could possibly be are shaded by the color of the ghost. Naturally, we want a better estimate of the ghost’s position. Fortunately, Bayes Nets provide us with powerful tools for making the most of the information we have. Throughout the rest of this project, you will implement algorithms for performing both exact and approximate inference using Bayes Nets. The project is challenging, so we do encouarge you to start early and seek help when necessary. While watching and debugging your code with the autograder, it will be helpful to have some understanding of what the autograder is doing. There are 2 types of tests in this project, as differentiated by their .test files found in the subdirectories of the test_cases folder. For tests of class DoubleInferenceAgentTest , you will see visualizations of the inference distributions generated by your code, but all Pacman actions will be pre-selected according to the actions of the staff implementation. This is necessary to allow comparision of your distributions with the staff’s distributions. The second type of test is GameScoreTest , in which your BustersAgent will actually select actions for Pacman and you will watch your Pacman play and win games. As you implement and debug your code, you may find it useful to run a single test at a time. In order to do this you will need to use the -t flag with the autograder. For example if you only want to run the first test of question 1, use: In general, all test cases can be found inside test_cases/q* . For this project, it is possible sometimes for the autograder to time out if running the tests with graphics. To accurately determine whether or not your code is efficient enough, you should run the tests with the --no-graphics flag. If the autograder passes with this flag, then you will receive full points, even if the autograder times out with graphics. Question 0 (0 points): DiscreteDistribution Class Throughout this project, we will be using the DiscreteDistribution class defined in inference.py to model belief distributions and weight distributions. This class is an extension of the built-in Python dictionary class, where the keys are the different discrete elements of our distribution, and the corresponding values are proportional to the belief or weight that the distribution assigns that element. This question asks you to fill in the missing parts of this class, which will be crucial for later questions (even though this question itself is worth no points). First, fill in the normalize method, which normalizes the values in the distribution to sum to one, but keeps the proportions of the values the same. Use the total method to find the sum of the values in the distribution. For an empty distribution or a distribution where all of the values are zero, do nothing. Note that this method modifies the distribution directly, rather than returning a new distribution. python busters.py Copy python autograder.py -t test_cases/q1/1-ObsProb Copy javascript: Second, fill in the sample method, which draws a sample from the distribution, where the probability that a key is sampled is proportional to its corresponding value. Assume that the distribution is not empty, and not all of the values are zero. Note that the distribution does not necessarily have to be normalized prior to calling this method. You may find Python’s built-in random.random() function useful for this question. There are no autograder tests for this question, but the correctness of your implementation can be easily checked. We have provided Python doctests as a starting point, and you can feel free to add more and implement other tests of your own. You can run the doctests using: Note that, depending on the implementation details of the sample method, some correct implementations may not pass the doctests that are provided. To thoroughly check the correctness of your sample method, you should instead draw many samples and see if the frequency of each key converges to be proportional of its corresponding value. Question 1 (2 points): Observation Probability In this question, you will implement the getObservationProb method in the InferenceModule base class in inference.py . This method takes in an observation (which is a noisy reading of the distance to the ghost), Pacman’s position, the ghost’s position, and the position of the ghost’s jail, and returns the probability of the noisy distance reading given Pacman’s position and the ghost’s position. In other words, we want to return P(noisyDistance | pacmanPosition, ghostPosition) . The distance sensor has a probability distribution over distance readings given the true distance from Pacman to the ghost. This distribution is modeled by the function busters.getObservationProbability(noisyDistance, trueDistance) , which returns P(noisyDistance | trueDistance) and is provided for you. You should use this function to help you solve the problem, and use the provided manhattanDistance function to find the distance between Pacman’s location and the ghost’s location. However, there is the special case of jail that we have to handle as well. Specifically, when we capture a ghost and send it to the jail location, our distance sensor deterministically returns None , and nothing else. So, if the ghost’s position is the jail position, then the observation is None with probability 1, and everything else with probability 0. Conversely, if the distance reading is not None , then the ghost is in jail with probability 0. If the distance reading is None then the ghost is in jail with probability 1. Make sure you handle this special case in your implementation. To test your code and run the autograder for this question: As a general note, it is possible for some of the autograder tests to take a long time to run for this project, and you will have to exercise patience. As long as the autograder doesn’t time out, you should be fine (provided that you actually pass the tests). Question 2 (3 points): Exact Inference Observation In this question, you will implement the observeUpdate method in ExactInference class of inference.py to correctly update the agent’s belief distribution over ghost positions given an observation from Pacman’s sensors. You are implementing the online belief update for observing new evidence. The observeUpdate method should, for this problem, update the belief at every position on the map after receiving a sensor reading. You should iterate your updates over the variable self.allPositions which includes all legal positions plus the special jail position. Beliefs represent the probability that the ghost is at a particular location, and are stored as a DiscreteDistribution object in a field called self.beliefs
Answered Same DayApr 23, 2022

Answer To: DS/CS 442 Spring 2021 Project 4: Ghostbusters Due: Sunday 4/25 at 11:59 pm I can hear you, ghost....

Sandeep Kumar answered on Apr 23 2022
106 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here