Knowledge Based Systems Module Handbook: Semester 1 2005/2006 DR Christian Huyck School of Computing Science
Knowledge Based Systems Module Handbook: Semester 1 2005/2006 DR Christian Huyck School of Computing Science
2b
BI S2040
Knowledge Based Systems
Module Handbook
Semester 1
2005/2006
Dr Christian Huyck
School of Computin Science
Module Introduction
Introduction
Welcome to "Knowledge-based systems for business". This course is about symbolic AI in general and
building knowledge based systems in particular. In particular we will work with two types of expert
systems rule based systems and case based reasoning systems. Additionally we will talk about
knowledge representation and knowledge engineering. !ou could also read through the notes for
lecture " below.
Contacting the Module Leader
Office Hours - Roo !o" M2#2 Hendon
Times to be determined after handbook publication. (Check the web site below.)
$ail [email protected]
Telephone 020 8!! "!2
#eb pa$es www.cwa.mdx.ac.uk%
Rationale Including Ais
Knowledge-based systems# the knowledge representation approaches that they depend on# and the
knowledge engineering techni$ues that are used to build them are presented in this module. It pro%ides
a thorough understanding of the principles# design# de%elopment and operation of these ad%ice-gi%ing
systems and particularly of expert systems# and an introduction to related artificial intelligence
applications.
Learning Outcoes
Knowledge &n completion of this module# the successful student will be able to - 'escribe the nature
of expertise.(") - 'escribe the nature# and identify the ad%antages and the disad%antages of knowledge-
based systems# and particularly expert systems# as used by commercial and public ser%ice
organisations.(*) - +xplain the working of rule-based systems# and the kinds of inferencing that are
used in such systems.(,) - 'escribe important knowledge representation formalisms.(-) - +xplain the
role and the tasks of the knowledge engineer# particularly with regard to knowledge ac$uisition# and
the de%elopment of knowledge-based systems.(.) /kills This module will call for the successful
student to demonstrate the ability to - +xtract knowledge structures from transcripts of inter%iews with
experts# and represent this knowledge using recognised formalisms.(0) - +%aluate proposed knowledge
engineering pro1ects from the point of %iew of %iability and cost effecti%eness.(2) - 'ecide appropriate
rule-based inferencing approaches in particular cases.(3) - 4ollect sufficient knowledge to build a
small K5/ in a particular knowledge domain# and represent it in a way that can be con%erted into a
machine-usable knowledge-base.(6) - 7se the expert system shell presented in this course to de%elop a
standalone K5/ application.("8) 9 7nderstand basic issues in searching. ("")
Assessent %chee
4oursework .8: +xamination .8:
2
Reading Materials
Core &exts
4ore Text ; <ackson# =eter. Introduction to +xpert /ystems (,rd edition). "666# Addison-Wesley#
I/5> 8-*8-"32030-3 ?ussell# /tuart @ >or%ig# =eter. Artificial Intelligence - A Aodern Approach.
/econd +dition *88,# =rentice Ball# I/5> 8-",-838,8*-*
Additional texts
; Turban# +fraim @ Aronson# <ay. 'ecision /upport /ystems and Intelligent /ystems (0th edition).
*88"# =rentice Ball# I/5> 8-",-836-0.-0 ; Awad# +lias. 5uilding +xpert /ystems - =rinciples#
=rocedures and Applications. "660# West =ublishing# I/5> 8-,"--800*0-3 +%ery attempt has been
made to ensure this information is correct at the time of publishing. Bowe%er additional information
may be pro%ided in the module handbook.
%tud' hours outside class contact
The total study hours for a 20cpt module is !80 hours. Therefore& if a module has time'tabled
acti(ities i.e. lecture%seminar%lab& of ) hours per week for a !! week semester (total of )) hours)& then
the out of class study commitment per module& per semester& students ha(e to study is !* hours.
(rief )uide to *eb-based Module Material
+ll the lecture notes& exams and lab descriptions are on
http,%%www.cwa.mdx.ac.uk%bis200%bis200.html
%oe rele+ant ,eb sites
These are old sites (0 /ept C88)D sorry I ha%enCt had time to update this.
AIAI Information /er%ices httpEEwww.aiai.ed.ac.ukEpro1ectsEtech.html
A semi-commercial AI research organisation based in +dinburgh. This lists some of their current
pro1ects.
AI on the web httpEEwww.cs.berkeley.eduEFrussellEai.html
/tuart ?ussell# who produced this site# is one of the authors mentioned in the next section. This site
hasnGt been updated since "663# but is still an impressi%e collection of 26. links to interesting AI
sites.
5ritish 4omputer /ociety /pecialist Hroup on +xpert /ystems
httpEEwww.bcs-sges.orgEsgesEsges.htm
Bome page. 'etails of their conferences# e%ening meetings etc.
K5/ Hroup at the 7ni%ersity of Texas - "/ome ongoing K5/E&ntology pro1ects and groups"
httpEEwww.cs.utexas.eduEusersEmfkbErelated.html
A large number of links on knowledge representation pro1ects# and related work.
>ational ?esearch 4ouncil of 4anada - "+xpert systems and knowledge-based systems"
httpEEai.iit.nrc.caEsub1ectsE+xpert.html
)
A collection of links.
7ni%ersity of Ieeds E >ew technologies Initiati%e - "WWW Training resources in K5/ @ /AIT"
httpEEagora.scs.leeds.ac.ukEnti-kbsEsub1ect.html
Another collection of links.
Course,or-
.etails of Course,or-
The main coursework is,
The assignment for the module is simply to do the "8 labs for the course. +ach lab will be worth "8
points# and will be e%aluated at the beginning of the subse$uent lab session. Jor example lab " will be
marked at the beginning of the lab session in week *.
Marking scheme each lab is marked indpendently and is worth up to "8 points. If you arenCt in the lab
on the week it is marked# you will recei%e a 8 out of "8. =art of the e%aluation will be to show the work
dynamically to dissuade plagiarism. Jor example# when e%aluating lab "# you will be asked to make a
rule in clips.
!ou will be able to drop the two lowest scores# so the mark will be out of 38.
Re-sit students are encouraged to attend the labs so that they can get the mark based on the
main coursework. However they may opt for:
The assignment for the module is as follows
!ou are to build a Knowledge 5ased /ystem using 4lips# or 4aspian. It will contain knowledge from a
domain of your choosing# and will include rule-based reasoning (either forward chaining# backward
chaining or mixed)# or case-based reasoning. Appro%al for your chosen knowledge domain must be
obtained from the module tutor# to ensure that the domain is suitable. !our coursework# when handed
in# should include a floppy disk containing the finished system.
In past semesters we ha%e made it mandatory that you select your own domains. This was to force you
to explore the knowledge engineering issues. While we would prefer you to choose your own domain#
we ha%e pro%ided se%eral example domains belowD it is unlikely that you will recie%e a first class mark
if you use these domains# but they should gi%e you an idea of a minimal system.
Aarking scheme
". The =rogram ?uns (up to *8).
*. /ophistication and +xtent of Knowledge 5ase (up to *. marks)
,. +xtent to which the system performs a useful function (up to ". marks)
-. 'iscussion of why this particularly domain is appropriate for the type of expert system you
used. (up to "8 marks)
.. 'escription of the knowledge ac$uisition process. A sample taken from a published source of
the knowledge or an inter%iew transcript are useful. (up to "8 marks)
0. 'escription of rules or cases and data items (up to "8 marks)
2. 'escriptions of "successful" and "unsuccessful" program runs# including sample output. (up to
"8 marks)
/ome notes on the abo%e marking scheme
"+xtent to which the system performs a useful function" - a tri%ial application will get less
marks than an application that someone (in the real world) might actually get some benefit
from. Also# marks may be deducted for lack of %alidity in the knowledgebase in other words#
if rele%ant features of the domain knowledge ha%e been ignored# or distorted# or in%ented# in
the process of turning them into components of the knowledgebase# this may result in loss of
marks.
"The extent of the knowledgebase" - a knowledgebase containing# say 3 rules# will get rather
poor marks in this category ("8 marks). &ne containing# say# *- rules will get rather high marks
("3)# assuming the rules are useful. 5eyond a certain point# howe%er# no more marks will be
awarded# so it is not worth de%oting time to producing an enormous rule base. Also note that
one rule can do the work of se%eral other rules. This is reflected in the sophistication of the rule
base.
"The sophistication of the knowledgebase". =artly# this is the extent to which the features of the
package are employed to produce an effecti%e reasoning system. 5ut it is also true that a more
ingenious or original system will obtain more marks than a less ingenious or original system.
"'escription of rule or cases and data items" - I want a chart describing the knowledge# and the
reasoning that it supports. Jor example an and-or chart for a backward chaining system# but
you may choose another form of representation if you feel it to be more appropriate. There is
no need to include a listing of the rules or the case base as youCll submit that on a floppy.
"'escription of successful and unsuccessful runs" - this describes runs of the system you
submit. There is no need to describe problems you had while de%eloping the system. Aoreo%er#
you should describe the system so that the run can be replicated.
'eadlines
=ro1ect handed in to /tudent &ffice (end week "")
Where to submit
o 4lips =ro1ects
". Tic-Tac-Toe
*. =lant Identification
,. 5ag =acking
-. A/ Word ?uler Belp 'esk
.. +ngine 'iagnosis
0. 'ormitory Assignment
o 4aspian =ro1ects
". Hift /election
*. 7ni%ersity =rogram /election
"
,. 5ag =acking
ThereCs a sample co%er sheet on the next page - feel free to copy it and use it on your
assignment# inserting your details. !our assignment# including co%er sheet# write-up and
program on floppy disk# must be submitted to the student office where it will be dated and
receipted. !ou should keep your receipt - it is for your own protection. 'o not hand written
assessed coursework direct to your tutor. !our assignment should normally be handed in on the
campus at which the module is being taught (e.g. Bendon)D if for any reason you ha%e to hand
it in at another campus# please point this out to the student office so that it can be sent to the
correct campus. If# in an emergency# you ha%e to send in written assessed work by post you
must send it by recorded deli%ery to the appropriate student office and keep the =ost &ffice
receipt. It will be deemed to ha%e been submitted on the date of the postmark.
?eceipts for work submitted outside opening hours can be collected from the student office.
.eadline for %ubission of Course,or-
The main coursework is due throughout the semester (week * to "")# by the end of the students lab
session.
Map of course,or- deadlines b' /rograe 0 le+el 12 #2 or 22 or 3 or 4
*here to subit"
The main coursework is described to the tutor in the lab session.
The resit coursework must be submitted to the -tudent office& you should attach a coursework
feedback form which will be dated and receipted. .ou should keep your receipt ' it is for your own
protection.
5eedbac- to students on course,or-
The main coursework will be marked in the lab session in cooperation with the student.
The resit coursework will be a%ailable at the end of the semester in the tutorGs office. =lease e-mail or
phone for an appointment.
/
Lecture /lan
#orkshop sessions
in week no,
0ecture
sessio
ns in
week
no,
Title 1eadin$s. +ll from
2ackson unless specified
! 3ntroduction to
Clips
! 3ntroduction and 4(er(iew Chapter ! and -ection ".!
and ".2
2 Chains& side
effects etc.
2 1ule 5ased -ystems +rchitecture and
6ro$rammin$ with 1ules
-ection ".!& ".2 and
Chapter
) 7ecision Trees ) 8ettin$ 1ules to #ork To$ether -ection ".) and Chap. 2
0oops and
9unction Calls
:nowled$e 1epresentation and 0o$ic -ection 8.!.! and 8.!.2
" -emantic ;ets
with Clips
" -emantic ;ets -ection /.! and /.2
/ 5acktrackin$ / 1ule 5ased -ystems <xamples Chapter )
* 3ntrouction to
Caspian
* Case 5ased 1easonin$ Chapter 22
8 7e(elop a C51
system
8 Case 5ased 1easonin$ <xamples
= :nowled$e
<n$ineerin$
= :nowled$e <n$ineerin$ and
5ackward Chainin$
-ection !0.!& !0.).! and
!0.).2
!0 5ackward
Chainin$
!0 9rames and <xpertise -ection /.)
!! open !! -earch -pace >nifyin$ Themes 1ussell and ;or(i$
Chapter ).
!2 open !2 Conclusion and 1e(iew
*
Laborator'6%einar Materials
Welcome to B! "#$#
I am 4hris Buyck.
Ay office is ?"82 in Bendon
Ay office hours are Thursday ""-"* this semester.
Ay email address is c.huyckKmdx.ac.uk# and this is the best way to get me.
This lecture is on my web site (www.cwa.mdx.ac.uk).
I know loads about +xpert /ystems and Artificial Intelligence.
'oes anyone want to ask me any $uestions about +/s or AIL
ICm also the lab tutor.
I think AI is interesting# in demand economically# and fun.
B! "#$# %ourse !tructure
The exam is worth .8: of the grade# and the coursework is worth .8. !ou ha%e to pass both to pass.
The coursework is to implement the labs on time. ItCs in the handbook# and at
httpEEwww.cwa.mdx.ac.ukEbis*8-8Ecoursework.html .
The course text is Introduction to +xpert /ystems by =eter <ackson
As usual# all e%aluation will be based on the learning outcomes.
I gi%e the lectures this semester.
&earning 'utcomes
+xpert /ystems
o Bow ?ule 5ased /ystems work
o 4ase 5ased ?easoning
o ?ule 5ased /hells
o 'e%eloping +/s
o +xpertise
Knowledge +ngineering
/ymbolic Knowledge ?epresentation
o Iogic
o /emantic >ets
o Jrames
/earch and /earch /paces
(ou Must )rogram
The labs are programming expert systems.
The exam will ha%e a significant portion on programming expert systems.
8
If you donCt want to program# withdraw from this course.
*+pert !ystems
+xpert /ystems are often called rule based systems. Alternately# they also refer to both rule based and case based
systems.
?ule based systems are made up mainly of a collection of rules.
?ules are if then else statements
/o that the system works in different cases# it also has working memory (WA).
WA is input by the user# the rules inspect it# and may modify it.
The ?ule based system itself looks at the WA# and selects rules to apply that are legitimised by the WA.
If (M bears li%e young) and (M gi%es milk) then (M is a mammal)
Why is this usefulL
Bow is it different than writing (e.g. <a%a) code.
,nowledge Representation
Bow do you represent knowledgeL
program %ariables integers# reals# booleans# characters# strings
programs
databasesL
Iogic
o All men are Aortal# /ocrates is a Aan# therefore /ocrates is Aortal
o Jirst &rder =redicate Iogic is part of this class.
o Junctions are important in all of this
/emantic >ets hierarchies# part-of# relationships.
Jrames e.g. the %erb hit has an actor slot# an ob1ect slot# and an instrument slot.
These are symbolic ways of representing knowledge. They will be on the exam.
%ase Based Reasoning
45? is based on a collection of cases.
!ou figure out what to do in each case in the collection# you may do the same thing in se%eral cases.
When a new case comes in# you compare it to the collection.
!ou gi%e the ad%ice of a nearby case.
An example might be a trouble shooting desk. 68: of the $ueries fall in "8 categories.
Jigure out what category it is in (including the ""th other category)# gi%e the appropriate ad%ice# or in the other
case# phone a help person.
This sa%es 68: of your help person time (after de%elopment).
What would a case look likeL
=
Bow do you tell which cases are near to the new caseL
,nowledge *ngineering
Bow do you build systems like theseL
!ou learn how to build the +/s (rule based and 45? systems).
!ou learn how to choose which is best (if either).
!ou get the information from the experts.
I can write an +/ for wine selection# but I canCt tell you much about wine.
I need to ask an expert.
Bow can you askL Inter%iews# reading# prototype e%aluation# ask multiple experts.
This is the process of knowledge engineering.
)rogramming *+pert !ystems
I want to concentrate on programming expert systems.
Iast semester there were %ery few firsts on the course works# and no firsts o%erall.
>one the less# people did well on the implement a ?ule 5ased system# and implement a semantic net exam
$uestion.
4onse$uently# ICd like to spend more of the lectures talking about implementing systems.
This ties in with software engineering# but I think programming is a different skill.
Bow can you make 4lips or 4aspian do thingsL
The labs concentrate on this programming# but we will also concentrate on programming during lectures.
n class e+ercise
A firm of wine importers relies hea%ily on its chief wine expert# who is skilled at selecting wines that are destined to be
popular# on the basis of their taste# colour# scent etc. /he is soon to retire. It is proposed to build an expert system that will
enable any of se%eral 1unior wine specialists to do her 1ob.
". Aake a rule that would be used in such a system.
*. What is an example of working memoryL
,. What is an example of deri%ed knowledgeL
-. Bow would you get the knowledge for the systemL
.. 'o you think it will workL
0. Why andEor why notL
-raphs
Hraphs are an important mathematical and computer science concept.
A graph consists of nodes and arcs that connect them.
Hraphs arenCt going to be on the exam# but we use a couple of types of graphs for knowledge representation.
We use semantic nets# decision trees# and-or trees# and frames.
!ou probably also know about a few other types of graphs like entity-relationship diagrams# flowcharts# and case
diagrams.
!0
'raw a graphN
The key difference between types is that the nodes and arcs ha%e different restrictions and meanings.
Jor example# nodes in a semantic net represent concepts# the arcs are directed# the arcs are labelled# and they show
the relationship between the nodes they connect.
The nodes in a decision tree represent a $uestion# and the the arcs represent answers.
ICll show you a semantic net and a decision tree.
!earch and !earch !paces
&ne thing that is important in programming# and particularly important in many AI systems is searching.
Jor example# lab0 has you writing a system that searches through a maOe
.
Bow would you search through this maOeL
This particular problem has se%eral important characteristics.
5acktracking is importantD if you make a wrong choice# you can go back.
There are a small number of discrete options. It is ob%ious how to mo%e from one state to the next.
!ou can only mo%e directly from one state to a few other ones.
This is a physical manifestation of searching.
&ther problems can be translated into a state space# and that space can be searched. The search pro%ides the
answer.
.dvice
". !ou will ha%e to program in this course.
*. 'o the labs# which are designed to teach you to program.
,. The ability to program will help considerably on the exam# but try to do the reading.
-. Ask $uestions in class.
.. If you keep up with the labs# youCll pass the course.
0. If you want a first# do the coursework early# read# and ask $uestions.
%onclusion
The coursework is to do the labs and show them to me. ItCs worth .8: and the exam is worth .8:.
WeCll learn about +xpert /ystems (?ule 5ased systems and 4ase 5ased ?easoning)# Knowledge ?epresentation#
and Knowledge +ngineering.
!!
ItCs practical# symbolic AI.
Who wants to be a student representati%e for this moduleL
What is AIL (ItCs not on the exam.)
Jor next week read 4hpt. " and section .." and ..*
The lab is to get a rule based system running
Rule Based !ystem .rchitecture
o if (Jeature LM /kin Bas) and (Jeature LM /eed Bas) then (Jeature LM type Jruit)
o if (Jeature LM /kin Bas>ot) then (Jeature LM type notJruit )
o if (Jeature M /eed Bas>ot ) then (Jeature LM type notJruit )
o if (Jeature LM colour green) and (Jeature LM type fruit) then (Jeature LM subtype Watermelon)
o if (Jeature LM colour red) and (Jeature LM type fruit) and (Jeature M s$uishy isnot) then (Jeature LM
subtype Apple)
o if (Jeature LM colour orange) and (Jeature LM type fruit) then (Jeature LM subtype &range)
o if (Jeature LM colour green) and (Jeature LM type notJruit) then (Jeature LM subtype Iettuce)
o if (Jeature LM colour red) and (Jeature LM type fruit) and (Jeature M s$uishy is) then (Jeature LM subtype
Tomato)
o In 4lips
If (or(Jeature LM colour red) (Jeature LM colour orange)) (Jeature LM s$uishy is )
Then (assert (Jeature LM subtype Tomato))
Write out 7I including assertions for Bas/kin# Bas/eed# /$uishy# and colour
explicitly state (run) and (reset)
*+planatory !ystem
&ne of the nice things about ?ule 5ased /ystems is that they can easily explain their reasoning.
Why is this useful.
Bow does it easily explainL
Why is M a lettuceL
<ust print out the rules that you used.
(!ou might ha%e to prune dead ends# e.g. tomato)
)rogramming with Rules
Jormally rules are as powerful as any programming language (like <a%a).
They are Turing 4omplete (the same guy as the Turing test but a different concept.
!"
It is harder to do complex looping and functions with +/s (e.g. card dealing).
That is# anything you can do with <a%a# you can do with rules.
&ne way to get the power is to ha%e a global %ariable store#
ha%e a mechanism for accessing and changing it#
and ha%e a mechanism for choosing which thing to do next.
With these things you can program anything that is programmable.
1ariables
What are %ariables in progammingL
TheyCre like mathematical %ariables but they ha%e a direct implementation in computer hardware.
There is computer memory associated with a %ariable (e.g. * bytes# ,* bytes# or *888 bytes).
It usually has a type associated with (e.g. boolean# integer or string)
The %ariable persists for a time specified by the program# then is used for some other program or perhaps reused
for your program.
!ou can inspect the %ariable (e.g. RR# S)
!ou can change the %ariable (R)
4lips uses lists for its %ariables. They call them facts.
/o# you define a fact by for instance a ,-ary predicate like
(age-of 4hris ,6).
The de%eloper and the reader nows that the age of 4hris is ,6# when he sees this fact.
Rules
A rule has the format
if Boolean-*+pr then !tmt
if and then are keywords
+xpr and /tmt refer to expression and statement. They refer to programming language concepts# that ICm not going
to fully explain.
A simplified %ersion is that an expression has a %alue and a statement does something.
The if is itself a statement# though it recursi%ely uses statement.
Another type of statement is the assignment
a R ,D
Ioops and procedure calls are also statements# as are compound statements (with curly braces).
An expression has a %alue# and a boolean expression has a %alue of type boolean.
Jor example
a RR ,
is an expression that has the %alue true or false depending on the %alue stored in the %ariable a.
!ou can also ha%e compound expressions combined using .nd 'r# or 2ot
Jor example (a P ") And (a S "8). In 4lips
(%alue La)(test (P La "))(test (S (La "8))
!/
which is the same as
(and(%alue La)(test (P La "))(test (S (La "8)))
This stuff is the same for many programming languages# so it should not be new to you.
Rule *+ercise
Write an if then rule for a stop light
If youC%e written the rule in 1a%a format# try it in clips format.
>ow write the rules for a dri%erCs beha%iour when the lights are# red# amber# green and red-amber (in clips format).
What data items would you assertL
Recognise .ct %ycle
?ule 5ased /ystems work on a ?econgise Act 4ycle
?oughly# rules are recognised as firable.
A rule is applied# which may or may not change working memory
It may ha%e side effects (e.g. print something out or mo%e a robot arm)
A new set of rules is recognised
If no rules apply the system is done.
WhyL
This can change if the system is interacti%e.
If it is interacti%e# WA can change because of the interface and new rules can be applied.
*asy 2otation but &ess )ower
+xpert /ystems ha%e a really simple notation
=eople can easily understand the if then rule structure
ItCs easy to generate rules
Bowe%er# it lacks power that structured programming gains from looping and function calls.
Jormally they are the same (Turing 4omplete)# but itCs harder to do complex stuff with +/s (e.g. card dealing).
It also gets hard to keep track of large +/ systems (o%er "888 rules).
/tructured and && programming are easier to manage.
%onclusion
?ule 5ased /ystems consist mainly of
an Inference +ngine# which is the same for different rule bases
a Knowledge 5ase (rules and working memory)
and a 7I
The inference engine runs through a recognise and act cycle
?ule 5ased /ystems are less powerful than structured programming# but easier to use and understand
ItCs easy to get explanatory powers from a ?ule 5ased /ystem by showing the rules that were applied
!*
Jor next week read sections .." and ..*# and 4hapter - to help with the 4lips command prompt.
%onflicting Rules
The rule selection mechanism chooses only rules that are %alid and applies one of them.
What happens when more than one rule can applyL
This is what a conflict is.
All the rules that are %alid (whose IB/ is True) are put into the conflict set.
+/ shells function differently and most ha%e different modes for choosing which rule to apply.
%onflict Resolution !trategy
When multiple rules can apply# you need a conflict resolution strategy
The conflict is between different rules
There are a range of different strategies
/ome systems apply all rules that can apply (e.g. the =arsimonious =roduction /ystem)
/ome use the rules with the most conditions
&thers 1ust do it by the order of the rules
With small systems it doesnCt really matter much# but with big systems it can really change performance.
'ne Rule 0iring Multiple 3imes
We said that if the IB/ matches# then the rule is put into the conflict set.
ItCs unusual for the ?B/ to change the IB/ so most rules should remain in the conflict set. ('id you follow thatL)
They donCt.
If a rule has been applied# it wonCt be applied again unless one of the things the IB/ depends on changes# or if
there are mutliple ways of it applying.
The simplest way to get a rule to fire twice is that it applies on multiple pieces of data
if (isdog Lx)RP(assert (issmelly Lx)))
with the two facts (isdog lassie) (isdog /antasIittleBelper)
The other way is to change the %alue the IB/ depends on.
0orward %haining
This is what we ha%e done so far.
Hi%en facts# apply rules
&f course there are a range of conflict resolution strategies
ItCs deri%ing new knowledge from existing knowledge
This is the way we normally explain Iogic
It works well when you already know a lot about the en%ironment
4an you think of another way to run a systemL
/sing 4erived ,nowledge
Iast week in the lab# we had a chain of reasoning
!8
+ach rule deri%ed a fact that anothe rule used
This is deri%ed knowledge
The larger the +/ the more deri%ed knowledge should be used
If not you ha%e a large series of unrelated rules
Many Rules
/tructured programming languages largely specify the order that statements will be executed.
?ule based systems by default do not.
This is the power and problem with them.
!ou can of course arrange it so that they are applied largely in the order you want.
&ne mechanism would be to ha%e a program-counter fact# and each rule would ha%e a different %alue on the if
side# and would change the %alue on the then side to select the next rule to apply.
This re$uires the programmer to select which rule to come next and largely erases the simplicity of a rule based
system.
Bowe%er# you can reach a happy medium.
!ou largely lea%e the system to choose which rule to apply next# but in certain cases you manage it.
The three basic control structures are branching (e.g. if then else)# looping# and function calls. !ou can do them all
with rules.
&oops
A loop repeats something o%er and o%er again
A rule or set of a rules can implement a loop
Jor one rule you need to keep the IB/ true but change one of the data items it depends on.
Jor example
if (%alue La) (test (S La .) then (assert (%alue (T La "))
!ou get La# see if it is less than .# and if so and assert a new fact. The next cycle this exact rule will be rerun again
until (%alue .).
This is the basic idea for any loop.
They can also benefit from an initialisation and conclusion rule.
0unctions
A function is a body of code that gets parameters.
'epending on the parameters the function may calculate a return %alue and may ha%e side effects
A simple %ersion of this can be done by making rules that only run when a particular fact is set.
When the function is finished# that fact is changed.
To call the function# you need to set up the parameters and then set the fact.
This is only a simple %ersion of function calls# because it does not allow recursi%e functions.
Jor example (defrule start-loopfunc (start myfunc) RP (assert (%alue ")) (assert (in myfunc)))
!=
(defrule loopfunc (in myfunc) (%alue La) (test (S La .)) RP (assert (%alue (T La "))))
(defrule endfunc Lf" S- (in myfunc) (%alue La) (test (R La .)) RP (retract Lf"))
0unction *+ercise
What facts would you use to represent a studentL
Write a rule that prints out a studentCs first and last name from the fact.
Aodify the rule (and perhaps add rules) that implement a function to print out a studentCs names.
Aodify the rules so that they take a parameter. The parameter is the student number and the rules will now only
printout that studentCs number.
4ecision 3rees
A standard way to model a process is a decision tree.
!ou start at the top# where the top node has a $uestion.
+ach possible answer has a branch# and depending on the answer you follow the branch.
The lea%es ha%e answers.
BereCs a decsion tree from the 'ecember *88, exam
2/
.rcs in !emantic 2ets
>odes can ha%e any %alue
Arcs can also ha%e any %alue
7sually the arc relationship goes in one direction# with the implied re%erse relationship in the other direction
(co%ered-by -P co%ers)
Typically# the semantic net has a small fixed number of primiti%es as arcs
This is because these are the main things that the >et can be used for
A particularly important relationship is Inheritence which is described by the label Is-A
nheritence
Inheritence is now used by &b1ect &riented =rogramming
The idea of Is-A is that the subcategory is a specialisation of the super-category. /o an &strich Is-A bird# and is
thus a special type of bird.
=roperties are also inheritedD so a bird is co%ered by feathers and therefore an &strich is co%ered by feathers.
This property inheritence can also be explicitly o%erriden.
/o# a bird tra%els by flying# but an &strich tra%els by Walking
&f course things can inherit from multiple super-categories. 'ogs are pets# and are mammals.
Inheritence 4onflicts. This means that there can be conflicts.
Instances are a special subset of inheritence. (Type %s. Token)
They refer to a particular indi%idual# where the general node refers to a class.
Inheritence and instance-of gi%es representational economy.
Another popular arc is part-of.
!emantic 2et *+ample
What birds are thereL
>ame some inheritence o%errides.
>ame some inherited features that are not o%erriden.
What colours can birds beL
What does 4lips ha%e that is related to this.
'raw a semantic net for mammals.
=ut in a cat-dog.