Unformatted text preview:

RULES ABOUT: what your Life Stage is6.871 Problem Set 3 Handed Out: Thur March 16, 2006Due: Thur March 23, 2006JOSHUA and Rule-based Systems Exercises I. Introduction This is an exercise designed to do two things: it will allow you to explore the online behavior of a rule-based system in many ways and it will get you familiar with Joshua, a tool that many people find useful for building their term project.The Knowledge Base (The Investment Rules Again)Following on with the paper exercises you did, in this exercise we’ll use the same rule set to decide among sixof the most common categories of mutual funds. The system assumes that you have $2000 to invest and canhelp select among the following possibilities:- a money-market fund- an income fund (e.g., bonds)- an aggressive growth fund- a mixed growth and income fund (abbreviated “G&I”)- a conservative growth fund- a tax-free fund- none (i.e., don't invest) For ease of reference, the complete set of rules in English is found at the end of this handout. As before, we have used some formatting conventions to help make their structure clear. Consider rule 12, for instance:12] if Investment Goal = RETIREMENT and Number Of Years To Retirement < 10then Category Of Fund = CONSERVATIVE GROWTH .8 Each rule is expressed in terms of an if part (the premise) and a then part (the conclusion). In rule 12 there aretwo clauses in the premise and (as in all of our rules) one in the conclusion. Each clause in a rule is expressed in terms of an attribute, object, and its value. As a formatting convention,attributes are written as phrases with their first letters capitalized (e.g., Investment Goal, Number Of Years ToRetirement, Category Of Fund); values are written in all capitals (RETIREMENT, 10, CONSERVATIVEGROWTH). The first clause thus asks whether the attribute Invest Goal has the value RETIREMENT, or, insmoother English, “the goal for this investment is to fund your retirement.” For ease of reading the object isoften left implicit, e.g., in this case investment goal of user is retirement.Putting the whole rule in somewhat better English, it says:if the goal for this investment is to fund your retirement, andthe number of years until you retire is less than 10, then the category of fund to select is the conservative growth funds. In Joshua the rule looks somewhat different; we’ll come to that below. Note in particular that the rule numbersin the handout at the end are for convenience. Joshua names rules rather than numbers them.- 1 -6.871 Problem Set 3 II. Getting Started You will be using the Allegro Common Lisp interpreter on Athena and the Joshua knowledge base found onthe course web page. We’ll start by familiarizing you with Allegro Common Lisp on Athena and Joshua. (While it is possible to install all this on a Windows PC, we strongly recommend against doing that. You can work from a Windows PC by ssh’ing to athena-x.dialup.mit.edu (via SecureCRT, make sure you configure the connection to Forward X11 packets,), while running XWin-32. Both SecureCRT and XWin-32 are available for installation from http://web.mit.edu/software/win.html)1. Log onto an Athena machine (athena-x.dialup.mit.edu works if you’re not in an Athena cluster). 2. athena% add acl_v6.2-alisp 6.871 This will attach the Allegro Common Lisp locker for the version we will be using, and the course locker. 3. Download from the course web page the knowledge base file invest-josh-kb.custom.lisp.Put this in your local directory. This will make you a local copy of the example knowledge base. 4. athena% chmod 700 ~/invest-josh-kb.custom.lispThis will just make sure that the file is readable.5. athena% joshua8 & Depending on server load, this may take awhile. An XEmacs will start and it will start up a lisp inferior with all the Joshua code in it. Eventually, you’ll see a CL-USER(1): prompt in the XEmacs window (the one with the *common-lisp* label).6. CL-USER(1): (clim-env:start-clim-environment)A small window called Navigator will pop up. 7. In the Navigator window, select Lisp Listener from the Tools menu.A Lisp Listener window will be raised, and you will see a ⇒ prompt. (Yes, windows all over the place.)8. ⇒:joshua syntax yes This command is necessary to enable the square bracket predication syntax. If you ever in the future forget to do this before compiling your project code, you will get an error message concerning a comma not being inside a backquote. 9. ⇒:edit file ~/invest-josh-kb.custom.lispThis will open the code in a buffer in your XEmacs window.10. Select buffer from the Compile other submenu of the ACLFile menu in XEmacs 11. Watch the status bar at the bottom of XEmacs for the message Compiling... done.. At this point, returnto your Lisp Listener window. 12. Now you can try asking what category of fund someone should invest in. Just type the following command: ⇒ (ask [category-of-fund ben-bitdiddle ?x] #’print-answer-with-certainty) You are of course free to inquire about people other than Ben Bitdiddle, our canonical test subject.See notes at the end of the handout for how to handle errors and the debugger.- 2 -6.871 Problem Set 3 III. Using Joshua: Predicates and Predications Every fact in Joshua’s database is called a predication. A predication a list enclosed by square brackets.For example: [FATHER-OF JOHN MARY] might mean that JOHN is the father of MARY. We define predicates (what we have called “attributes” inclass) using the define-predicate macro. To define a simple predicate, all we have to do is this (as you’llsee below, the prompt character for Joshua is a right-arrow):⇒ (define-predicate father-of (father child)) The first argument to the macro is the name of the predicate, and the second is an argument list. Thereis an optional third argument to the macro, which is a list of types for the predicate to inherit from. This isan advanced feature you don’t have to know about right now, but if you are interested, you can see byexamining the code that accompanies this problem set how predicates that have certainty factors aredefined, inheriting from a base class that provides certainty factor support. To undefine a predicate, simply execute this command: ⇒ (undefine-predicate ’father-of) IV. Using Joshua: TELL-ing things The first and most simple thing you can do with Joshua is to tell it facts. Take, for example the followingcode: ⇒(tell [HAS-HEALTH-INSURANCE BEN-BITDIDDLE YES]) We can also tell


View Full Document

MIT 6 871 - Problem Set 3

Download Problem Set 3
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Problem Set 3 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Problem Set 3 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?