Rochester Institute of Technology
RIT Scholar Works
Theses
Thesis/Dissertation Collections
4-22-1986
Design of an expert system to perform cladistic
analysis
Walter Wolf
Follow this and additional works at:
http://scholarworks.rit.edu/theses
This Thesis is brought to you for free and open access by the Thesis/Dissertation Collections at RIT Scholar Works. It has been accepted for inclusion
in Theses by an authorized administrator of RIT Scholar Works. For more information, please contact
Recommended Citation
Design
ofanExpert System
toPerform Cladistic Analysis
Approved by:
Rochester Institute of Technology
School of Computer Science and Technology
Design of an Expert System to Perform Cladistic Analysis
Walter A. Wolf
A thesis, submitted to
The Faculty of the school of Computer Science and Technology,
in partial fulfillment of the requirement for the degree of
Master of Science in Computer Science
John A. Biles
John A. Biles
Lawrence A. Coon
Lawrence Coon
deny)
perm1ssi~n
.
to
the Wallace Memorial J;,ibrary, of
R.I;T.,
to
,
.... ---- .-I . \ ~_.
reproduce my
th~si~
in whole or in
-
part. Any reproduction w11l
.\,
CONTENTS
1.
Project Background
12.
Cladistics
3
3.
Artificial Intelligence
6
4.
Expert
Systems
7
5.
Implementations
13
6.
Initial Decisions
17
7.
Elements
oftheSystem
23
8.
Conclusion
47Bibliography
51
Appendix 1
~Main
and
Oddsandends
52
Appendix 2
~Sample
1.
Project
Background
Before I
commenced thestudy
of computer scienceI
was abiochemist,
most recentlyinvolved
in
thestudy
of thebiosynthesis
of sex pheromonesin
certain moths.Sex
phero-mones are compounds that
females
emit to attract mates.It
seemed natural tolook for
athesis projectthatwould utilize the
knowledge
andtraining
thatI
already possessed.It
turned out tobe difficult
todesign
a meaningful projectin
myfield,
but
someinteresting
projectsin
associated areas were considered.Two
of these were particularlyappealing.
The
first involved
modeling
the effects of certaindrugs
on themaleinsect's
reactionstothe sex pheromone.
Normally
the males undergo a set pattern ofbehaviors
which canbe
predicted statistically.
However,
variousdrugs
influence
andinterrupt
thisbehavior
patternin different
ways, andthis allowsthem tobe
usedas nervous systemprobes.Although
intrig-ing,
this projectinvolves
too much experimentation and speculation and not enough use ofthe computer
for
avalid computer sciencethesis.It
remains as apotential researchproject.The
other probleminvolved
the classification ofinsects into
families,
etc., an activitythat
traditionally
has depended
upon physical characters,but
more recentlyhas
also usedchemical
information,
such as theidentity
of the sex pheromone.A
particularlyinteresting,
but
relatively young,branch
ofthediscipline
is
calledcladistics, whichinvolves
considerationof evolutionary relationships as well as physical and
biochemical
ones.It
wasdecided
thatthis would
be
a suitablefield in
which to write a simple expert system , asit
wasdata inten
sive, thus making the use of a computer attractive,
if
not necessary, and yet not welldeveloped,
thuslimiting
thenumberof rules thesystem wouldhave
to consider.In this thesis I will
first
try
to acquaint the reader with somebasic
concepts of artificialintelligence,
expert systems and cladistics.Then
theprocess we went throughdesigning
oursystemwill
be
outlinedand the actual systempresented.One
point wasbrought home
to meearly in
my reading--creating
anactual, function
systems
presently
written started withdoctoral
thesis anddeveloped from there,
andit has
been
estimated thateven a"bare-bones" system wouldtake atleast
aman-yeartodevelop
[A.Poole,
personalcommunication],
notcountingtesting
and refinement.However,
many ofthemajordecisions
(data
representation, ruleformat,
etc.)have
tobe
made
early in
the project, and theinference
engine code shouldbe
writtenfirst,
sothat evena system too simple to
be
of much use will serve the educational purposes of a completedevelopment.
Of course,
the system could thenbe further fleshed
out, or thelessons learned
2.
Cladistics.
2.1.
Background.
One
ofthe oldestfields
in
biology
is taxonomy,
or systematics, whichinvolves
the classification of
living
organismsinto
species anddefining
the species relationships.More
recently thishas been
expanded toinclude
the evolutionary aspects ofspeciation thatis,
how
speciesdeveloped
over time.Historically,
threemajor methods ofclassificationhave been
used:(1)
Numerical
(phenetic)[Colgan;
Romesburg].
This
methodis
based
on a numericalanalysis of
traits,
either thefew
exhibiting the widestdifferences
or the maximumnumber that are shared.
This
methodis
quite populardue
toits
essentially numericnaturewhich can
easily be
programmed, thuslending
themystique ofthecomputer toit
andits
practitioners.However,
it
has
a major problem ~it
canlead
to grouping of
species that
do
nothave
a common ancestor(polyphyly)
or resultin decendants
of a single ancestorbeing
placedin different
groups(papaphyly).
(2)
Evolutionary
taxonomyfRose].In
this method, the rate ofevolutionary
change(or
degree
ofdifference)
is
reflectedin
the classification.Organisms
thathave
undergoneconsiderable change are placed
in
a separate groupfrom
close relatives thathave
remainedmore
"conservative,"
or similarto theancestor. Aproblemwiththismethod
is
that
it
gives risetoparaphyly.(3)
Phylogenetic(cladistic)
[Cracraft;
Hennig].
This
method emphasizes recency of common ancestry.
Two
operational taxonomic units(otu's
~groups on the
level
you arecurrently operating, eg, species,
families,
etc.) that share a common ancestor are considered more closelyrelatedthan
is
athird otu thatlacks
this commonancestor,
evenif
it
shares many ofthe characters of one ofthe others. In other words,degree
of changeis
subservient to recency of common ancestry.All decendants
of a common ancestorTwo
or more otu's that sharederived
(unique)
characters are considered tohave
anancestor
in
common.One
of themainduties
ofthe cladistis
todetermine
which characters are
derived
and which are ancestral.Classification
mustbe done
usingderived
characters
only
tobe
valid.This decision
is
best based
onfossil
evidence.Lacking
this,
"out-group
comparisons"are used~
if
a character appears
in
othercloselyrelatedgroups,it is
probably ancestral.This
requires extensiveknowledge
of groups close to thosebeing
studied, a knowledgethat tends to varyamongst practitioners ofthesubject.
2.2.
Cladistic Analysis.
Before
one can start a cladistic analysis, which explores the evolutionary relationshipsbetween
otu's, you musthave
the speciesunder considerationfully
defined
and possess someinformation
abouttheir evolutionaryhistory.
Then thefollowing
decisions
mustbe
made:(1)
Which
charactersdefine
the classification and arethey
in
any way related or grouped(ie,
if
redhair
andfreckles
gotogether,
are these one character ortwo?);
(2)
What
are the sister(or
ancestral) groups;(3)
Whichcharacters evolved once andwhichmaybe
theresult ofconvergent evolution;(4)
Whichcharacters are ancestral and whicharederived;
and(5)
In
cases whereindependent
characters areincongruent,
whichhas
moreweight(ie,
if A
and
B
have
traitQ
andB
andC
sharetraitZ,
is
B closertoA
orC?).
2.3.
Biochemical Implications.Traditionally,
classificationhas been based
on morphology ~descriptions
of physical
parts ofthe organism under study
(shape
ofwings, size ofova, etc.)Recently,
biochemical
characteristics
have
alsobeen
considered[Brown;
Rose].
As
thisis
an areain
whichI have
Female
moths alert potential mates to their positionby
emitting small amounts of achemical, called a sex
pheromone,
thatspecificly
attract males oftheir own species.As
characters related to reproduction are
particularly important in
speciation, information about theidentity
andbiosynthesis
of these compounds shouldbe
of great use to the cladist.This is
just
thekind
ofinformation
thatI have
available.Thus
it is
of specialinterest
to me to construct a system that would aid the cladistin
incorporating
biochemical data into his
analysis.Adding
newinformation
to the systemshould
be
easy andit
shouldbe
simple to modify, so that various ways ofinterpreting
theeffects ofthe added
information
canbe
seen.Finally,
it
wouldbe desirable for
thesystem tohave
the potential to possess enough expertise to suggest proper weighting and grouping3.
Artificial
Intelligence.
Artificial
Intelligence
(Al)
has been defined
as thebranch
ofcomputer sciencedealing
with
symbolic,
non-algorithmic methods of problem solving[Buchanan].Items
arerelatedandconclusions reached through
judgmental
rules, orheuristics,
as well as through theoreticallaws
anddefinitions.
Programs
containinference
mechanisms and/orknowledge bases
andposses mechanisms tosearch
for
facts
and associateitems
when appropriate.Historically,
thisfield
arosefrom
thestudy
of(human)
intelligence (Winston).
Comput
ers were employed
because
they
aidin
thinking
aboutthinking,
force
precisionin implemen
tation,
quantify
information
processing
and, perhaps of most practicalimportance,
are easierto work with than animals.
(My
wife, the sheepfarmer,
does
not agree with thelast
reason).Major
fields
ofinvestigation included
matching, goal reduction, constraint exploration,search,
problem-solving
andlogic
methods.Additional
topicsinclude
"common
sense,"understanding natural
language,
andlearning.
Looking
more closelyatAl
revealsit
tobe
somewhatless
thanindicated
above.What
is
particularly
noticeableis
that thefield
is
not non-algorithmic~ ratherthe typesand purposes
ofthe algorithms
have been
changed.At
this earlystagein its
development,
Alis
still closelylinked
to traditionalcomputer science,but
is
expandingits
scope andthe types ofproblemsit
attemptsto copewith.
As in
all computer programming, one of thebiggest
advantages ofdoing
Alis
thatit
forces
the practitioner to think about thedetails
ofthe over-all processhe
wishes toimple
ment.
Such
problems asknowledge
acquisition and representation,data base
manipulationand search strategies are
interesting
and are not always encounteredin
more traditionalareas.Thus
workingin
thisfield forces
theprogrammer toconsider new representations andimple
4. Expert
Systems.
4.1.
Definition.
The
term'expert
system'has
proven tobe
difficult
todefine
exactly.Commonly,
such asystem
is
said to achieve expertisein
afield,
although thereis
generaldisagreement
as towhat
is
"expertise"and
how
extensivethescope of afield
shouldbe.
The
definition I
found
most usefulis
an operational one proposedby
Buchanan andShortliffe.
They
say an expert systemis
"..
anAl
programdesigned
(a)
to provideexpert-level
solutions to complexproblems,(b)
tobe
understandable and(c)
tobe
flexible
enoughtoaccomodate new
knowledge
easily."In
addition,I
feel it
shouldbe
usableby
a variety ofusers,
from
non-expertsneeding direction
to experts who themselves need advice and easyaccessto
large
data-handling
capabilities.Let
usbriefly
examinethese points.We
allknow
that there are expertsin
certainfields
~
practitioners who, with access to the same
data
as non-experts, arrive at "better" conclusions, usually
in less
time. Howthey
do
thisis
often unclear, especially to the experts themselves.
It
is
generallyfelt
that experts employheuristics,
or rules ofthumb,
that allow themtoquickly
focus
onthekey
elements ofthe problem and assemble theseinto
areasonable conclusion.
A
key
tobuilding
an expert systemis
tofind
an expertwho can(and
will) articulatethe
heuristics in
aform
that canbe
codedfor
a computer.Thus
we musthave
an expert'sheuristics,
away to representthem,
adata base
to which theknowledge
canbe
applied, andan effective languageor set of procedures toallowthese elementsto
function
together.The
system mustbe
understandable.This implies
that annon-expertfinds it
reasonableto use and understands the
logic
that supports the presented conclusions.Reasonable
to usemeans
it
must quicklyfocus
on the problem athand
and exploreit
in
an expectedfashion.
For
example, thebuilders
ofthe MYCIN system(see
below)
found it
necessary
toinclude
questions thatwhen
they
were not asked theusers would notbelieve
the conclusions.In addition,
the system mustbe
able to'back
up'its
answers through somekind
of explanationfacility.
This
is
not alarge
problemin
a systemthat closelymodels humanthinking,
but
canbe
a real problemin
those thatuse othertypes of approach toreasoning.A
system shouldeasily
accomodate newknowledge.
This
couldbe
immediate
~infor
mation about the problem at
hand
that guidesdecision
making-or
long
term-changes to
the
knowledge base
ofthe system.These
maybe done
by
different
methods,but both
shouldbe
simple touse andhave
thebulk
oftheworkdone
by
thesystem.Finally,
the system should operatein
several modes,depending
on the expertise oftheuser.
It
should makedecisions
onbehalf
of the non-expert, makedata
manipulation andattempting alternates easier
for
the expert andbe
capable oflearning
from
those willing toshare their expertise. In this way
it
should reflect ahuman
expert, whose exactbehavior
depends
notonly
upon the problembut
also upon thedegree
of sophistication ofthe peoplehe
is
workingwith.4.2.
Knowledge
andits
uses.For
one such as myself, whose experience with computerized problem solvinginvolves
mostly
interactive,
computationintensive
programs,it is
tempting
toconclude that thekey
toexpert performance
lies in
the schemes(procedures)
onedesigns for
manipulatingdata.
However,
thisis
not the case."The
power of an expert systemderives from
theknowledge it
possesses, not
from
the particularformalisms
andinference
schemesit
employs"[Hayes-Roth].
Knowledgeis
key
~knowledge
representation andinference
schemes provide themechanism.
The
knowledge referred to really consists of two components:data
(facts
in
thefield)
and
heuristics (special
rules unique to thefield.)
Thus
most successful systems are not general ~ their content and
implementation
aredictated
by
the content andformalisms
of theIt
has been
a"long
term" goal(if
soyoung
afield
canhave
such athing)
of personsdeveloping
expert systems to create a more generalinference
mechanism.This
will notbe
an"expert in
everything,"but
rather willbe
a generalknowledge
manipulator which canbe
supplied with
(or
learn)
variousdata bases
tobecome
aninstant
expertin
thefield
of choice.In
fact,
one can obtain suchsystems(eg,
IRIS,
TEIRESIAS).
However,
at present these arerather restrictive and
only
serve wellfor
simpleproblems, evenif
youhave
an expert willingto usethem.
So far
wehave
treatedknowledge
as an absolute. Infact,
much usefulknowledge
is
somewhat uncertain ~
this may
be
true,
orusually(but
notalways) thathappens.
To be
ableto
deal
with complex problems, an expert system mustbe
able todeal
with uncertain(fuzzy)
data
and probabilistic rules.This
canbe
handled,
to somedegree,
by
the use ofweightingfactors,
but
is
an areaofexpert systemresearchthatcanusefurther development
[Negoita].4.3.
Kinds
ofSystems.
There
aremany
possible ways to organize theknowledge
that the system contains andmanipulates.
Some
ofthesearediscussed below.
4.3.1.
State Space Search.
The
problemis
structuredin
terms of alternatives available at each state.The
next possible states are
determined
by
a set of rules and transitive operators.In
general thisleads
toa combinatorial explosion which requires
discarding
certain states(not
examining them orstates
derived from
them.)
One
type ofspace state searchis
called generate andtest,
where all possible next states are generated and sometesting
procedurediscards
poor(unlikely)
ones.
4.3.2.
Logical Systems.These follow
the rules offormal logic
and are most suitedfor
small, welldefined
sysselection.
4.3.3.
Procedural
Representations.
This
involves
a series of small steps, each the result ofa well-defined situation.Often
thesegive
operationally
goodresults,but
ones thataredifficult
toexplain.4.3.4.
Semantic
Nets.
These
consist ofnodes(objects,
concepts,events)
andlinks
(interactions). Related facts
can
be closely
linked
to reduce the effective search space.The
netis
notdirected,
so theentire search space
is
always available, making this a very versatile and possibly complicatedmethod.
4.3.5.
Frames.
These
aredata
structures thatinclude declarative
and proceduralinformation
as well asrelationships.
One
oftheinteresting
attributes you can programinto
aframe
is
the ability todecide
if
it is
usefulin
a givensituationand,if
not, tocall anotherin its
place.4.3.6.
Production
sytems.The
basis
ofthese systemsis
a set ofrulesin
theform if
(condition)
then(action).
Eachrule
is
explicit andindependent (doesn't
call another rule.)This
organizationis
goodfor
large
systems thatinclude
self-modification as afeature,
as the rules can refer to the systemitself
aswell asto thearea ofknowledge
thesystemis
about.A
"pure"production system would consist of a rule
interpreter (inference engine)
and atwo-part
data base:
aset of rules and a collectionoffacts.
How closely
the rules are coupledto the rule
interpreter
and how general theirform
is
willdetermine how domain
specificthesystem
is.
As
mentioned above, most systems are,in
fact,
quitedomain specific, due
to theform
oftherules andthetailoring
oftheinference
engine.The
rules themselves wouldhave
the conditions evaluated(or matched)
with referenceanother appropriate rule would
be
applied or afailure
indicated.
More
than one rule mayapply
to a givensituation,
so some sortof conflictresolutionis
necessary.The data
base is
the sole storagefor
all the state variables ofthe system.It is
totally
and
equally
accessibleby
all rules.If
desired,
it
canbe
modified eitherby
theuser orby
the programitself.
The
interpreter
assistsin selecting
and executing the relevant rule andin
interacting
with the user.
It may
also contain some sort of explanationfacility,
althoughthisis
notreallya part of a"pure" system.
4.4.
Examples.
4.4.1.
DENDRAL.
One
ofthefirst
successful expert systems, DENDRAL uses agenerate and test organizationto
deduce
organic structuresfrom
mass spectrograms.Its
strengthlies in
an exhaustivealgorithm to generate all possible structures and an effective test series to prune the search
tree
(ie,
an extensive setofrules relatedtomassspectrography.)4.4.2.
meta-DENDRALA
system thatlearns how
tointerpret
mass spectrogramsby being
taughtby
an expert.It
is
supplied spectra and seeksinterpretations from
the expert,from
whichit
derives
its
ownrules.
It
thenhelps
theexpert(or
others) tointerpret
other spectra.4.4.3.
CASNET.
This
is
anetwork systemdesigned
to aidin
thediagnosis
of glaucoma.Nodes
are confirmed
ordenied
by
questionningthedoctor
and thenthe treatmentis
found
in
atable.It
is
4.4.4.
MYCIN.
MYCIN
is
a production rule systemdesigned
todiagnose infectious diseases.
It inter
views
doctors
and recordsfacts
along
withconfidencefactors. It
possess more than500
rules,5.
Implementations.
5.1.
General.
In
Building
Expert
Systems,
Hayes-Roth
et. al. outline an approach to the actualimple
mentation of an expert system.
They
suggest thefollowing
steps:Identification.
Identifying
theproblem andits
characteristics.Conceptualization.
Deciding
on the concepts to representfactual knowledge
and theknowledge
containedin
theheuristics.
Formalization.
Designing
structures to organize theknowledge.
Implementation.
Designing
interpretation
methodsfor
thedata
andheuristic,
andTesting.
Validating
the system.The
actualdesign
process, ofcourse, consists of multipleiterations
throughthesteps.Note
that the expert plays akey
rolein
theidentification
andimplementation
steps, aswell as
lesser
rolesin
the others.This
reemphasizes a point made many timesin
myreading:the expert must
be
consulted early and often.Knowledge
is
thekey,
not the programmer's cleverness, althoughthis alwayshelps.
The
systemis
moreflexible
and easiertoupdateif
theknowledge base
is
separatefrom
the
inference
engine.This does
not mean you musthave
just
twolarge
files,
but
rather thatthe
logical
controlfunctions
are separatedfrom
thedata.
In
general, one can nottotally
accomplish
this,
but
it
shouldbe
attempted.The
intertwining
of control andinterpretation
and the unique
format
ofthe interpretation methodis
what makes most expert systems more5.2.
Choice
ofLanguage.
Most
workin Artificial Intelligence
up to thisdate has been done in
somedialogue
ofLISP,
even though thisis
not always apparent.For
example, one ofthe standard textsin
thearea
[Winston]
is
more orless language
independent,
but
comes with asupplementary volumein
which all ofthe examplesin
thebook
areimplemented
in LISP.
Indeed,
this companionvolume
is
designed
as aLISP
teaching tool,
so one canlearn Artificial Intelligence
and"its
language"
atthe same time.
Some
reasonsfor
this are offeredby
Hayes-Roth.
Both authors emphasizethe ability ofthe
language
tohandle
symbols and perform 'computations' with them.It
is important
torealize that a symbol or word means nothing to the computer or to the
LISP
compiler,but
it
can
be
manipulated as thoughit did
(by
suitable algorithms.) LISPis designed
tohandle
large
numbers of symbols(lists)
and their relationshipsin
a recursivefashion,
andis
quiteeffective at
doing
this.Another
advantage of thislanguage is
thatit is
normally usedin
a ratherinteractive
environment, allowing the programto
be developed in
smallbits,
function
by function,
whichsaves a great
deal
of time.Also,
most elements of memory management are taken care ofautomatically,
freeing
theprogrammerfrom
someworries.Finally,
thereis
theleast
"solid"but
perhaps mostimportant
reason ~habit
[Foster].
LISP
is
sofirmly
entrenchedin
thefield
that manypractitioners simplydo
notwanttoinvest
the effort
in
learning
analternative.This
positionis bolstered
by
thefact
that manydevelop
ment tools are available
in
onedialogue
or another ofLISP,
and these canbe
massivetime-savers.
Recently,
achallengertoLISP
has
emerged.Prolog,
alogic
programminglanguage,
wasdeveloped in
Europe,
andis
popularthere andin
Japan,
whereit
was chosenas thelanguage
ofthe fifth-generationcomputer project.
One
ofthe main advantages ofProlog
is
that programmingin
it is
easier.As is
LISP,
it
development
stage, and canbe
implemented
and testedin
small stages.The
codeitself
is
often easier to understand than
is
that ofLISP,
though some recursive procedures canbe
equally confusing in
eitherlanguage.
It
is
also more portable thanLISP,
currently, atleast,
lacking
dialects
(as
we shall seelater,
thisis
notstrictly
true.)
Prolog
has
somedrawbacks,
also.It
saves the programmer the need to program asearch of a
large data base
by doing
it for
him,
but in
doing
solimits
the available options.The
searchstrategy
is
depth-first,
which canbe
quiteinefficient
whendealing
with alarge
data-base,
such asthose usedin
expert systems.It
is difficult
to change this strategyin
Prolog.One
can "get around"it
by
employingrather
baroque data
structures[Clocksin],
but
these addlittle
to program clarity or speed.Prolog
does employ
ahash
techniquein data
searches,but
once againtheprogrammerhas lit
tlecontrolin
cases where thisis
notthebest
approach.Prolog
is
also younger thanLISP,
and thuslacks
the well-thought-out set ofdevelop
ment tools ofthe older
language.
In addition,it is
closelytied to mathematicallogic,
whichsometimes makes
"common-sense"
logic
difficult
toimplement.
Another difference
is
thatLISP
is
"lower-level"than
Prolog,
allowing moreversatilityatthe price of
having
tohandle
moredetails.
Prolog
does
much of thedata-base
management"under
the hood,"but
certain approaches areharder
to employin it.
In particular,Prolog
is
ideal for
rule-based systems, where a ruleis
oftheform
'if x(and/or
y and/or ...) then a(and/or b
and/or...).Other
types of organization(e.g., blackboards)
canbe implemented in
Prolog,
but
not as easily.Some
choose to continue this conflict betweenlanguages
while others aretrying
toresolve
it. One
resolution approachinvolves
thedevelopment
oflanguages
thatborrow
strongpoints
from both
LISP and Prolog[Foster].One
such system,Super-LOGLISP,
is currently
under development at Syracuse
University,
andis
expected toinclude
parallelprocessing
capabilities.
A
second approachinvolves
writinginterpreters
that canhandle both LISP
andlanguage for
the useimmediate
problem.Both LISP
andProlog
are quite limitedin
theirability to
do
calculations, soit
wouldbe helpful
toinclude
some sort of upgradein
this area6.
Initial Decisions.
6.1.
Scope
Before actually
implementing
my system, I had
to make severaldecisions.
These
were'large'
in
nature anddetermined
thenature and scope oftheactual expert system.The
first,
ofcourse,
waschoosing
theproblemtobe
worked on.As
already mentioned,we
decided
to write a system thatdealt
withthefield
ofcladistics.This
is
of specialinterest
both
in itself
andin
referencetosome other(biochemical)
workthat Ihave done.
This led easily
to the seconddecision,
one of considerablyless
import.
It
seemednatural that an expert system
dealing
withcladisticsbe
namedClaud,
and soit
was.A
much moreimportant
questioninvolved
thebreadth
ofthe system ~who was to use
it
and what capabilitiesit
was tohave.
The
standard concept of an expert systeminvolves
creation experts
(in
computer science and thefield
ofinterest)
but
useby
non-experts. Anon-expert could
be
a"man
off the street,"but
more usually was envisioned as a person atleast
somewhatknowledgeable in
thefield
under consideration.The
way such a systemfunctions
can vary,but
certainbasic
elements are usuallypresent.
These include
adata
base,
a setofmanipulations(heuristics)
suppliedby
the expertand away to applythese manipulationsto the
data for
thecaseunderconsideration.In
addition there may
be
some ability to add to or change thedata base
and to explainthe way thesystem's conclusions were or were notreached.
Thus
the system can contain the ability to manipulate and change alarge data base
specific to a
field
aswell asthe ability to applycertainheuristics
toit. The
manipulative abilities
wouldbe
extremely useful to another expert, whoprobably doesn't
need, atleast
constantly, the
heuristics in
theprogram ~he brings his
ownto theproblem.Thus,
withjust
a small(sic)
amount ofadditionaleffortthesystem canbe
madeto serveother experts as well as non-experts.
It
wasdecided
toinclude
these capabilitiesin
Claud,
implement
suchfacilities.
The
next problem todeal
with was the role of the expert.I
had been
promisedcooperation
by
Dr.
Richard
Brown,
an entomologist whodid
traditional cladistics and wasalso
interested in
expanding
its
scope toinclude
biochemical data.
Although
I
was convincedofthe
necessity
ofkeeping
in
close touch withhim,
thefact
thathe
was(and
is)
in Missis
sippi raised somepractical
difficulties.
Thus
we compromised on thefollowing
scheme.I
discussed
the general approach withDr. Brown
several times via telephone.He
then supplied me with some ofhis
"rules-of-thumb"
aswell as somereal
data
andhis
conclusionsfrom
them.I
incorporated
theheuristics
into
Claud,
performed the type of analysishe does
(see
below)
and checkedback
withDr.
Brown
tobe
sure thatI
understoodhim
andthatClaud
reached reasonable conclusions.The
fact
thatit
did
wasgratifying but
expectedontherathersimplelevel
thatClaud
functions.
This
process gave me averyclearillustration
oftheneed tobe
close to the expert.The
kind
ofheuristics Dr. Brown
was able to come up withby
himself
were quite simple andunsophisticated,
leading
to rather simple(uninteresting)
rulesfine for illustration but
notadequate
for
real analysis.I
feel
thatif
wehad been
able tointeract
moredirectly
he
wouldhave been forced
todelve
moredeeply
into
the actualmentalprocesseshe
uses andthe rulesobtainedwould
have been
much moreinteresting.
We
alsohad
todecide
on the type of analysis thatClaud
would actuallydo.
Cladistics
normally
is
done in
three stages: gatheringdata,
interpreting
it
anddoing
statistical analysis.The
first
stage, gatheringdata,
is
essentially aliterature/laboratory
project, andis
not reallywhat we expect of an expert system.
The
statistical processis
either cluster analysis or avariation of
it,
and canbe done
by
standard packages(e.g.,
Genstat).
Although
this couldbe
included in
Claud,
it
wouldbe
awkward andredundant.Thus
it
wasdecided
tolimit Claud's
abilities to thoseinvolved
in
the analysis ofdata.
This
wouldinclude
rules tointerpret
thedata for
non-experts(i.e.,
telling
themhow
toexpert,
so she could seehow
various assumptions would changetherelationships amongcharacters,
otus, etc.Finally,
wehad
to choose thelanguage
in
which toimplement
the system.At RIT
wehave
both LISP
andProlog
availible, but do
nothave any
ofthedevelopment
tools thathave
been
written to support expert system writingin LISP.
We
alsohave
more orless
a wideopen
field
~not
many
expert systemshave been
writtenhere.
We
decided
touseProlog
for
several reasons.Without
theLISP development
tools,
thesimplicity
ofProlog
programming
was attractive.Also,
relativelyfew
expert systemshave
been
writtenin
Prolog,
so we would notjust
be
reinventing the wheel.That
is,
there aremany
basic
procedures that mustbe
usedin
any system, and thesehave been
well studiedin
LISP.
However,
since wedid
nothave
access to them we wouldhave
to startfrom
scratch.Writing
thesein
Prolog
wouldbe
morein
thenature ofbreaking
new ground, and would alsobe
useful toany
whofollowed
us and needed such proceduresfor
usein
morefully
developed
systems.Another
strong argumentfor
usingProlog
was that theform
of cladistic analysis naturally
suggests the use ofa rule-based system.These
systems contain rules,data
and away tomanipulate them
(inference
engine), all of which are relativelyeasy
to programin Prolog.
The
rules mayhave
similar or varyingformats,
and theinference
engine canbe
general orquite specific,
depending
uponhow
general(adaptable
to other uses) you wish to make thesystem.
As
cladisticsis
a rather specific(esoteric?)
branch
ofbiology,
the rules would probably
be in formats
specific to thefield,
but it
wouldbe
worthwhile totry
and make themanipulativeprocedures asgeneral as possible.
After
having
made thisdecision,
I discovered
aninteresting
situation.I
have
access toa
Prime
computer at theNew York State
AgriculturalExperiment Station
in
Geneva,
abranch
ofCornell
University.This
computerhas only
threelanguages
availible onit:
APL,
FORTRAN and
Salford
LISP/Prolog.The latter
is
aninterpreter/compiler
written atfact,
one can eveninsert
compiledFORTRAN
codein
theprogram.This
meantthatI
couldcode
in
Prolog
and still useLISP
commands wheneverthey
were more convenient(i.e.,
input/output.)
The
Prolog
differs
slightly from
theC-Prolog
available atRIT
(see
below),
but
has
thesamebasic
capabilities.In
addition to thelanguage
for
an expert system, there was also someone at the stationwho
had actually
written part of such a system.Although
the system was notfully
operative(the
expertdied
asthey
werewriting
it),
it
was extremelyhelpful
tobe
able todiscuss
theproblems
involved
in creating
such a systemwithsomeonewhohad
actuallydone
it.
6.2.
Details.
Having
decided
on the scope ofthe system,I
stillhad
somedetails
to work out.For
example,
how
would the userinteract
with the system?Although
Idon't like
usingmenu-driven
systems,it
seemed that thisform
was most appropriatefor
the non-expert part ofthesystem.
Basically,
thereis
alot
ofinformation
that the system canhandle,
but
thenumber ofchoices to
be
made as to the manner ofhandling
is
quitelimited
and perscribed.Thus
thereis
no needto offerdifferent
formats
and extensive options ~a choice
from
alist
willdo
fine.
When
being
usedby
an expert, the system could "discuss"his
optionsby
asking afew
simple yes-no or
fill-in-the-blank
type of questions.It
could then offer options, advice orconclusions,
depending
upon whichwas required.It
wasdecided
tofind
a general way todeal
with multiple choice type questions(and
appropriate actions.)
This
oneform
could service multiple choice, menu and yes-no typequestions. Fill-in-the-blanks
(e.g.,
"What
otudo
you wish to change?") wouldbe handled
onan
individual basis.
This
resultsin
all questions ofthefirst
three typeshaving
the samefor
mat and processing,while thoseofthe
fourth
type coulddiffer
in form
andtreatment.The
nextdecision
was promptedby
the awkwardness ofthePrime
editor.In
fact
it is
virtually unusable ~
I
used the word processor(Muse)
to createmy
files.
The
system wouldcom-plete system.
The
systempresently
consists of sixfiles:
(1)
The
mainfile,
calledClaud,
which consulted the otherfiles
and askedif
the userwishedto
employ
theexpertor non-expert aspect ofthe system;(2)
A
file
containing
themultiple choice questionprocessing
rules;(3)
A
file,
calledoddsandends, containing
other useful'tools',
such as a general exit routine,
printing predicates, etc.;
(4)
A
file
thathandles input.
In general, the system willacceptinput from files
that containonly
data,
but
stores theinformation
as relationships which are predicatesin Prolog.
Thus
someprocessing
ofinput data is
required;(5)
A
file
thatcontains theheuristics
tobe
usedby
the non-expert; and(6)
A
file
that contains thedata base
manipulation proceduresfor
useby
the expert.This
file
referencesthe previousone, sotheexpert canalso access thebuilt-in
rules.Although
not all expert systems contain one, I always planned tohave Claud
include
anexplanation
facility.
How todo
this was worked out ratherlate in
the process(see
below),
but
when to explain actions wasdecided early
on.It
seemed that explanations were mostuseful when something
didn't
work as expected; whenit did
work only the results wererequired
(have I been
using UNIX toolong?)
So it
wasdecided
toinclude,
with each rule,the
ability
to explainwhyit
did
notfunction
if, indeed,
it did
not.The
explanations were tobe
as specific as possible ~ the "segmentationfault
~core dumped" syndrome was to
be
avoided as much as possible.
Finally,
thedecision
as tohow
much ofthe otherlanguages
availible to me~LISP
andFORTRAN
- were tobe
usedhad
tobe
made.The fact
that no statisticalcalculations wereto
be
included
meantthat FORTRAN wasnot reallyneeded.Although
thiswas notdecided
entirely
untilClaud
wasdone,
thereturned outtobe only
one occasion whereLISP
was preferred
toProlog
~input from
the keyboard.Salford
Prolog
requires a period after allinput
procedure
'READ',
whichdoes
nothave
this requirement, was used.No
special coding7.
Elements
oftheSystem.
7.1.
Tools.
The
first
priority in writing Claud
was to create a set of generally useful tools thatwould
simplify writing
the rest ofthe systemAs
mentioned above,I had
the opportunity ofspeaking
to a person whohad already
written an expertsystemin
Prolog,
so Ihad
afair
idea
of what was needed.
Another
reasonfor
doing
thisfirst
was that codefor
these procedurestends to
be
fairly
simple, so that this offered a chancetoperfect(or
atleast
improve)
myownabilities
in writing
Prolog
code.In
Prolog,
the orderin
which the various constructs are executeddepends
upon thesuccess or
failure
ofsurrounding
constructs.Success
allows you to proceedforward
whilefailure
causesbacktracking
~how
much and
how
far
canbe
controlled, to some extent,by
the use ofthe cut
(!).
This
variabilityin
execution orderis
one of the specialfeatures
thatmakes
Prolog
so suitablefor Artificial Intelligence
applications. Program execution sequenceis
not always under the control of the programmer, so that the variations possible are muchmore complexthan those usuallyachievablewitha simple
if-then-else
structure.However,
sometimesit is
necessary tobe
able to predict whether a rule or predicatewill succeed or not.
If
failure is
desired,
afail
predicate canbe
included in
the rule. However,
it
is
not so simple toguarantee success.Thus
I wrotemyfirst
rule, whichassures thatagiventasksucceeds:
accomplish(Task)
:-Task
; true.The
semi-colonis
an"or",
so either the task ortrue,
whichis
always true.As
an aside, wecan noticeProlog's rathersplit personality,where
fail is
'fail',
but
succeedis
'true.'Note
thatthis rule certainlymeets thegoal ofstartingwithsimple code.
Next
we needed the ability to easily output phrases.Prolog
has
the standard predicate'write',
but it is
rather limited.In its
more generalform
it
accepts two arguments:something
be
0,
the standard output stream.Thus
thefollowing
predicates were written, roughlycorrespond to the
Pascal
"write"and "writeln" commands:
prln(List)
:-prln(0,List),!.
prln(Unit,List)
:-pr(Unit,List),
nl(Unit),!.pr(List)
:-pr(0,List).
pr(Unit,[]).
pr(Unit,[First|Rest])
:-write(First,Unit),
pr(Unit,Rest),
To
output a phrase,invoke
"pr(['phrase'])."To
output phrases and variables, use,for
example, "prln([X,'
is before
\Y])."I
felt it
wouldbe
useful tobe
ableto end theprogram atany
time,
saving
thedatabase.
Thus I
wrote the rule 'byebye' whichdumps
thedata
into four files
(char,
otu, ances andhaschar)
and returns the user to theProlog
system ('abort'in Salford
Prolog.)
Of
course,these
files
contain predicates, notjust
rawdata,
and somay simply be
consultedtobe
readin
to anew run oftheprogram.
All
input
by
theuseris done
through theprocedure'readin.'
This
is
sothat,
at anytime,
theuser canterminate the currentprogram run
by
typing
theletter
e.readin
:-X
is
'READ'O,
(X
=e,
byebye;
true).
READ
is
aLISPproceduredirectly
usablein Salford
Prolog.Finally,
a way to count things such as predicates(i.e.,
howmany
instances
of type"name"
currently exist
in
thedatabase)
was needed.It
turns out that thisis
not so simple, asthere are no true variables
in
Prolog
- statements such asX
=X
+ 1 are notlegal.
In
fact,
this way.
I
was stumpedby
thisfor
a whileuntil
Prof. Biles
suggested theapproach ofusingthe
data
base
as aplace tokeep
track ofthings.
Thus
wecandeclare
thepredicate count(X),where
X
is
the magnitude ofthecount.For counting in
general we need two abilities: zero the count andincrease
the count.Thus
wedefine
twonew rules toallow us todo
this.clearcount
:-abolish(count,l),
assert(count(0)).
upcount
:-count(X),
abolish(count,l),
Y
is
X
+1,
asserta(count(Y)).
The
count canbe
determined
atany
timeby
calling
count(Value).We particularly
want theability
to counthow many
instances
of a certain predicateoccur
in
thedata base.
To do
this we use thebuilt-in
predicate 'functor.'Functor(A,B,C)
declares
A
tobe
a structure withfunctor B
and number ofargumentsC.
Thus,
supplying
Band
C defines A.
countpred(Pred,Arity,Count)
:-functor(Name,Pred,Arity),
clearcount,
accomplish(countpred(Name)),
count(Count).
countpred(Name)
:-(Name,upcount),
fail.
Countpred/3
worksby declaring
the passed predicate, using 'functor,'zeroing
the count,counting
by
means of countpred/1 and returning the valuein Count. Note how
countpred/1works.
If
a predicate of the given nameis
found,
we execute upcount and thenfail.
This
failure
causes,
by
backtracking,
the next predicate ofthe same name tobe
searchedfor.
If
not
found,
the whole rule returns afailure.
But
countpred/1is
'accomplished'in
7.2.
Multiple Choice Question Handling.
Next,
it
wasdecided
toimplement
the clauses thathandled
multiple choice types ofquestions.
Discussions
withmy "Expert Systems
Expert"led
to theidea
ofhaving
a multiplechoice operator, so that each question could
have
an associated questionidentifier.
The
question
itself
would consist of alist
of prompts andresultant actions.The first
wouldbe
themainprompt that
headed
the question andtherestwould representthechoices.Prof.
Biles
recommended that the questions consist of alist
ofitems,
where eachitem
consisted of a string
(to
be
displayed)
and a resulting action.This
made theform
of thequestionclearer andthe numbering ofthe choices easier.
Thus
atypical questionlooks
like:
mainmenu multiplechoice
([item(['Do
youwishto:'],
dummy),
item('have Claud
give you advice',advisor),
item('discuss
withClaud
yourproblem',discussion),
item('end
this session',byebye)]).
This
willbe displayed
as :Do
youwish to:1)
have Claud
giveyouadvice;2)
discuss
withClaud
your problem;3)
endthis session.Enter
choice:Notice
thatthefirst
item,
theheader,
is different from
thelatter
items,
thechoices.The
clauses used todisplay
the question and act on the response are shownin Fig. 1.
The
rule'multchoice'
displays
the general prompt, takes anyinitial
actionif
oneis
desired,
displays
the choices, promptsfor
aresponse and takes theactiontheresponse requests.Note
that the
form
of the actual ruleis
differentfrom
thatjust described. There
are two reasonsfor
this.First,
in
general there willbe
noinitial
actiondesired (in
the example question givenabove the action was
"dummy"
-
i.
e.,do
nothing.)Thus
this actionis
identified
by
multchdecomposeand then
'accomplished,'
:-
mode(
'prv2')
./*
Clauses
to take
care of multiple choice questions.These
should /*have
the
form:
/* question
id
multiplechoice
/* Citem(['
initial
prompt'],
initial
action(set
vars,
etc)),
/*
item( 'choice
1',
actionresulting from first
choice),
/*
...].
/* or
initial
item
may be
replacedby
the
single word"noprompt".
/*Multchoice does
the
initial
steps(if
they
arethere)
and /* callsother clauses
to
processthe
question.READ
is
aLisp
/*function that
reads characters without
the
necessity
of /*typing
a period afterthem.
mul
tchoice(
[noheaderllQuestion]
)
:-repeat,
mul
tchdisplay(
Question,].),
pr(['
enter choice:
']),
readin(X),
multchaction(Question,X),
/*fails
oninvalid
response nl.mul
tchoice(
Question)
:-mul
tchdecompose(
Questi
on,Prompt
,Task
,Rest)
,accomplish
Task)
,repeat,
prln(Prompt),
nl,
multchdisplay(Rest,l), pr(['Enter choice:
']),
readin(X),
multchaction(Rest,X),
/*fails
oninvalid
response nl./*
/*
Takes
a
list
(eg,
of questions and actions) anddecomposes
/*it
to the
first
item,
seconditem
andthe
rest ofthe
list.
/*mul
tchdecompose(
[Fi
rstllRest]
.Prompt.Task.Rest) :-mul
tchdecompose( Fi
rst, Prompt
,Task
)
.mul
tchdecompose(item(
Prompt, Task), Prompt,
Task).
/*/*
Displays
the
variouschoices,
numbering them.
/*mul
tchdi
splay
(Questions
.Number) :-multchdecompose(Questions,Lastques,Lasttask,[]),
prln(
[Number
,'
)
' .Lastques,'.']),
nl,
mul
tchdi
splay
(Questions,
Number)
:-mul
tchdecompose
(
Questi
ons,Nextques
,Nexttask
,Rest
)
,prln([Number,')
',
Nextques,';']),
Numplus
is
Number
+1,
mul
tchdi
splay
(
Rest
,Numpl
us)
,/*
/*
These
clauses perform an approprate action after/*
the
response
is
readby
the
READ function.
/*
The
first
clausedeals
with aninvalid
response,
causing
a/*
prompt
to
be
printed andthe
questionto be
redisplayed./*
Length
is
abuilt in function
that
determines
the
length
/*of a
list.
The
'get' clauses getthe
appropriate/* command
from
the
question
list
and returnit
to
be
executed./*
Note
that the
commandis
not"accomplished",
thus
it
can/*
fail,
which causes an error messageto
be
printed/* and an
alternate selection requested.
/
*mul
tchacti
on(Quesli
st,
Selection)
:-length
(Quesli
st,
Length),
Numques
is
Length,
(Selection
<1
;
Selection
>Numques),
nl,
prln(['
Invalid Selection
try
again']),
nl , nl ,
fail.
mul
tchaction(Queslist,
Selection)
:-1
ength(
Quesl
i
st, Length
)
,Numques is
Length,
Selection
>=1,
Selection
=<Numques,
mul
tchget( Quesl
ist, Selection, Command),
(
Command
;
nlSelection
inoperative
choose again']) ,nl ,fail)
i
mul
tchget(Quesl
ist,
PI
ace,
Command)
:-multchgetcom(Queslist,Place,[item(Ques,Command)HRest]).
multchgetcom(List,l,List) :-
!.
mul
tchgetcom([First1IRest], Number,
Dummy)
Num2
is
Number
-1,
exist the rule continues.
Second,
one of the choicesmay have
an action associated withit
that
fails
~e.g., in
thedesign
phase one optionis
not yetimplemented.
Failure here
shouldresult
in
an error messagerequesting
adifferent
choice and redisplay ofthe question.Thus
the actions
in
the 'items'are not 'accomplished,'
but
canlead
tofailure.
An
error messageis
then printed
by
'multchaction' and theform
of 'multchoice' causes the question tobe
redisplayed.
The
clause 'multchdisplay' prints outthe stringportion ofeachitem,
suitablynumbered.It
alsoillustrates Prolog's
selection process.Any
Artificial Intelligence language has
todeal
with the situation when the programmer
desires different
actionsdepending
on theform
orcontent of the parameters passed to a procedure, rather than the chioce of the procedure.
Prolog
selects the correct rulepositionally
~it
tries thefirst correctly
named rulein
thedata
base
for
parameter match, then the second, etc.In
our case, when thelist
representingfurther
choicesis
empty
we are on thelast item
and want specialhandling
~e. g., no more
recursion.
The
final
cutis
necessary to prevent reentry onbacktracking
in
case offailure in
'multchoice.'
The
list
ofitems
and the users choice are passed to 'multchaction' which thenexecutesthe appropriate action.
The
first
clause named multchactiondetermines
thelength
ofthelist
(the
number of possible choices) and generates an error messageif
the choiceis impossible
(too
large
or too small.).It
thenfails,
so that the second clause of this nameis
alwaysentered.
This
clausefails
immediately
if
the choiceis
impossible.
If
it is
alegal
choice,'multchget'
goes
down
thelist
to the appropriateitem
and returns thedesired
actionin
thevariable
Command.
Then either this commandis
successfully executed or a "selectionino
perative"
error message
is
generatedandtherulefails.
7.3.
File Handling.
In
general, theinput
toClaud
will comefrom four
previously createdfiles.
These
files
contain
only data
~strings or numbers
filehandler
:-charlist,otulist,ancestorlist,hascharacter,
multi
piechoice(seehaschar,
Question),
mul
tchoice(
Question)
.charlist
:-nl,
pr(['Enter
the
name ofthe
characterfile:
']),
readin
(Name)
,fileopen(Name,4,read),
for(Num, 1,1000,1),
read(Char,'LINE',4),
assertit(Num,
Char,
char),closeunit(4)
,nl
Characters
are:']),nl,
printit(char).
otulist
:-nl.
pr(['Enter
the
name ofthe
otufile:
']),
readin
(Name),
fileopen(Name,4,read)
,for(Num, 1,200,1),
read(0tu,'LINE',4),
assertit(Num,0tu,otu),
closeunit(4),
nl ,prln(['0tus are:
']),nl
,printit(otu).
ancestorlist
:-nl,
pr(['Enter the
name ofthe
ancestral characterfile:
]),
readin
(Name),
f
i 1
eopen(
Name
,4
,read)
,for(Num,l,1000,l),
read(Char,'LINE',4),
assertit(Num,Char,ances),
closeunit(4),
nl,prln([
'Ancestral
characters are:]),nl,
printances.printances
:-ances(Z.X),
char(X.Y),
prln([X,')
',Y]),
fail.
printances :- nl .
hascharacter
:-nl,
prln(['Enter the
name ofthe
file that
']),
pr(['relates otus and characters:
']),
readin(Name),
fileopen(Name,4,read)
,for(Num, 1,1000,1),
Otu is
'READ'(4),
asserthasc(Otu),
closeunit(4)
.asserthasc(Otu)
:-Otu
='END
OF
FILES',
Char is
'READT4),
isitances(Otu.Char),
.fall.
asserthasc(_)
.isitances(Otu.Char)
:-ances(_,Char),! ,
assertz(haschar(Otu,Char,0)).
isitances(Otu.Char)
:-assertz
(
haschar
(
Otu
.Char,10
)
)
.seehaschar multiplechoice
([item(['Do
you wishto
seethe
otu/characterentries?'],
dummy )
,item(
'yes' ,display),
item(
'no' ,prln([]))]).
display
:-nl,
prln(['0TU
Character
-(A)
meansancestral']),
nl,
haschar(Otu,Charnum,Code),
char(Charnum.Char),
otu
(Otu,
Name),
pr(
[Name]
),tabulate(
17
),pr(
[Char]),
((Code
= 0,pr(['(A)
']))
;prln([])),fail.
di
splay
: -nl ./*
/*
Asserts
strings(or
any
otherterms)
readfrom
afile
andfails,
/*Suceeds
when end offile
is
reached. /*assertit(Num,
String,
Name)
:-Stri ng
= 'END__0F_F
I
LE$
' ,assertz(Name(
Num.
String)
)
,I
.fail.assertit(_,_,_).
/*
/*
Prints
out all occurances of a predicate/
2
/*passed
to
it in
Name(eg,
characterlist,
etc). /*printit(Name)
:-call(Name(X,Y)),
prln([X,')',Y]),
fail.
printit(
)
:- nl.
entered
into
thedatabase
as predicates.The
clauses todo
this aregivenin
Fig
2.
The
careful
reader will notice thatin
these rules similarfunctions
are sometimes coded differently.This
is
partly
because
I
wanted totry
different
thingsin
Prolog
and partlybecause
Ididn't
always recognizethat thecode could
be
the same, and so rewroteit.
The
files
containing
the characterlist
and the otulist
are similar, each containing onestring
perline.
They
shouldbe
enteredin
thedata
base
as predicates containing a numberand the string, e.g.,
char(3,
'big
nose')
or otu(7,'mother-in-law').We
can seehow
thisis done
b