Week2 3 Intro Rule Based Systems
Week2 3 Intro Rule Based Systems
Expert
Systems
• Introduction
• Main components
• Inference mechanisms
Expertise
Knowledge Base
Facts / Information
Inference Engine
Expertise
8 Copyright
(C)
2022 by
Structure of a Rule-Based System
1. study good_grade
2. not_study bad_grade
3. sun_shines go_out
4. go_out not_study
5. stay_home study
6. bad_weather stay_home
INFERENCE
WORKING ENGINE
MEMORY
PATTERN EXECUTION
MATCHER ENGINE
RULE
BASE
AGENDA
working memory
select modify
Knowledge interpreter
base fire output
New information
working memory
select modify
Knowledge interpreter
base fire output
18
(C) Copyright 2022 by Prof.Abeer El-Korany
Reasoning with production rules(cont.)
Architecture of a typical production
system:
New information
Knowledge interpreter
base fire output
19
(C) Copyright 2022 by Prof.Abeer El-Korany
Reasoning with production rules(cont.)
Architecture of a typical production
system:
New information
working memory
select
modify
Interpreter
Knowledge executes
base fire actions
output
20
(C) Copyright 2022 by Prof.Abeer El-Korany
Reasoning with production rules(cont.)
working memory
select modify
Interpreter
Knowledge executes
base fire actions output
21
(C) Copyright 2022 by Prof.Abeer El-Korany
Inference Engine Cycle
• Describes the execution of rules by the inference engine
– match
• Find rules whose antecedents are satisfied
• Add them to agenda
– conflict resolution
• select the rule with the highest priority from the agenda
– execution
• perform the actions on the consequent of the selected rule
• Update the agenda (remove the fired rule from the agenda and add others)
• The cycle ends when no more rules are on the agenda, or when
an explicit stop command is encountered
25 Copyright
(C)
2022 by
Forward chaining Example
• Consider the simple fire example
R1: IF hot AND smoky THEN there is a fire
R2: IF alarm_beeps THEN smoky
R3 IF there is a fire THEN switch_on_sprinklers
26 Copyright
(C)
2022 by
Forward chaining Example (cont.)
• Second cycle:
– Find all rules with conditions satisfied : R1
– Choose one and apply action: there is a fire
. Working memory
alarm_beeps .1
Hot .2
Third cycle Smoky .3
Rules with conditions satisfied:there
R3 is a fire. .4
apply action: switch_on_sprinklers
27 Copyright
(C)
2022 by
Forward chaining
• Facts are held in a working memory
• Matches the antecedents of available rules with the current state until it
finds a rule all of whose antecedents are satisfied
28 Copyright
(C)
2022 by
Forward Chaining Inferencing
(cont.)
1. Scan the rules looking for ones whose
premises match the contents of the working
memory.
2. Fire the rule which was found.
3. Place its conclusion in the working memory.
4. Until no additional rule fire, go to 1.
29 Copyright
(C)
2022 by
Inference Network Representation
• We can represent forward chaining with rules as a network:
has hair
is a mammal
eats meat
is a carnivore
tawny color
is a tiger
black stripes
has a tail
32 Copyright
(C)
2022 by
Backward Chaining Example (cont.)
• Set conditions as new goals: G3: hot, G4: smoky.
• G3: hot, G4: smoky
• Third cycle:
– Try to prove G3: hot. In initial facts.
– Try to prove G4: smoky. Conclusion of rule R2
• Fourth cycle:
• G5: alarm_beeps.
– In initial facts, so all done…
– Proved hypothesis switch_on_sprinklers.
33 Copyright
(C)
2022 by
Forward &Backward Chaining
Example (Cont.)
• A forward chaining system would note first that it
knew A and B and could therefore conclude C–
then that it knew B and C and could then conclude
D– finally note that fortuitously, D was what it
wanted to prove
34 Copyright
(C)
2022 by
• Example
An expert system used to make classification between Ostrich and
Duck have the following rules: -
R1: IF have wing = yes and mammel = yes THEN bird = yes
R2: IF bird = yes and neck length = long THEN can-fly = no
R3: IF bird = yes and leg length = small THEN can-fly = no
R4: IF can-fly = no and leg length = small and neck length = small
THEN Duck = yes , Ostrich = no
R5: IF can-fly = no and leg length = long and neck length = long
THEN Duck = no , Ostrich = yes
Reasoning tree
starter-motor battery-or-cables spark-plugs
not
not
not
44 Copyright
(C)
2022 by
Simple Medical Expert System
• User interaction
– Patient: I have a headache
– System: I suggest you take a pain killer. Do you have a sore
throat?
– Patient: Yes, I do.
– System: Have you been coughing?
– Patient: No,
– System: Have you been feeling tired recently?
– Patient: Yes, I have.
– System: It sounds as though you may have glandular fever or
tonsillitis.
45 Copyright
(C)
2022 by
Forward vs. Backward Chaining
Forward Chaining Backward Chaining