Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!ames!ucbcad!ucbvax!decvax!decwrl!sun!imagen!turner From: turner@imagen.UUCP (D'arc Angel) Newsgroups: comp.ai Subject: AI Expert sources (part 1 of 9) Message-ID: <793@imagen.UUCP> Date: Sun, 18-Jan-87 22:39:37 EST Article-I.D.: imagen.793 Posted: Sun Jan 18 22:39:37 1987 Date-Received: Mon, 19-Jan-87 19:36:58 EST Organization: The Houses of the Holy Lines: 1527 Keywords: ai,sources here it is and rather lengthly, cat all nine parts together and shar it, don't forget to remove my .signature at the end of each file. #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create: # AIAPP.JAN # CONTNT.JAN # EXPERT.JAN # FILES.JAN # OPSNET.JAN # PERCEP.JAN # This archive created: Sun Jan 18 19:24:39 1987 # By: D'arc Angel (The Houses of the Holy) export PATH; PATH=/bin:/usr/bin:$PATH echo shar: "extracting 'AIAPP.JAN'" '(29884 characters)' if test -f 'AIAPP.JAN' then echo shar: "will not over-write existing file 'AIAPP.JAN'" else sed 's/^ X//' << \SHAR_EOF > 'AIAPP.JAN' X X X AI Apprentice X by Bill Thompson and Bev Thompson X "Creating Expert Systems from Examples" X January 1987 AI EXPERT X X X XFigure 1. X X batch# part# power symptom Problem X X b 312 ac no power powersupply X a 312 ac weak gear bad X c 412 dc sparking powersupply X d 412 ac no power wiring X c 212 dc sparking powersupply X c 412 ac weak wiring X a 212 ac no power gear bad X b 412 dc weak wiring X b 212 ac weak gear bad X X X XFigure 2 - A decision tree produced from the data in Table 1. X X X batch# part# power symptom Result X X b 412 ac weak gear bad X a 212 dc weak powersupply X d 212 dc sparking wiring X d 412 ac no power powersupply X X X XTable 1 - A training set of data for a repair problem. X X If batch# is a X then result is gear bad. X X If batch# is b X and part# is 212 X then result is gear bad. X X If batch# is b X and part# is 312 X then result is powersupply. X X If batch# is b X and part# is 412 X then result is wiring. X X If batch# is c and power is ac X then result is wiring. X X If batch# is c X and power is dc X then result is powersupply. X X If batch# is d X then result is wiring. X X X batch# ? X a: ---------------------------------------------gear bad X b:part# ? X 212: ---------------------------------------- gear bad X 312: ---------------------------------------- powersupply X 412: ---------------------------------------- wiring X c:power?? X ac: ----------------------------------------- wiring X dc: ----------------------------------------- powersupply X d: --------------------------------------------- wiring X X X XTable 2 - A new set of data collected for the repair problem. This data X is used for validation of the solution. X X Xclinical descript distribution group Result X Xfever upper resp. epidemic respiratory parainfluenza Xchills lower resp. local enteric adenovirus Xrash mid resp. children exanthems mumps Xswelling hospital latent rhinovirus Xmalaise youngadults echo Xheadache universal coxasackie Xcough varicella X X X rubella X XTable 3 - Definitions of results and attributes for identifying viruses. X Xlevel type of subject programming cover type basic Author X software matter covered language Xintro/adv gen/spec gen/spec no/yes soft/hard no/yes X1. 1. 4. 3. soft 5. Jones X2. 5. 5. 4. soft 1. Smith X1. 1. 1. 3. soft 1. Fisher X1. 1. 1. 3. hard 5. Mitchell X1. 1. 1. 1. soft 1. Argyle X5. 1. 5. 5. hard 1. Chang X X X Table 4 - An example set for selecting a textbook. This set was produced X using the Flexigrid program. X Xsubject matter ? (gen/spec) X < 2.50: programming covered ? (no/yes) X < 2.00: ---------------------------------- Concepts X >=2.00: cover ? X hard: -------------------------- Today's X soft: -------------------------- Information X >=2.50: level ? (intro/adv) X < 1.50: -------------------------------- Society X >=1.50: level ? (intro/adv) X < 3.50: ------------------------ Applications X >=3.50: ------------------------ Data_structures X X Xupply of serotinous cones X. X Xprompt 10/acre adequate XAre 10 trees per acre adequate to seed the area ? X. X Xtrans 10/acre adequate X10 per acre is /not/ adequate X. X Xprompt burning planned XHas a prescribed burning been planned ? X. X Xtrans burning planned Xburning is /not/ planned X. X Xtrans use seed tree XYou should /not/ use seed trees to seed the area X. X 15 Xif branch 11 is yes Xand pine desired is yes Xand pine suited is yes Xand desirable seed is yes Xand serotinous cones is yes Xand 10/acre adequate is yes Xand burning planned is no Xthen silviculture method is clearcut Xand branch 17 is yes . X Xtrans silvaculture method Xthe best silviculture method to use X. X X16 Xif branch 11 is yes Xand pine desired is yes Xand pine suited is yes Xand desirable seed is yes Xand serotinous cones is yes Xand 10/acre adequate is no Xthen silviculture method is clearcut Xand branch 17 is yes . X X17 Xif branch 11 is yes Xand pine desired is yes Xand pine suited is yes Xand desirable seed is yes Xand serotinous cones is no Xand two harvests wanted is yes Xand two harvests possible is yes Xthen silviculture method is shelterwood Xand branch 17 is yes . X Xprompt two harvests wanted XDo you want to do two commercial harvests on this area ? X. X Xtrans two harvests wanted Xtwo commercial harvests are /not/ wanted X. X Xprompt two harvests possible XIs it possible to get two harvests from this area ? X. X Xtrans two harvests possible Xtwo harvests can /not/ be done on this area X. X X18 Xif branch 11 is yes Xand pine desired is yes Xand pine suited is yes Xand desirable seed is yes Xand serotinous cones is no Xand two harvests wanted is yes Xand two harvests possible is no then silviculture method is clearcut Xand branch 17 is yes . X X19 Xif branch 11 is yes Xand pine desired is yes Xand pine suited is yes Xand desirable seed is yes Xand serotinous cones is no Xand two harvests wanted is no Xthen silviculture method is clearcut Xand branch 17 is yes . X X20 Xif branch 11 is yes Xand pine desired is yes Xand pine suited is yes Xand desirable seed is no Xthen silviculture method is clearcut Xand branch 17 is yes . X X21 Xif branch 11 is yes Xand pine desired is yes Xand pine suited is no Xthen convert is yes Xand recommend is convert . X Xtrans convert Xyou should /not/ convert the area to some more desirable kind of tree X. X X22 Xif branch 11 is yes Xand pine desired is no Xthen convert is yes Xand recommend is convert . X X X26 Xif branch 17 is yes Xand adequate seedbed is yes Xthen branch 18 is yes . X Xprompt adequate seedbed XIs there an adequate seedbed for planting ? X. X Xtrans adequate seedbed Xthere is /not/ an adequate seedbed for planting X. X X27 Xif branch 17 is yes Xand adequate seedbed is no Xthen prepare site is yes Xand branch 18 is yes . X trans prepare site Xthe site should /not/ be prepared before planting X. X X28 Xif branch 18 is yes Xand silviculture method is shelterwood Xthen use natural seeding is yes Xand recommend is use natural seeding . X Xtrans use natural seeding Xnatural seeding techniques should /not/ be used X. X X29 Xif branch 18 is yes Xand silviculture method is clearcut Xand improved stock is yes Xthen plant is yes Xand recommend is plant . X Xprompt improved stock XIs there improved planting stock available ? X. X Xtrans improved stock Xthere is /not/ improved stock available X. X Xtrans plant Xsince there is better stock available you can /not/ plant using that stock X. X X30 Xif branch 18 is yes Xand silviculture method is clearcut Xand improved stock is no Xand good cone supply is yes Xthen scatter cones is yes Xand recommend is scatter cones . X Xprompt good cone supply XIs there a good supply of serotinous cones on the area ? X. X Xtrans good cone supply Xthere is /not/ a good cone supply X. X Xtrans scatter cones Xyou should /not/ scatter the supply of serotinous cones over the area X. X X31 Xif branch 18 is yes Xand silviculture method is clearcut Xand improved stock is no Xand good cone supply is no Xthen direct seed is yes Xand recommend is direct seed . X Xtrans direct seed XSince the cone supply is inadequate, you should /not/ directly seed the area X. X X X------------------------------------------------------------------------- X XThe following comments are not a part of the knowledge base. If you Xtry to run the knowledge base this part of the file should be removed X X XAbbreviated KEY X X1. stocking good is yes ............................. 2 X1. stocking good is no ............................. 10 X 2. avg < 5 is yes ................................ 3 X 2. avg < 5 is no ................................. 4 X3. 2000 + per acre is yes ..........WEED OR CLEAN.... 8 X3. 2000 + per acre is no ............................ 8 X 4. age is mature ................................. 11 X 4. age is immature ............................... 5 X5. site index > 60 is yes ........................... 6 X5. site index > 60 is no ............................ 9 X 6. product size is large ......................... 7 X 6. product size is small ......................... 9 X7. 120 + basal area is yes .........THIN............. 9 X7. 120 + basal area is no ........................... 9 X 8. severe competition is yes ....RELEASE.......... 9 X 8. severe competition is no ...................... 9 X9. high risk is yes ................................. CONTROL IF FEASIBLE X9. high risk is no .................................. WAIT X 10. other resources is yes ....................... MAINTAIN X 10. other resources is no ........................ 11 X11. pine suitable is yes ............................. 12 X11. pine suitable is no .............................. CONVERT X 12. desirable seed is yes ........................ 13 X 12. desirable seed is no ........USE CLEARCUT..... 17 X13. serotinous cones is yes .......................... 14 X13. serotinous cones is no ........................... 16 X 14. 10/acre adequate is yes ...................... 15 X 14. 10/acre adequate is no ......USE CLEARCUT..... 17 X15. burning planned is yes ........................... USE SEED TREE X15. burning planned is no ...........USE CLEARCUT..... 17 X 16. two harvests wanted is yes ..USE SHELTERWOOD.. 17 X 16. two harvests wanted is no ...USE CLEARCUT..... 17 X17. adequate seedbeds is yes ......................... 18 X17. adequate seedbeds is no .........PREPARE SITE..... 18 X 18. silviculture method is shelterwood ........... USE NATURAL SEEDING X 18. silviculture method is clearcut .............. 19 X19. improved stock is yes ............................ PLANT X19. improved stock is no ............................. 20 X 20. good cone supply is yes ...................... SCATTER CONES X 20. good cone supply is no ....................... DIRECT SEED X X X XThe purpose of this exercise is to show how a knowledge base can be designed to directly follow a key. There are several places where the XKB could have been made more efficient, but this would have meant Xdeparting from the order of the key. You might find it an interesting Xexercise to explore other ways this same information could have been Xrepresented in the KB. X XThe key appears in the Managers Handbood for Jack Pine in the North Central XStates. The Handbook was produced by the North Central Forest Experiment XStation of the Forest Service of the U.S. Dept. of Agriculture. Our Xintention in writing this knowledge base is to show the structure of a Xknowledge base written for a backward chaining inference engine directly Xfrom an existing document. If this KB were to be actually used, it would Xneed to have clearer questions and more explanations to the user. These Xexplanations are provided in the handbook and could be easily incorporated Xinto the knowledge base. X XThe knowledge base will run on the expert system shell MicroExpert which is Xan example of a backward chaining inference engine. MicroExpert is Xavailable from McGraw-Hill for $49.95 and can be ordered by calling 1-800- X628-0004 or, in NY, 212-512-2999 . The knowledge base is described in the Xcolumn AI Apprentice which appears in the November issue of AI Expert Xmagazine. The design details of the inference engine which runs the KB is Xdescribed in the article "Inside an Expert System" in the April 1985 Xisuue of BYTE magazine. X XMicroExpert, AI Apprentice and "Inside an Expert System" are all written Xby Bev and Bill Thompson . We're always happy to hear about your thoughts Xand comments, good or bad on any of our work. Contact us at the address Xbelow, on Compuserve or BIX. Our Compuserve id is 76703,4324 and we can be Xreached by Easyplex or in the AI Expert Forum. Our BIX id is bbt and we Xmay be contacted via BIXmail or by leaving comments in the MicroExpert Xconference. X XBill and Bev Thompson XR.D. 2 Box 430 XNassau, N.Y. 12123 X X X TREES.PRO X PROLOG program X X X/* This PDPROLOG program implements a knowledge base based upon the X following key: X X To run the program type "go." X Caution - This program can be very S L O W. X XAbbreviated KEY X X1. stocking good is yes ............................. 2 X1. stocking good is no ............................. 10 X 2. avg < 5 is yes ................................ 3 X 2. avg < 5 is no ................................. 4 X3. 2000 + per acre is yes ..........WEED OR CLEAN.... 8 3. 2000 + per acre is no ............................ 8 X 4. age is mature ................................. 11 X 4. age is immature ............................... 5 X5. site index > 60 is yes ........................... 6 X5. site index > 60 is no ............................ 9 X 6. product size is large ......................... 7 X 6. product size is small ......................... 9 X7. 120 + basal area is yes .........THIN............. 9 X7. 120 + basal area is no ........................... 9 X 8. severe competition is yes ....RELEASE.......... 9 X 8. severe competition is no ...................... 9 X9. high risk is yes ................................. CONTROL IF FEASIBLE X9. high risk is no .................................. WAIT X 10. other resources is yes ....................... MAINTAIN X 10. other resources is no ........................ 11 X11. pine suitable is yes ............................. 12 X11. pine suitable is no .............................. CONVERT X 12. desirable seed is yes ........................ 13 X 12. desirable seed is no ........USE CLEARCUT..... 17 X13. serotinous cones is yes .......................... 14 X13. serotinous cones is no ........................... 16 X 14. 10/acre adequate is yes ...................... 15 X 14. 10/acre adequate is no ......USE CLEARCUT..... 17 X15. burning planned is yes ........................... USE SEED TREE X15. burning planned is no ...........USE CLEARCUT..... 17 X 16. two harvests wanted is yes ..USE SHELTERWOOD.. 17 X 16. two harvests wanted is no ...USE CLEARCUT..... 17 X17. adequate seedbeds is yes ......................... 18 X17. adequate seedbeds is no .........PREPARE SITE..... 18 X 18. silviculture method is shelterwood ........... USE NATURAL SEEDING X 18. silviculture method is clearcut .............. 19 X19. improved stock is yes ............................ PLANT X19. improved stock is no ............................. 20 X 20. good cone supply is yes ...................... SCATTER CONES X 20. good cone supply is no ....................... DIRECT SEED X X X XThe purpose of this exercise is to show how an expert system can be Xdesigned to directly follow a key. There are several places where the Xprogram could have been made more efficient, but this would have meant Xdeparting from the order of the key. You might find it an interesting Xexercise to explore other ways this same information could have been Xrepresented in the program. X XThe key appears in the Managers Handbood for Jack Pine in the North Central XStates. The Handbook was produced by the North Central Forest Experiment XStation of the Forest Service of the U.S. Dept. of Agriculture. Our Xintention in writing this knowledge base is to show the structure of a Xknowledge base written for a backward chaining inference engine directly Xfrom an existing document. If this KB were to be actually used, it would Xneed to have clearer questions and more explanations to the user. These Xexplanations are provided in the handbook and could be easily incorporated Xinto the knowledge base. X This program is similar to the KB for the expert system shell XMicroExpert which is an example of a backward chaining inference engine. XMicroExpert is available from McGraw-Hill for $49.95 and can be ordered Xby calling 1-800-628-0004 or, in NY, 212-512-2999 . XThe knowledge base is described in the AI Apprentice column which appears Xin the November issue of AI Expert magazine. XThe design details of the inference engine which runs the KB is Xdescribed in the article "Inside an Expert System" in the April 1985 Xisuue of BYTE magazine. X XMicroExpert, AI Apprentice and "Inside an Expert System" are all written Xby Bev and Bill Thompson . We're always happy to hear about your thoughts Xand comments, good or bad on any of our work. Contact us at the address Xbelow, on Compuserve or BIX. Our Compuserve id is 76703,4324 and we can be Xreached by Easyplex or in the AI Expert Forum. Our BIX id is bbt and we Xmay be contacted via BIXmail or by leaving comments in the MicroExpert Xconference. X XBill and Bev Thompson XR.D. 2 Box 430 XNassau, N.Y. 12123 */ X X/* Control - In MicroExpert terms, the goal of the consultation is X recommendation */ X Xgo :- clear_kb, X give_advice. Xgive_advice :- recommendation(X), X fail. Xgive_advice :- print_advice. X X/* The rules - X These are implemented this way to mimic the MicroExpert rule set. X Looking at them side by side should show the similarities. */ X Xfact(branch8,yes) :- fact('stocking good',yes), X fact('avg < 5',yes), X fact('2000+ per acre',yes), X recommend('The stand of jack pine must be weeded and cleaned.'). Xfact(branch8,yes) :- fact('stocking good',yes), X fact('avg < 5',yes), X fact('2000+ per acre',no). Xfact(branch9,no) :- fact('stocking good',yes), X fact('avg < 5',no), X fact(age,mature), X assertz(fact(branch11,yes)). Xfact(branch11,yes) :- fact('stocking good',yes), X fact('avg < 5',no), X fact(age,mature), X assertz(fact(branch9,no)). Xfact(branch9,yes) :- fact('stocking good',yes), X fact('avg < 5',no), X fact(age,immature), X fact('site index > 60',yes), X fact('product size',large), fact('120+ basal area',yes), X recommend('It is important to thin the area'). Xfact(branch9,yes) :- fact('stocking good',yes), X fact('avg < 5',no), X fact(age,immature), X fact('site index > 60',yes), X fact('product size',large), X fact('120+ basal area',no). Xfact(branch9,yes) :- fact('stocking good',yes), X fact('avg < 5',no), X fact(age,immature), X fact('site index > 60',yes), X fact('product size',large). Xfact(branch9,yes) :- fact('stocking good',yes), X fact('avg < 5',no), X fact(age,immature), X fact('site index > 60',yes). Xrecommendation(maintain) :- X fact('stocking good',no), X fact('other resources',yes), X recommend('You should maintain the stand in its present condition'). Xfact(branch11,yes) :- fact('stocking good',no), X fact('other resources',no). Xfact(branch9,yes) :- fact(branch8,yes), X fact('severe competition',yes), X recommend('Competing trees should be eliminated.'). Xfact(branch9,yes) :- fact(branch8,yes), X fact('severe competition',no). Xrecommendation(control) :- X fact(branch9,yes), X fact('high risk',yes), X recommend('The current area should be controlled, if at all feasible.'). Xrecommendation(wait) :- X fact(branch9,yes), X fact('high risk',no), X recommend('You should wait before doing anything else to this stand.'). Xrecommendation('use seed tree') :- X fact(branch11,yes), X fact('pine desired',yes), X fact('pine suited',yes), X fact('desirable seed',yes), X fact('serotinous cones',yes), X fact('10/acres adequate',yes), X fact('burning planned',yes), X recommend('You should use seed trees to seed the area.'). Xfact(branch17,yes) :- X fact(branch11,yes), X fact('pine desired',yes), X fact('pine suited',yes), X fact('desirable seed',yes), X fact('serotinous cones',yes), X fact('10/acres adequate',yes), X fact('burning planned',no), X add_fact(silvaculture,clearcut), X recommend('The best silvaculture method to use is clearcut.'). fact(branch17,yes) :- X fact(branch11,yes), X fact('pine desired',yes), X fact('pine suited',yes), X fact('desirable seed',yes), X fact('serotinous cones',yes), X fact('10/acres adequate',no), X add_fact(silvaculture,clearcut), X recommend('The best silvaculture method to use is clearcut.'). Xfact(branch17,yes) :- X fact(branch11,yes), X fact('pine desired',yes), X fact('pine suited',yes), X fact('desirable seed',yes), X fact('serotinous cones',no), X fact('two harvests wanted',yes), X fact('two harvests possible',yes), X add_fact(silvaculture,shelterwood), X recommend('The best silvaculture method to use is the shlterwood method.'). Xfact(branch17,yes) :- X fact(branch11,yes), X fact('pine desired',yes), X fact('pine suited',yes), X fact('desirable seed',yes), X fact('serotinous cones',no), X fact('two harvests wanted',yes), X fact('two harvests possible',no), X add_fact(silvaculture,clearcut), X recommend('The best silvaculture method to use is clearcut.'). Xfact(branch17,yes) :- X fact(branch11,yes), X fact('pine desired',yes), X fact('pine suited',yes), X fact('desirable seed',yes), X fact('serotinous cones',no), X fact('two harvests wanted',no), X add_fact(silvaculture,clearcut), X recommend('The best silvaculture method to use is clearcut.'). Xfact(branch17,yes) :- X fact(branch11,yes), X fact('pine desired',yes), X fact('pine suited',yes), X fact('desirable seed',no), X add_fact(silvaculture,clearcut), X recommend('The best silvaculture method to use is clearcut.'). Xrecommendation(convert) :- X fact(branch11,yes), X fact('pine desired',yes), X fact('pine suited',no), X recommend('You should convert the area to some more desirable kind of tree.'). Xrecommendation(convert) :- X fact(branch11,yes), X fact('pine desired',no), X recommend('You should convert the area to some more desirable kind of tree.'). Xfact(branch18,yes) :- fact(branch17,yes), X fact('adequate seedbed',yes). Xfact(branch18,yes) :- X fact(branch17,yes), X fact('adequate seedbed',no), X recommend('The site should be prepared before planting.'). Xrecommendation('natural seeding') :- X fact(branch18,yes), X fact(silvaculture,shelterwood), X recommend('The natural seeding technique should be used.'). Xrecommendation(plant) :- X fact(branch18,yes), X fact(silvaculture,clearcut), X fact('improved stock',yes), X recommend('Since there is better stock available, you can plant using that stock.'). Xrecommendation('scatter cones') :- X fact(branch18,yes), X fact(silvaculture,clearcut), X fact('improved stock',no), X fact('good cone supply',yes), X recommend('You should scatter the serotinous cones over the area.'). Xrecommendation('direct seed') :- X fact(branch18,yes), X fact(silvaculture,clearcut), X fact('improved stock',no), X fact('good cone supply',no), X recommend('You should directly seed the area.'). X X/* These routines add new facts to the internal knowledge base - kb */ X Xfact(X,Y) :- kb(X,Y),! . Xfact(X,Y) :- not(kb(X,Anything)), X question(X,Answer), X assertz(kb(X,Answer)), X Y = Answer. X Xadd_fact(X,Y) :- kb(X,Y),!. Xadd_fact(X,Y) :- assertz(kb(X,Y)). X Xrecommend(X) :- add_fact(advice,X). X X/* Questions to ask the user */ X Xquestion('stocking good',Ans) :- X print('Is the stocking of the jack pine stand currently'),nl, X print('at least minimum ? '),nl,nl, X print('If you are unsure of how to determine stocking,'),nl, X print('see page 4 in the Managers Handbook for Jack Pine'), X nl, X ask('',Ans,[ yes , no ]). Xquestion('avg < 5',Ans) :- X ask('Is the average diameter of the trees less than 5 inches ?', X Ans,[yes,no]). Xquestion('2000+ per acre',Ans) :- X ask('Are there 2000 or more trees per acre ?',Ans,[yes,no]). question(age,Ans) :- X ask('Is the age of the stand mature or immature ?', X Ans,[mature,immature]). Xquestion('site index > 60',Ans) :- X ask('Is the site index greater than 60 ?',Ans,[yes,no]). Xquestion('product size',Ans) :- X ask('Do you want to manage the timber for large or small products ?', X Ans,[large,small]). Xquestion('120+ basal area',Ans) :- X ask('Is the basal area per acre at least 120 square feet ?', X Ans,[yes,no]). Xquestion('other resources',Ans) :- X ask('Do you want to maintain this condition to support other resources?', X Ans,[yes,no]). Xquestion('severe competition',Ans) :- X ask('Is there severe overstory competition ?',Ans,[yes,no]). Xquestion('high risk',Ans) :- X ask('Is there a high risk of loss or injury ?',Ans,[yes,no]). Xquestion('pine desired',Ans) :- X ask('Do you want to keep jack pine in this area ?',Ans,[yes,no]). Xquestion('pine suited',Ans) :- X ask('Is jack pine well suited to this site ?',Ans,[yes,no]). Xquestion('desirable seed',Ans) :- X ask('Is there a desirable jack pine seed source on the area ?', X Ans,[yes,no]). Xquestion('serotinous cones',Ans) :- X ask('Do the trees on the site have serotinous cones ?',Ans,[yes,no]). Xquestion('10/acres adequate',Ans) :- X ask('Are 10 trees per acre adequate to seed the area ?',Ans,[yes,no]). Xquestion('burning planned',Ans) :- X ask('Has a prescribed burning been planned ?',Ans,[yes,no]). Xquestion('two harvests wanted',Ans) :- X ask('Do you want two commercial harvests on this area ?',Ans,[yes,no]). Xquestion('two harvests possible',Ans) :- X ask('Is it possible to get two harvests from this area ?',Ans,[yes,no]). Xquestion('adequate seedbed',Ans) :- X ask('Is there an adequate seedbed for planting ?',Ans,[yes,no]). Xquestion('improved stock',Ans) :- X ask('Is there an improved planting stock available ?',Ans,[yes,no]). Xquestion('good cone supply',Ans) :- X ask('Is there a good supply of serotinous cones in the area ?', X Ans,[yes,no]). X X/* Utility Routines - to be useful, we should add some routines to allow X the user to ask "How" and "Why" */ X Xdisplay_kb :- kb(X,Y), X print(X,' is ',Y), X nl, X fail. Xdisplay_kb. X X Xprint_advice :- X nl,nl, print('Based upon your responses, the following is recommended :'),nl,nl, X show_advice. Xshow_advice :- X kb(advice,X), X print(X), X nl, X fail. Xshow_advice :- X nl,print('To see the complete set of derived facts,'), X print('type "display_kb."'). X X Xclear_kb :- retract(kb(_,_)), X fail . Xclear_kb. X Xmember(X,[X|_]). Xmember(X,[_|Y]) :- member(X,Y). X Xask(Ques,Ans,LegalResponses) :- X nl,print(Ques,' '), X read(Ans), X member(Ans,LegalResponses),!. Xask(Ques,Ans,LegalResponses) :- X nl,nl,nl, X print('Please respond with : ',LegalResponses),nl,nl, X ask(Ques,Ans,LegalResponses). X X X X X X X X Listings and Figures X printed in AI EXPERT magazine X X X1. Jack pine stand with minimum or higher stocking .................. 2 X1. Jack pine stand with less than minimum stocking .................. 10 X X 2. Average tree diameter less than 5 inches ..................... 3 X 2. Average tree diameter 5 inches or more ....................... 4 X X3. 2,000 or more trees per acre ..................WEED OR CLEAN ..... 8 X3. Less than 2,000 trees per acre ................................... 8 X X 4. Stand is mature .............................................. 11 X 4. Stand is not mature .......................................... 5 X XFigure 1 - Key for forest management taken from USDA Forest Service X Handbook X X X X |-- yes ===> weed or clean X | and do # 8 X |-- yes --- 2000+ per acre-| X | |-- no ===> do # 8 X |-- yes -- diameter-| X | < 5 in. | |-- mature ===> do # 11 Xminimum | |-- no -- age-| Xstocking-| |-- young ===> do # 5 X | X | echo shar: "a missing newline was added to 'AIAPP.JAN'" echo shar: "18 control characters may be missing from 'AIAPP.JAN'" SHAR_EOF if test 29884 -ne "`wc -c < 'AIAPP.JAN'`" then echo shar: "error transmitting 'AIAPP.JAN'" '(should have been 29884 characters)' fi fi echo shar: "extracting 'CONTNT.JAN'" '(2351 characters)' if test -f 'CONTNT.JAN' then echo shar: "will not over-write existing file 'CONTNT.JAN'" else sed 's/^ X//' << \SHAR_EOF > 'CONTNT.JAN' X X Contents -- AI EXPERT X January 1987 X X XARTICLES X-------- X XPlanning with TWEAK Xby Jonathan Amsterdam X XLike all exploratory work in the sciences, AI research proceeds Xin cycles of 'scruffy' exploration and 'neat' consolidation. XAfter years of exploration into different planning algorithm Xdesign strategies, M.I.T.'s David Chapman may have created a new Xera in planning research with his neat summary of more than a Xdecade of scruffy work on an algorithm called TWEAK. X X XRete Match Algorithm Xby Charles L. Forgy and Susan Shepard X XThe Rete Match algorithm is a fast method for comparing a set of Xpatterns to a set of objects to determine all possible matches. XIt may be the most efficient algorithm for performing the match Xoperation on single processor. Developed by Charles L. Forgy in X1974, it has been implemented in several languages in both Xresearch and commercial grade systems. X X XImperative Pattern Matching in OPS5 Xby Dan Neiman X XSurely the Rete Match algorithm is an efficient data structure Xfor implementing production systems. But what else can it be Xused for? Let's look at the OPS5 language as a case study of Xthe Rete net as an experimental tool kit. Then we'll present a Xtechnique that will show the programmer how to use Rete Match as Xa general purpose pattern matching tool. X X XPerceptrons and Neural Nets Xby Peter Reece X XThere are at least ten billion neurons handling over one million Xinput messages per second in the human brain. With many of the Xearlier hardware and software obstacles now overcome, let's look Xback to one of the most successful pattern classification Xcomputers---the Perceptron---and show how you can implement a Xsimple Perceptron on your home computer. X X XDEPARTMENTS X----------- X XBrain Waves X"AI for Competitive Advantage" Xby Eugene Wang, Gold Hill Computers X XAI INSIDER X XEXPERT'S TOOLBOX X"Using Smalltalk to Implement Frames" Xby Marc Rettig X XAI APPRENTICE X"Creating Expert Systems from Examples" Xby Beverly and Bill Thompson X XIN PRACTICE X"Air Traffic Control: A Challenge for AI" Xby Nicholas Findler X XHARDWARE REVIEW X"A LISP Machine Profile: Symbolics 3650" Xby Douglas Schuler, et. al. X XSOFTWARE REVIEW X"Expertelligence's PROLOG for the Mac: XExperPROLOG II" X X echo shar: "a missing newline was added to 'CONTNT.JAN'" echo shar: "159 control characters may be missing from 'CONTNT.JAN'" SHAR_EOF if test 2351 -ne "`wc -c < 'CONTNT.JAN'`" then echo shar: "error transmitting 'CONTNT.JAN'" '(should have been 2351 characters)' fi fi echo shar: "extracting 'EXPERT.JAN'" '(7019 characters)' if test -f 'EXPERT.JAN' then echo shar: "will not over-write existing file 'EXPERT.JAN'" else sed 's/^ X//' << \SHAR_EOF > 'EXPERT.JAN' X X Expert's Toolbox X January 1987 X "Using Smalltalk to Implement Frames" X by Marc Rettig X X X XListing 1 X XDEFINITION OF CLASS SLOT X XDictionary variableSubclass: #Slot X instanceVariableNames: '' X classVariableNames: '' X poolDictionaries: '' X XMETHODS FOR CLASS SLOT X XsetFacet:facetName with:aValue X self at:facetName put:aValue X ^aValue X XgetFacet: facetName X ^self at:facetName ifAbsent:[nil] X XsetValue:aValue X self setFacet:'value' with:aValue X XgetValue X ^self getFacet:'value' X X_________________________________________ XDEFINITION OF CLASS FRAME X XDictionary variableSubclass: #Frame X instanceVariableNames: '' X classVariableNames: '' X poolDictionaries: '' X XMETHODS FOR CLASS FRAME X XsetSlot:slotName facet:facetName contents:aValue X | tempSlot | X tempSlot := self at:slotName X ifAbsent:[self at:slotName put: Slot new]. X tempSlot setFacet:facetName with:aValue. X ^aValue X XgetSlot:slotName facet:facetName X ^(self includesKey:slotName) X ifTrue: [(self at:slotName) getFacet:facetName] X ifFalse:[nil] X XsetSlot:slotName value:aValue X ^self setSlot:slotName facet:'value' contents:aValue XgetSlotValue:slotName X "Get the value facet of a slot. If no such slot, look up the AKO X inheritance chain. It that's no good, run a demon to get the value." X | temp | X ((temp := self getSlot:slotName) isNil) X ifTrue: [((temp := self lookUpAkoChain:slotName) isNil) X ifTrue: [^self runDemonForValue:slotName] X ifFalse:[^temp getValue]] X ifFalse:[(temp includesKey:'value') X ifTrue: [^temp getValue]] X ifFalse:[^self runDemonForValue:slotName]] X XgetSlot:slotName X ^self at:slotName ifAbsent:[nil] X XsetSlot:slotName with:aSlot X ^self at:slotName put:aSlot X XlookUpAkoChain:slotName X "Look up the inheritance chain for a slot with the name in slotName. X If you find it, return the Slot." X ^(self includesKey:'AKO') X ifTrue: [((self isAKO) includesKey:slotName) X ifTrue: [^(self isAKO) getSlot:slotName] X ifFalse:[^(self isAKO) lookUpAkoChain:slotName]] X ifFalse:[nil] X XisAKO X ^self getSlot:'AKO' facet:'value' X XisAKO:aFrame X self setSlot:'AKO' value:aFrame X X____________________________________ XSOME SAMPLE METHODS FOR DEMONS X XaddDemon:aBlock slot:slotName type:demonType X (#('ifNeeded' 'ifAdded' 'ifRemoved') includes:demonType) X ifTrue: [self setSlot:slotName facet:demonType with:aBlock] X ifFalse:[self error:'Invalid Demon Type'] X XrunDemonForValue:slotName X | aBlock | X aBlock := self getSlot:slotName facet:'ifNeeded'. X (aBlock isNil) X ifTrue: [^nil] X ifFalse:[^self setSlot:slotName value:(aBlock value)] X X X XListing 2 X XA SAMPLE HIERARCHY OF FRAMES, SHOWING USE OF DEMONS X | mammal dog firstDog askDemon | Xmammal := Frame new. Xmammal setSlot:'hide' value:'hairy'. Xmammal setSlot:'blood' value:'warm'. X Xdog := Frame new. Xdog isAKO:mammal. Xdog setSlot 'numberOfLegs' value:4. X X" Here is a simple if-needed demon, which will ask the X user for a value,while suggesting a default value." XaskDemon := [Prompter prompt:'What is this doggie''s name? X default:'Phydeaux']. X XfirstDog := Frame new. XfirstDog addDemon:askDemon slot:'name' type:'ifNeeded'. XfirstDog isAKO:dog. XfirstDog setSlot:'color' value:'brown'. X X"This message would cause the demon to be fired off..." Xfido getSlotValue:'name' X X XFRAME.CLS X XDictionary variableSubclass: #Frame X instanceVariableNames: '' X classVariableNames: '' X poolDictionaries: '' ! X X!Frame class methods ! ! X X X!Frame methods ! X XaddDemon:aBlock slot:slotName type:demonType X (#('ifNeeded' 'ifAdded' 'ifRemoved') includes:demonType) X ifTrue: [self setSlot:slotName facet:demonType with:aBlock] X ifFalse:[self error:'Invalid Demon Type']! X XgetSlot:slotName X "return the slot object corresponding to slotName." X X ^self at: slotName ifAbsent: [nil]! X XgetSlot: slotName facet: facetName X X ^(self includesKey: slotName) X ifTrue: [(self at:slotName) getFacet:facetName] X ifFalse: [nil]! X XgetSlotValue:slotName X "get the value facet of a slot. If no such slot, look up AKO chain. X If that's no good, run a demon to get the value." X X | temp | X ((temp := self getSlot: slotName) isNil) X ifTrue: [((temp := self lookUpAkoChain: slotName) isNil) X ifTrue: [^self runDemonForValue:slotName] X ifFalse:[^temp getValue]] X ifFalse:[(temp includesKey: 'value') X ifTrue: [^temp getValue] X ifFalse:[^self runDemonForValue:slotName]]! X XisAKO X ^self getSlot: 'AKO' facet:'value'! X XisAKO: aFrame X "set the AKO slot of a frame" X X self setSlot:'AKO' value:aFrame! X XlookUpAkoChain: slotName X "Look up the inheritance chain for a slot with the name in slotName. X If you find it, return the Slot" X X ^(self includesKey: 'AKO') X ifTrue:[((self isAKO) includesKey:slotName) X ifTrue: [^(self isAKO) getSlot: slotName] X ifFalse:[^(self isAKO) lookUpAkoChain: slotName]] X ifFalse:[nil]! X XremoveSlot: slotName X ^self removeKey:slotName ifAbsent:[nil]! X XrunDemonForValue: slotName X X | aBlock | X aBlock := self getSlot: slotName facet: 'ifNeeded'. X (aBlock isNil) X ifTrue: [^nil] X ifFalse:[^self setSlot:slotName value:(aBlock value)]! X XsetSlot: slotName facet: facetName with: value X X | tempSlot | X tempSlot := self at:slotName X ifAbsent: [self at:slotName put: Slot new]. X tempSlot setFacet: facetName with: value. X ^value! X XsetSlot:slotName value:aValue X "set the value facet of a slot" X X ^self setSlot:slotName facet:'value' with:aValue.! X XsetSlot:slotName with: aSlot X "associate the slot aSlot with the name slotName. " X X ^self at: slotName put: aSlot! ! X X XFRMTRM.TXT X X| mammal dog fido s askDemon t | X" Examples of frame and slot classes in use. X Select and DOIT." X Xmammal := Frame new. Xmammal setSlot: 'hide' value: 'hairy'. Xmammal setSlot: 'bloodType' value: 'warm'. X Xdog := Frame new. Xdog isAKO: mammal. Xdog setSlot: 'numberLegs' value: 4. X XaskDemon := [Prompter prompt:'What is this dog''s name?' default: 'Bruno']. Xdog addDemon:askDemon slot:'name' type:'ifNeeded'. X Xfido := Frame new. Xfido addDemon:askDemon slot:'name' type:'ifNeeded'. Xfido isAKO:dog. Xfido setSlot:'color' value:'brown'. X X" Let's see the demon fire " Xfido getSlotValue:'name'. X X XSLOT.CLS X XDictionary variableSubclass: #Slot X instanceVariableNames: '' X classVariableNames: '' X poolDictionaries: '' ! X X!Slot class methods ! ! X X X!Slot methods ! X XgetFacet: facetName X ^self at: facetName ifAbsent: [nil]! X XgetValue X ^self getFacet: 'value'! X XremoveFacet: facetName X ^self removeKey:facetName ifAbsent:[nil]! X XsetFacet: facetName with: aValue X X self at: facetName put: aValue. X ^aValue! X XsetValue: aValue X self setFacet: 'value' with: aValue! ! X a echo shar: "a missing newline was added to 'EXPERT.JAN'" echo shar: "55 control characters may be missing from 'EXPERT.JAN'" SHAR_EOF if test 7019 -ne "`wc -c < 'EXPERT.JAN'`" then echo shar: "error transmitting 'EXPERT.JAN'" '(should have been 7019 characters)' fi fi echo shar: "extracting 'FILES.JAN'" '(837 characters)' if test -f 'FILES.JAN' then echo shar: "will not over-write existing file 'FILES.JAN'" else sed 's/^ X//' << \SHAR_EOF > 'FILES.JAN' X X X Articles and Departments that have X Additional On-Line Files X X AI EXPERT X January 1987 X (Note: Contents page is in file CONTNT.JAN) X X X X XARTICLES RELEVANT FILES X-------- -------------- X XJanuary Table of Contents CONTNT.JAN X XAdding Rete Net to Your OPS5 Toolbox OPSNET.JAN Xby Dan Neiman X XPerceptrons & Neural Nets PERCEP.JAN Xby Peter Reece X X XDEPARTMENTS X XExpert's Toolbox EXPERT.JAN X"Using Smalltalk to Implement Frames" Xby Marc Rettig X XAI Apprentice AIAPP.JAN X"Creating Expert Systems frm Examples" Xby Beverly and Bill Thompson X SHAR_EOF if test 837 -ne "`wc -c < 'FILES.JAN'`" then echo shar: "error transmitting 'FILES.JAN'" '(should have been 837 characters)' fi fi echo shar: "extracting 'OPSNET.JAN'" '(359936 characters)' if test -f 'OPSNET.JAN' then echo shar: "will not over-write existing file 'OPSNET.JAN'" else sed 's/^ X//' << \SHAR_EOF > 'OPSNET.JAN' X X X Adding the Rete Net to Your OPS5 Toolbox X (Supplemental files arranged by filename headings) X January 1987 AI EXPERT X by Dan Neiman X X X XEditor's Note: X XAdditional notes and clarifications for Imperative Pattern Match code, Xas described in January '87 issue of AI/Expert. X XThe code described in AI/Expert is still evolving (i.e. the more I use it, the more Xfeatures I add), and there was not sufficient space to give complete instructions in Xthe magazine, so the following notes should be used as a supplement to the Xarticle. X XTo use the Rete net modifications, load the code into an existing Common Lisp OPS5 Ximage. Then use the pmatch and map-pmatch functions as described in the article. X X XIt was probably not made clear in the article, but both pmatch and map-pmatch Xreturn the values of the last expression evaluated in the righthand side. So, Xfor example, to get the names of all employees making 30K a year, you might use the Xcode: X?(map-pmatch (employees ^name ^salary > 30000) X --> X ? ) X XThe RHS of the above function just evaluates and returns the binding of . XBecause the function used was map-pmatch, a list of *all* employees satisfying the Xgiven constraints is returned. X XThe syntax of the pmatch and map-pmatch commands has been modified slightly since Xthe article went to press. The method described for passing Lisp variables to a Xpattern match function proved to be inexpressibly awkward for lexically bound Lisps X(the system was originally written in Franz). The following modification makes it Xconsiderably easier to pass arguments to the pattern match routines. X XBecause the pattern match is compiled, the only way to interactively match a particular Xvalue is to write that value into working memory, and include that working memory element Xin the pattern match. This is fairly awkward to do by hand, so I've incorporated a macro Xinto the pmatch and map-pmatch commands which do it automagically. The arguments are passed Xby following the pmatch function with an argument list. The argument list is distinguished Xfrom a pattern by the "args" keyword. The syntax is: X X(pmatch (args arg1 arg2 ... argN) X (condition element 1) X (condition element 2) X --> X RHS) X XAfter macro expansion, the result is effectively X (let ((tt (make ipm$data arg1 arg2 ... argN))) X (query1 (ipm$data ) X (condition element 1) X (condition element 2) X : : : X --> X RHS) X (oremove tt) ) X XNote that the working memory element is added and deleted automatically. X XAs an example, the code to locate all children of a couple might look like this X(defun children(mother father) X ?(map-pmatch (args mother father) X (mother ^name ^child ) X (father ^name ^child ) X --> X (make parents ^name ^father ^mother ) X ?) X Xand given the working memory: X(mother ^name ann ^child bob) X(father ^name fred ^child bob) X(mother ^name sue ^child alex) X(father ^name fred ^child john) X(mother ^name ann ^child john) X(father ^name fred ^child cheryl) X X(children 'ann 'fred) would return (bob john) X Xand create the working memory elements X X(parents ^name bob ^father fred ^mother ann) X(parents ^name john ^father fred ^mother ann) X XDebugging code: As is the case with OPS5 productions, if you recompile a pmatch Xor map-pmatch function, you must remove working memory and replace it. A pattern match Xwill only work on data which has been added after compilation. This does tend to Xmake debugging tedious. X XEverytime a pmatch operation is recompiled, it generates a new body bound to a variable of Xthe form queryN. Because queries are not explictly named, it's difficult to automatically Xexcise them. So the net will tend to fill with superfluous nodes during debugging. XThe function exquery will excise all existing queries. Executing the sequence, X(oremove *) X(exquery) X(i-g-v) X Xwill remove all working memory and queries and reset all global variables. X XIf a pmatch or map-pmatch function blows up while evaluating its RHS, reset the Xglobal variable *in-rhs* to nil before proceeding. X XQuestions about this code can be directed to: XDan Neiman XCompuServe 72277,2604 XCSNET dann@UMASS-CS.csnet X Xor c/o COINS Dept. X Lederle Graduate Research Center X University of Massachusetts X Amherst, MA 01003 X X XIndex to software: X XCLSUP.LSP : Common Lisp support functions to define some canonical X functions missing in Common Lisp. X XOPSMODS.L : The OPS5 modifications described in the article. X XCOMMON.OPS : OPS5 for Common Lisp XTI.OPS : OPS5 for TI Explorers XFRANZ.OPS : OPS5 for Franz Lisp X XMONK.OPS : Test file for OPS5 XPRTOWER.OPS : Test file for OPS5 X X XNEWOPS.L X X;OPS5 modifications for Common Lisp X; by: Dan Neiman X; Original idea conceived at ITT ATC May, 1986 X; Converted to Common Lisp and expanded at COINS Dept., UMASS Fall 1986 X X;Copyright notice: Much of this code is modified or original OPS5 code which is X;copyrighted by C. Lanny Forgy of CMU, and is used with his permission. The rest is X;Copyright (c) Daniel Neiman, COINS Dept. UMass. Permission is given to use this X;code freely for personal, educational, or research applications. It is not to be X;sold, or incorporated into a for-profit product without permission of the author. X;The purpose of this code is to illustrate alternative uses of the Rete net and X;alternative control structures in OPS5. No guarantees are made about its fitness X;any particular application, and no claim is made about the presence or absence of X;bugs. X;Version of 12/12/86 X X;This file contains the necessary OPS5 modifications to perform X;the RHS pattern matching/control function described in the X;accompanying January '87 AI/Expert article. The code is a supplement to OPS5 and is X;intended to be loaded into a Common Lisp OPS5 image. X X;Note: The idea behind this modification is to add memory to the &p node and create X;functions to interrogate that memory at will. Sort of an elegant idea. But, because X;it has to be patched into an implementation which was not designed to do so, there's a X;lot of fairly nasty looking code here. Take heart, most of it is just slightly modified X;ops5 code and can be pretty much ignored. X X;This variable is used to determine if we encountered a pmatch X;or map-pmatch in top-level lisp code or while compiling an X;OPS5 production. X X(proclaim '(special *compiling-rhs* *qnames* *cmp-p-context-stack* X *system-state-stack* *NMATCHES* *ipm-data-stack*)) X(setq *qnames* nil) X(setq *system-state-stack* nil) X(setq *cmp-p-context-stack* nil) X(setq *compiling-rhs* nil) X(setq *ipm-data-stack* nil) X X;Read macro for variable evaluation on "RHS" of pattern match X;All &whatever macros on the righthand side must be preceded by X;a ?. This will expand to ($varbind '&whatever) X;To avoid having a plethora of read macros, ? will be double-duty. X;If ? precedes a ?(pmatch ....), then the expression is evaluated X;and the appropriate match stuff is placed in the rete net. The ;code is replaced by (query queryN pattern-body). X X;Read macro ? executes the following function. X(defun $$ipm$$dofunc$$(strm chr) X (let ((inp (read strm t nil t))) X (cond ((atom inp) X (if (eq '#\< (char (string inp) 0)) ;is it an OPS variable? X `($varbind ',inp) X (intern (concatenate 'string "?" (princ-to-string inp))))) X ((member (car inp) '(map-pmatch pmatch) :test #'eq) X (eval inp)) X (t X inp)))) X X X;make ? a read macro X(set-macro-character #\? #'$$ipm$$dofunc$$ t) X X(defun &query (rating name var-dope ce-var-dope rhs frhs) X (prog (fp dp) X (cond (*sendtocall* X (setq fp *flag-part*) X (setq dp *data-part*)) X (t X (setq fp *alpha-flag-part*) X (setq dp *alpha-data-part*))) X (and (member fp '(nil old)) X (ipm-removepm name dp)) X (and fp (ipm-insertpm name dp)))) X X X; each conflict set element is a list of the following form: -- --------------- C'est la vie, C'est la guerre, C'est la pomme de terre Mail: Imagen Corp. 2650 San Tomas Expressway Santa Clara, CA 95052-8101 UUCP: ...{decvax,ucbvax}!decwrl!imagen!turner AT&T: (408) 986-9400