You are on page 1of 48

Introduction to Expert System

History of AI
Rule-Based Systems
INTRODUCTION TO INTELLIGENT SYSTEMS

y Introduce students to the fundamentals and


applications of intelligent systems.
y Includes neural networks, genetic algorithms,
fuzzy logic, rough set as well as rule-based and
hybrid expert systems
y Methods have been applied successfully to a
variety of problems ranging from chess playing
and predicting financial markets to detecting
cancer cells.
INTRODUCTION TO INTELLIGENT SYSTEMS

y Understand the basic concepts of artificial


intelligence
y Understand how the different methodologies
can be used to solve complex problems in the
real world.
y Ability to evaluate and choose the right
intelligent system metodology to solve a
particular problem.
y Know when to use intelligent systems for a
particular problem.
y Be able to build a simple Expert System and
Artificial Neural Network Application.
Intelligent Machines

y The Big Questions of the Universe:


◦ How does a human mind work
◦ Can non-humans have minds?
y Intelligence is the ability to understand and
learn things.
y Intelligence is the ability to think and
understand instead of doing things by instinct or
automatically.
„ We can define intelligence as the ability to
learn and understand, to solve problems and
to make decisions.
Early Expert Systems

y DENDRAL (Stanford) used to determine the


molecular structure of Martian soil, based on the
mass spectral data provided by a mass
spectrometer.
„ The DENDRAL project originated the fundamental
idea of expert systems – knowledge
engineering, which encompassed techniques of
capturing, analysing and expressing in rules an
expert’s “know-how”.
Early Expert Systems

y MYCIN was a rule-based expert system for the


diagnosis of infectious blood diseases.
y MYCIN’s knowledge consisted of about 450
rules derived from human knowledge in a
narrow domain through extensive interviewing
of experts.
y The knowledge incorporated in the form of
rules was clearly separated from the reasoning
mechanism.
y A domain-independent version of MYCIN called
EMYCIN (Empty MYCIN) was later produced
Early Expert Systems

y PROSPECTOR was an expert system for mineral


exploration which used a combined structure that
incorporated rules and a semantic network.
y PROSPECTOR had over 1000 rules.
y The user input the characteristics of a suspected
deposit: the geological setting, structures, kinds of
rocks and minerals.
y PROSPECTOR compared these characteristics with
models of ore deposits and made an assessment
of the suspected mineral deposit.
y It could also explain steps used to reach the
conclusion.
Rule-based expert systems

y What is knowledge?
y Rules as a knowledge representation
technique
y Structure of a rule-based expert system
y Characteristics of an expert system
y Forward chaining and backward chaining
y Conflict resolution
y Summary
Knowledge

y Knowledge is a theoretical or practical


understanding of a subject or a domain.
y Knowledge is also the sum of what is currently
known
y Anyone can be considered a domain expert if he
or she has deep knowledge (of both facts and
rules) and strong practical experience in a
particular domain.
Rules
Most experts are capable of expressing their
knowledge in the form of rules for problem solving.

IF the ‘traffic light’ is green


THEN the action is go

IF the ‘traffic light’ is red


THEN the action is stop

Any rule consists of two parts: the IF part, called


the antecedent (premise or condition) and the
THEN part called the consequent (conclusion or
action).
Rules
y A rule can have multiple antecedents joined by the
keywords AND (conjunction), OR (disjunction) or a
combination of both.

IF <antecedent 1> IF <antecedent 1>


AND <antecedent 2> OR <antecedent 2>
. .
. .
. .
AND <antecedent n> OR <antecedent n>
THEN <consequent> THEN <consequent>
Rules
y The antecedent of a rule incorporates two parts:
an object (linguistic object) and its value. The
object and its value are linked by an operator.
y Operators such as is, are, is not, are not are used
to assign a symbolic value to a linguistic object.
y Mathematical operators define an object as
numerical and assign it a numerical value.

IF ‘age of the customer’ < 18


AND ‘cash withdrawal’ > 1000
THEN ‘signature of the parent’ is required
Rules: relations or recommendations
Rules can represent :
y Relation (there is relation between antecedent
and consequent)
IF the ‘fuel tank’ is empty
THEN the car is dead
y Recommendation (the value of recomondation
are And statement and Or statement)
IF the season is autumn
AND the sky is cloudy
AND the forecast is drizzle
THEN the advice is ‘take an umbrella’
Directives and Strategies
y Directive (depend on statement in antecedent and how
correlation to consequent)
IF the car is dead AND the ‘fuel tank’ is empty
THEN the action is ‘refuel the car’

y Strategy
IF the car is dead
THEN the action is ‘check the fuel tank’;
step1 is complete

IF step1 is complete AND the ‘fuel tank’ is full


THEN the action is ‘check the battery’;
step2 is complete

IF step2 is complete AND the ‘battery’ is ok


THEN the action is ‘check the busy’;
step3 is complete
Basic structure of a rule-based expert system
K n o w le d g e B a s e D a ta b a s e

R u le : IF -T H E N F act

In fe r e n c e E n g in e

E x p la n a tio n F a c ilitie s

U s e r In te rfa c e

U ser
Production Rule Systems

y The knowledge base contains the domain


knowledge useful for problem solving represented
as a set of rules.
y When the condition part of a rule is satisfied, the
rule is said to fire and the action part is executed.
y The database includes a set of facts used to
match against the IF (condition) parts of rules
stored in the knowledge base.
Production Rule Systems

y The inference engine carries out the reasoning.


It links the rules given in the knowledge base with
the facts provided in the database.
y The explanation facilities enable the user to ask
the expert system how a particular conclusion is
reached and why a specific fact is needed.
y The user interface is the means of
communication between a user and an expert
system.
Complete structure of a rule-based expert system

E x te r n a l
D a ta b a s e E x te r n a l P r o g r a m

E x p e r t S y s te m
K n o w le d g e B a s e D a ta b a s e

R u le : I F - T H E N F act

I n fe r e n c e E n g in e

E x p la n a tio n F a c ilitie s

D e v e lo p e r
U s e r In te r f a c e In te r f a c e

U ser
K n o w le d g e E n g in e e r
E x p e rt
Forward chaining

y Domain knowledge is represented by a set of IF-


THEN production rules
y Data is represented by a set of facts about the
current situation.
y The inference engine compares each rule stored in
the knowledge base with facts contained in the
database.
y When the IF (condition) part of the rule matches a
fact, the rule is fired and its THEN (action) part is
executed.
y The matching of the rule IF parts to the facts
produces inference chains.
y The inference chain indicates how an expert
system applies the rules to reach a conclusion.
Inference engine cycles via a match-fire procedure

Database

Fact: A is x
Fact: B is y

Match Fire

Knowledge Base

Rule: IF A is x THEN is y
An example of an inference chain

Rule 1: IF Y is true
AND D is true
THEN Z is true
A X
Rule 2: IF X is true
AND B is true B Y
AND E is true Z
THEN Y is true E D
Rule 3: IF A is true
THEN X is true
Forward chaining

y Forward chaining is data-driven reasoning.


y The reasoning starts from the known data
y The topmost rule is executed and adds a new fact
to the database.
y Any rule can be executed only once.
y The match-fire cycle stops when no further rules
can be fired
Forward chaining

Database Database Database Database

A B C D E A B C D E A B C D E A B C D E
X X L X L Y X L Y Z

Match Fire Match Fire Match Fire Match Fire


Knowledge Base Knowledge Base Knowledge Base Knowledge Base
Y&D Z Y&D Z Y&D Z Y&D Z
X&B&E Y X&B&E Y X&B&E Y X&B&E Y
A X A X A X A X
C L C L C L C L
L&M N L&M N L&M N L&M N

Cycle 1 Cycle 2 Cycle 3


Backward chaining

„ Backward chaining is goal-driven reasoning.


„ The expert system has the goal (a hypothetical
solution) and the inference engine attempts to find
the evidence to prove it.
„ The knowledge base is searched to find rules that
might have the desired solution i.e they have the
goal in their THEN (action) parts.
„ If such a rule is found and its IF (condition) part
matches data in the database, the rule is fired and
the goal is proved.
Backward Chaining
„ If the goal is not proved, the inference engine
puts aside the rule it is working with (the rule is
said to stack) and sets up a new goal, a sub
goal, to prove the IF part of this rule.
„ The knowledge base is searched again for rules
that can prove the sub goal.
„ The inference engine repeats the process of
stacking the rules until no rules are found in the
knowledge base to prove the current sub goal.
Backward chaining
Pass 1 Pass 2 Pass 3
Database Database Database

A B C D E A B C D E A B C D E
? ?

Z Y X
Knowledge Base Knowledge Base Knowledge Base
Y&D Z Y&D Z Y&D Z
X&B&E Y X&B&E Y X&B&E Y
A X A X A X
C L C L C L
L&M N L&M N L&M N

Each inline process is Goal: Z Sub-Goal: Y Sub-Goal: X


always back to first line
(back) till next line Pass 4 Pass 5 Pass 6
Database Database Database

A B C D E A B C D E A B C D E
X X Y X Y Z

Match Fire Match Fire Match Fire


Knowledge Base Knowledge Base Knowledge Base
Y&D Z Y&D Z Y&D Z
X&B&E Y X&B&E Y X&B&E Y
A X A X A X
C L C L C L
L&M N L&M N L&M N
Sub-Goal: X Sub-Goal: Y Goal: Z
Forward or backward chaining?

y If an expert first needs to gather some


information and then tries to infer from it
whatever can be inferred, choose the forward
chaining inference engine.
y However, if your expert begins with a hypothetical
solution and then attempts to find facts to prove
it, choose the backward chaining inference
engine.
Conflict resolution

„ Rule 1:
IF the ‘traffic light’ is green
THEN the action is go
„ Rule 2:
IF the ‘traffic light’ is red
THEN the action is stop
„ Rule 3:
IF the ‘traffic light’ is red
THEN the action is go
„ A method for choosing a rule to fire when more than one rule
can be fired in a given cycle is called conflict resolution.
Conflict Resolution

„ In forward chaining, BOTH rules would be fired.


„ Rule 2 is fired first as the topmost one, and as a
result, its THEN part is executed and linguistic
object action obtains value stop.
„ However, Rule 3 is also fired because the
condition part of this rule matches the fact ‘traffic
light’ is red, which is still in the database. As a
consequence, object action takes new value go.
Conflict Resolution Methods

y Fire the rule with the highest priority.


y Fire the Most Specific Rule. (Longest
Matching Strategy). Based on the assumption
that a specific rule processes more information
than a general one.
„ Fire the rule that uses the Data Most Recently
Entered in the database.
THERMOSTAT:

A demonstration Rule Based Expert System

To illustrate some of the ideas discussed above, we next consider a


simple rule based expert system. The LEONARDO Expert
system shell was selected as the tool to build a decision support
system called THERMOSTAT.

The system provides advice on how to select the thermostat setting


based on the season of the year, the day of the week and the time
of day. Note that this example reflects seasons in Australia, where
January, February and December are summer months.
THERMOSTAT :

A demonstration Rule Based Expert System

Knowledge Base
/* THERMOSTAT: A demonstration Rule-Base Expert System

Rule : 1
If the day is Monday
Or the day is Tuesday
Or the day is Wednesday
Or the day is Thursday
Or the day is Friday
Then today is a workday

Rule : 2
If the day is Saturday
Or the day is Sunday
Then today is the weekend
THERMOSTAT :

A demonstration Rule Based Expert System

Rule : 3
If today is a workday
And the time is ‘between 9 am and 5 pm’
Then operation is ‘during business hours’
Rule : 4
If today is a workday
And the time is ‘before 9 am’
Then operation is ‘not during business hours’
Rule : 5
If today is a workday
And the time is ‘after 5 am’
Then operation is ‘not during business hours’
Rule : 6
If today is the weekend
Then operation is ‘not during business hours’
THERMOSTAT :

A demonstration Rule Based Expert System


Rule : 7
If the month is January
Or the month is February
Or the month is December
Then the season is summer

Rule : 8
If the month is March
Or the month is April
Or the month is May
Then the season is autumn

Rule : 9
If the month is June
Or the month is July
Or the month is August
Then the season is winter
THERMOSTAT :

A demonstration Rule Based Expert System


Rule : 10
If the month is September
Or the month is October
Or the month is November
Then the season is spring

Rule : 11
If the season is spring
And operation is ‘during business hours’
Then thermostat_setting is ’20 degrees’

Rule : 12
If the season is spring
And operation is ‘not during business hours’
Then thermostat_setting is ’15 degrees’
THERMOSTAT :

A demonstration Rule Based Expert System


Rule : 13
If the season is summer
And operation is ‘during business hours’
Then thermostat_setting is ’24 degrees’
Rule : 14
If the season is summer
And operation is ‘not during business hours’
Then thermostat_setting is ’27 degrees’
Rule : 15
If the season is autumn
And operation is ‘during business hours’
Then thermostat_setting is ’20 degrees’
Rule : 16
If the season is autumn
And operation is ‘not during business hours’
Then thermostat_setting is ’16 degrees’
THERMOSTAT :

A demonstration Rule Based Expert System

Rule : 17
If the season is winter
And operation is ‘during business hours’
Then thermostat_setting is ’18 degrees’

Rule : 18
If the season is winter
And operation is ‘not during business hours’
Then thermostat_setting is ’14 degrees’

/* The SEK directive sets up the goal of the rule set


THERMOSTAT :

A demonstration Rule Based Expert System

Objects

THERMOSTAT uses seven linguistic objects: Month, day, time, today,


operation, season and the thermostat setting.

Each object can take one of the allowed values (for example, object month can
take the value of January, February, March, April, May, June, July, August,
September, October, November or December).

An object and its value constitute a fact (for instance, the month is January, the
day is Monday, the time is ‘after 5 pm’). All facts are placed in the database.
THERMOSTAT :

A demonstration Rule Based Expert System

Object Allowed Values Object Allowed Values

Month January, February, March, Day Monday, Tuesday, Wednesday,


April, May, June, July, Thursday, Friday, Saturday,
August, September, October, Sunday
November, December

Season Summer, Autumn, Winter, Operation During business hours, not


Spring during business hours
THERMOSTAT :

A demonstration Rule Based Expert System

Options

The final goal of the rule based expert system is to produce a solution to the
problem based on input data. In THERMOSTAT, the solution is a temperature
selected from the list of eight options:

Thermostat_setting is ’20 degrees’


Thermostat_setting is ’15 degrees’
Thermostat_setting is ’24 degrees’
Thermostat_setting is ’27 degrees’
Thermostat_setting is ’20 degrees’
Thermostat_setting is ’16 degrees’
Thermostat_setting is ’18 degrees’
Thermostat_setting is ’14 degrees’
THERMOSTAT :

A demonstration Rule Based Expert System

Dialogues

In the dialogue shown below, the expert system asks the user to input data
necessary to solve the problem (the season of the year, the day of the week and the time of
the day). Based on the answers supplied by the user (answers are indicated by arrows), the
expert system applies rules from its knowledge base to infer that the season is winter
(august is winter in Australia), the day is a workday and the operation is during business
hours. Rule 17 then selects one of the allowed values of the thermostat_setting.

What month is it ?
ÎAugust

Rule : 9
If the month is June
Or the month is July
Or the month is August
Then the season is winter
THERMOSTAT : A demonstration Rule Based Expert System

What day is it ?
ÎFriday

Rule : 1
If the day is Monday
Or the day is Tuesday
Or the day is Wednesday
Or the day is Thursday
Or the day is Friday
Then today is a workday

What time is it ?
Îbetween 9 am and 5 pm

Rule : 3
If today is a workday
And the time is ‘between 9 am and 5 pm’
Then operation is ‘during business hours’
THERMOSTAT :

A demonstration Rule Based Expert System

Rule: 17
If the season is winter
And operation is ‘during business hours’
Then thermostat_setting is ’18 degrees’

Inference Engine

The standard inference technique in Leonardo is


backward chaining with opportunistic forward chaining. It
provides the most efficient use of the available information.
However, Leonardo also provides an opportunity to turn off
backward or forward chaining, and thus to study both inference
techniques separately.
THERMOSTAT :

A demonstration Rule Based Expert System

Forward chaining is the data driven reasoning and thus we


need first to provide some data. Assume that

The month is August


‘month’ instantiated by user input to August

The day is Friday


‘day’ instantiated by user input to Friday

The time is ‘between 9am and 5 pm’


‘time’ instantiated by user input to ‘between 9 am and 5
pm’
THERMOSTAT :

A demonstration Rule Based Expert System

The following process will then happen:

Rule : 1 fires ‘today’ instantiated by Rule: 1 to ‘workday’


Rule : 3 fires ‘operation’ instantiated by rule: 3 to ‘during
business hours’
Rule : 9 fires ‘season’ instantiated by rule: 9 to ‘winter’
Rule : 17 fires ‘thermostat_setting’ instantiated by
Rule : 17 to ’18 degrees’
No rules fire stop
THERMOSTAT :

A demonstration Rule Based Expert System

Backward chaining is goal driven reasoning, so we need first to establish a


hypothetical solution (the goal). Let us, for example, set up the following goal:

‘Termostat_setting’ is ’18 degrees’

Pass 1
Trying Rule: 17 Need to find object ‘season’
Rule: 17 stacked Object ‘season’ sought as ‘winter’

Pass 2
Trying Rule: 9 Need to find object ‘month’
Rule: 9 stacked Object ‘month’ sought as ‘June’

Ask month
Î August ‘month’ instantiated by user input to August
THERMOSTAT :

A demonstration Rule Based Expert System

Trying Rule: 9 ‘Season’ instantiated by rule: 9 to ‘winter’

Pass 3
Trying Rule: 17 Need to find object ‘operation’
Rule: 17 stacked Object ‘operation’ sought as ‘during business hours’

Pass 4
Trying Rule: 3 Need to find object ‘today’
Rule: 3 stacked Object ‘today’ sought as ‘workday’

Pass 5
Trying Rule: 1 Need to find object ‘day’
Rule: 1 stacked Object ‘day’ sought as ‘monday’

Ask day
Î Friday ‘Day’ instantiated by user input to Friday
THERMOSTAT :

A demonstration Rule Based Expert System

Trying Rule: 1 ‘today’ instantiated by rule: 1 to ‘workday’

Pass 6
Trying Rule: 3 Need to find object ‘time’
Rule: 3 stacked Object ‘time’ sought as ‘’between 9 am and 5 pm’

Ask time
ÎBetween 9 am and 5 pm‘time’ instantiated to between 9 am and 5 pm’

Trying rule: 3 ‘operation’ instantiated to ‘during business hours’

Pass 7
Trying Rule: 17 ‘Thermostat_setting’ instantiated to ’18 degress’

You might also like