Unformatted text preview:

6.871 Problem Set 2 Handed Out: Thur March 3, 2005 Due: Thur April 7 JOSHUA and Rule-based Systems Exercises I. Introduction This is an exercise designed to do two things: it will allow you to explore the behavior of a rule-based system in many ways and it will get you familiar with Joshua, a tool that many people found useful last term for building their term project. The Knowledge Base In this exercise we’ll be using a simple system that can help you to decide among six of the most common categories of mutual funds. The system assumes that you have $2000 to invest and can help 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) The complete set of rules in English is found at the end of this handout. To help you read them, 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 < 10 then 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 are two 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 To Retirement, Category Of Fund); values are written in all capitals (RETIREMENT, 10, CONSERVATIVE GROWTH). The first clause thus asks whether the attribute Invest Goal has the value RETIREMENT, or, in smoother English, “the goal for this investment is to fund your retirement.” For ease of reading the object is often 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, and the 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 numbers in the handout at the end are for convenience. Joshua names rules rather than numbers them. - 1 - 16.871 Problem Set 2 II. Getting Started You will be using the Allegro Common Lisp interpreter on the server and the Joshua knowledge base found on the assignments page. We’ll start by familiarizing you with Allegro Common Lisp on the server and Joshua. 1. Log onto the server. 2. server% 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 assignments 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. server% chmod 700 ~/invest-josh-kb.custom.lisp This will just make sure that the file is readable. 5. server% 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.lisp This 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, return to 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 2 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” in class) using the define-predicate macro. To define a simple predicate, all we have to do is this (as you’ll see 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. There is an optional third argument to the macro, which is a list of types for the predicate to inherit from. This is an advanced feature you don’t have to know about right now, but if you are interested, you can see by examining the code that accompanies this problem set how predicates that have certainty factors are defined, 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 following code: ⇒(tell [HAS-HEALTH-INSURANCE BEN-BITDIDDLE YES]) We can also tell things that are justified by certainty factors, like so: ⇒(tell [HAS-LIFE-INSURANCE BEN-BITDIDDLE YES] :justification ’((user-input 0.8))) Note that we can replace the 0.8 with any certainty factor we choose, and that the symbol USER-INPUT is just a notation to let us to know where the justification comes from; you can write anything there. UNTELL-ing things is also possible, for example: ⇒ (untell [HAS-LIFE-INSURANCE


View Full Document

MIT 6 871 - Problem Set 2

Download Problem Set 2
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 2 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 2 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?