UMBC CMSC 471 02 Spring 2021 |
• home • about • schedule • hw • exams • notes • colab • github • resources • papers • news • discord • webex • |
HW2: Cats and Dogsout 2/4, due 2/18click to accept your repositoryThis short assignment will give you a bit of experience in developing heuristics for Algorithm A*. 1 The DOGCAT GameDOGCAT is a simple word game that I learned from Jeff Shrager, who was the TA when I first taught an AI course in 1980. We used it for a Lisp programming assignment. You are given two words with the same number of letters (we will be using three and four letter words) in each, e.g. DOG and CAT. Your goal is to transform the first word into the second by replacing one letter at a time with any other letter as long as the result is a proper English word. For example, we could change DOG to FOG but not to GOG (not a proper English word) or to GOD (two letters were changed). Thus, one way of getting from DOG to CAT might be:
There are many ways to make most translations. Here is another way:
Some examples are very hard to do. Try changing WHY to ASK. The game can be generalized to words of other lengths and we can also make the problem more interesting by defining other properties of the transformation we want to optimize. For this assignment, we'll work with words of three or four characters. We will define three cost measures:
2. What to doStart by accepting your GitHub Classroom repository. This will contain the starter file dc.py that you will need to complete as well as the AIMA Python required files search.py and utils.py files. Then study the aima search.py file. You should look at the Problem class and its methods, in particular, and the search algorithms. Write a generic version of a DC class that solves instances of the dog_cat problem given an initial and final word using the aima code for astar_search. We've created a stub file for dc.py, which is the only file you need to complete. To complete this stub, you must finish the DC class by completing the init, actions, result, goal_test, h and repr methods. You will probably need to write some auxiliary functions as well. Your heuristic h function must be admissible, that is, always returning an estimate that is less than or equal to the true value. It should not be the trivial estimate of 0, of course. Note that both your path_cost and h methods will have to be sensitive to the problem's cost parameter. We've provided you with dictionary of all of the legal English three and four letter words along with their rarity measures. See this datafile words34.txt.gz and the code in the dc.py stub that loads it: import gzip ... dict_file = "words34.txt.gz" 3. Testing your codeOnce you've written your dc.py file you can test it with dcsolve.py and dctest.py. The dcsolve.py script takes an initial and goal word and an optional cost measure and shows the solution found by our dc.py problem along with the cost and time taken. The dctest.py script takes no arguments and runs a number of examples using each of the three cost measure. See this example of its use. Note that your program may not produce exactly he same answers, since the A* algorithm with an admissible heuristic finds one of shortest solutions to a problem -- there may be several that are equally short.HW2> python dcsolve.py dog cat steps 3: dog cog cot cat (0.0020) HW2> python dcsolve.py bear duck steps steps 4: bear beak beck deck duck (0.0019) HW2> python dcsolve.py bear duck scrabble scrabble 11: bear beak beck deck duck (0.0034) HW2> python dcsolve.py bear duck frequency frequency 38: bear beak beck buck duck (1.4166) What to hand inThe assignment is due by midnight on Thursday, February 18. After you have written, debugged and tested your dc.py file, you should do the following.
Background reading
|
BIT.LY/471s21 • CMSC 471 02 Spring 2021 • CSEE • UMBC |