Rule-Based Reasoning

Download Report

Transcript Rule-Based Reasoning

Rule-Based Reasoning
Introduction
UBI 517 Expert Systems
1
Introduction

Rule based systems are going to be
discussed with respect to


the structure of rules,
the two inference methods,
• Forward and backward reasoning

the two basic architectures used to organize
rules and perform inferencing.
• inference networks
• pattern matching
UBI 517 Expert Systems
2
What are Rules?



Rules represent knowledge using IF-THEN
format
The IF portion of a rule is a condition,
(also called a premise or an antecedent),
which tests the truth value of set of facts.
If these are found true, the THEN portion
of a rule (also called the action, the
conclusion or the consequent) is inferred
as a new set of facts.
UBI 517 Expert Systems
3
Production Systems and the Rules



The rule based systems are also called
production systems.
Simon and Newel developed the production
system to model human problem solving.
A production system consists of:



An area of memory that is used to track the current
state of the universe under consideration (working
memory - database).
A set of production rules :condition - action pairs
(knowledge base).
An interpreter (inference engine) recognizes and
executes a production whose conditions has been
satisfied. This control may be either data driven or goal
driven.
UBI 517 Expert Systems
4
Rule-based Inference



Using search techniques and pattern
matching, rule based systems automate
reasoning methods and provide the logical
progression from initial data to the desired
conclusion.
Thus the process of problem solving in
knowledge based systems is to create a series of
inferences that create a “path” between the
problem definition and the solution
This series of inferences is progressive in nature
and is called an inference chain.
UBI 517 Expert Systems
5
Example

Suppose we are building a knowledge
based system for forecasting the weather
over the next 12 – 24 hours in Florida
during the summer.
RULE 1:
IF
the ambient temperature is above 900F
THEN the weather is hot.
RULE 2:
IF
the relative humidity is greater than 65%
THEN the atmosphere is humid
RULE 3:
IF
the weather is hot and the atmosphere is humid
THEN thunderstorms are likely to develop.
UBI 517 Expert Systems
6



Assume the following facts are true:
The ambient temperature is 920F
The relative humidity is 70%
Rules 1 and 2 are fired and the following new
facts are deduced
The atmosphere is humid
The weather is hot
Which satisfy the premises of the rule 3, causing
a new fact to be derived:
Thunderstorms are likely to develop.
UBI 517 Expert Systems
7


A single rule could have been written to
reach the same conclusion:
Rule 1-A:
IF
the ambient temperature is above
900 F and
the atmospheric relative humidity
> 65%
THEN thunderstorms are likely to develop
There may be other rules that use the facts “The weather
is hot.” and “The atmosphere is humid.”
UBI 517 Expert Systems
8


Rule based systems differ from logic in
the following major ideas:
1. They are generally non-monotonic
2. They accept uncertainty in the deductive
process.
Non-monotonic reasoning is the concept by
which derived facts can be retracted when they
are no longer true.
UBI 517 Expert Systems
9
The reasoning Process

There are two means of progressing
toward conclusions:
1.
2.
Start with all the known data and progress to
the conclusion (data driven or forward
chaining)
Select a possible conclusion and prove its
validity by looking for supportive evidence
(goal driven or backward chaining).
UBI 517 Expert Systems
10
Example


Suppose we have a task of identifying
different varieties of fruit.
Knowledge used in identification of fruits
can be described through a set of rules.
UBI 517 Expert Systems
11
R01:IF shape = long and
color = green or yellow
THEN fruit = banana
R02:IF shape = round or oblong and
diameter > 4 inches
THEN fruitclass = vine
R03:IF shape = round and
diameter < 4 inches
THEN fruitclass = tree
R04:IF seedcount = 1
THEN seedclass = stonefruit
R05:IF seedcount > 1
THEN seedclass = multiple
R08:IF fruitclass = vine and
surface = rough and
color = tan
THEN fruit = cantolope
R09:IF fruitclass = tree and
color = orange and
seedclass = stonefruit
THEN fruit = apricot
R10:IF fruitclass = tree and
color = orange and
seedclass = multiple
THEN fruit = orange
R06:IF fruitclass = vine and
color = green
THEN fruit=watermelon
R11:IF fruitclass = tree
color = red and
seedclass = stonefruit
THEN fruit = cherry
R07:IF fruitclass = vine and
surface = smooth and
color = yellow
THEN fruit = honeydew
R12:IF fruitclass = tree and
color = orange and
seedclass = stonefruit
THEN fruit = peach
UBI 517 Expert Systems
12
R13:IF fruitclass = tree and
color = red or yellow or
green and
seedclass = multiple
THEN fruit = apple


R14:IF fruitclass = tree and
color = purple and
seedclass = stonefruit
THEN fruit = plum
The knowledge expressed
in rules can be pictorially
represented by a graph
The graphical format
clearly details the
connections that exist
between the rules via the
parameters.



AND parameters
OR parameters
Intermediate parameters
Generally these facts can
be derived through the
application of some rules
rather than being
requested directly from
UBI 517 Expertthe
Systems
user.

13
Graphical Representation
UBI 517 Expert Systems
14
Data driven reasoning vs goal driven
reasoning

Data driven reasoning is ideally suitable
for problem domains involving synthesis
such as design, configuration, planning,
scheduling.


In these cases many but equally acceptable
solutions exist.
Goal driven reasoning is ideally suited for
diagnostic problems.

In these cases there are small number of
conclusions that can be drawn.
UBI 517 Expert Systems
15
Conflict Resolution

The patterns in working memory are matched against
the conditions of the production rules this produces a
subset of the productions called the conflict set whose
conditions match the patterns in working memory. One
of the productions in the conflict set is then selected
(conflict resolution) and the production is fired. That
is, the action of the rule is performed changing the
contents of working memory. After the selected
production rule is fired the control cycle repeats with the
modified working memory. The process terminates
when no rule conditions are matched by the contents of
working memory.
UBI 517 Expert Systems
16
Forward Reasoning Inference Process
New rules
Knowledge
Rules
Step1:
Match
Applicable
rules
Ste2:
Conflict Resolution
Selected
rules
Step3:
Execution
Facts
Facts
New Facts
UBI 517 Expert Systems
17
Forward Reasoning

Rule interpretation in forward reasoning
involves the repetition of the basic steps:
1.
Matching: Find all rules whose premises are true and
mark them as being applicable
2.
Conflict Resolution: If more than one rule applies then
select the rule with the highest priority (those whose
premises have been satisfied).
3.
Action: Execute the action of the lowest numbered
applicable rule. If none applies then halt.
4.
Reset: Reset the applicability of all rules and return to
step 1.
UBI 517 Expert Systems
18
Example

Assume the database contains the following
facts:




Diameter = 1 inch
Shape = round
Seedcount = 1
Color = red
UBI 517 Expert Systems
19
Trace of Rule Based Forward Reasoning
Execution Cycle
Applicable rules
Selected rules
Derived facts
1
3,4
3
Fruitclass = tree
2
3, 4
4
Seedclass = stonefruit
3
3, 4, 11
11
Fruit = cherry
4
3, 4, 11
-
-
UBI 517 Expert Systems
20
Backward Reasoning




Backward reasoning corresponds very closely to
depth first search.
The system starts with an empty database of
known facts.
A list of goals (or conclusions) is provided for
which the system attempts to derive values.
For fruit identification problem initially:


Known fact Base: ( )
Goals: (fruit)
UBI 517 Expert Systems
21
Steps in Backward Reasoning



Form a stack initially composed of all the top
level goals defined in the system.
Consider the first goal from the stack. Gather all
rules capable f satisfying this goal.
For each of these rules:
1.
2.
If all premises are satisfied, then execute this rule to
derive its conclusion. Remove this goal from the stack
and go to step to 2.
If any premise of a rule is not satisfied, look for rules
that derive the specified value for the parameter used
in this premise. If any can be found, consider it as a
subgoal and put it on top of the stack, return to step 2.
UBI 517 Expert Systems
22
Steps in Backward Reasoning
If step above can’t find a rule to derive the
specified value, then query the user for its
value and add it to the database. If the
premise is satisfied continue with the next
premise, if not consider the next rule.
If all rules that can satisfy the current goal
have been attempted and all have failed, then
this goal remains undetermined. Remove it
from the stack and return to step 2. If the
stack is empty, announce completion and halt.
3.

UBI 517 Expert Systems
23
Example- Fruit Identification Problem



Suppose that the fruit we are trying to
identify is cherry.
The top level goal: fruit
Step2: Gather all rules that can derive
this goal


Rules 1, 6, 7, 8, 9, 10, 11, 12, 13 and 14
Execution starts with rule1
UBI 517 Expert Systems
24
Example- Fruit Identification Problem
R1: IF
THEN
shape = long and
color = green or yellow
fruit = banana
There is no value for shape in database
The inference mechanism asks the user:
What is the value for shape?
We respond with a value of round which is added to
the database.
Known Fact Base: ( (shape = round) )
Based on closed-world assumption rule1 fails.
Execution proceeds torule6.
UBI 517 Expert Systems
25
Example- Fruit Identification Problem
R6: IF
THEN
fruitclass = vine and
color = green
fruit = watermelon
R2 and R3 are capable of deriving values for fruitclass.
Add this subgoal to the stack
Goals: ( (fruitclass)
(fruit) )
R2: IF shape = round and
diameter > 4 inches
THEN fruitclass = vine
R3: IF shape = round or oblong and
diameter < 4 inches
THEN fruitclass = tree
UBI 517 Expert Systems
26
Example- Fruit Identification Problem
Shape = round (from the database)
What is the value for the diameter? (queered)
Known Fact Base:
( (shape = round)
(diameter = 1)
R2 fails
R3 derives
(fruitclass = tree) )
UBI 517 Expert Systems
27
Example- Fruit Identification Problem

R7 and R8 fail
Fruitclass = vine
R9: IF
THEN
fruitclass = tree and
color = orange and
seedclass = stonefruit
fruit = apricot
What is the value for color?
Respond :red
R9 and R10 fail
UBI 517 Expert Systems
28
Example- Fruit Identification Problem
R11: IF
fruitclass = tree and
color = red and
seedclass = stonefruit
THEN
fruit = cherry
R4: IF
THEN
Seedclass= ?
seedcount = 1
seedclass = stonefruit
What is the value for seedcount?
Respond :1
UBI 517 Expert Systems
29
Example- Fruit Identification Problem



All premises of R11 are satisfied.
R11 is fired and cherry is concluded for the fruit.
Known Fact Base:
( ( shape = round)
( diameter = 1)
( fruitclass = tree)
( color = red)
( seedcount = 1)
( seedclass = stonefruit)
( fruit = cherry) )
UBI 517 Expert Systems
30
Rule Based Architectures

There are two basic structures to the
knowledge contained within a rule based
system:
1.
2.
inference networks and
pattern matching systems.
UBI 517 Expert Systems
31
Inference Networks



Inference network can be represented as
a graph in which the nodes represent the
parameters that are facts.
Each fact can serve as an antecedent or
consequent of a rule.
The rules are represented by the
interconnections between the various
nodes. This knowledge is used by the
inference process to propagate results
throughout the network.
UBI 517 Expert Systems
32
Sample Inference Networks
amb-temp
rel-hum
R1
R2
hum-cond
temp-cond
storm

All interconnections between the nodes are known prior to
execution


Searching to Match facts with premises is minimized
Implementation of the inference engine and explanation is
simplified
UBI 517 Expert Systems
33
Pattern Matching Systems




Pattern matching systems use extensive
searches to match and execute the rules,
deriving new facts.
Relationships between rules and facts are
formed at run-time based on the patterns that
match the facts.
A pattern matching system depends on matching
the premises of a rule to existing facts to
determine which rules have their premises
satisfied by the facts and can, therefore execute.
The premises of a rule are patterns. These
patterns are satisfied when a search through the
database of facts discovers any facts that match
UBI 517 Expert Systems
34
them.
Pattern Matching Systems
1.
2.
The typical features included within pattern
matching systems are classified as one of the
following five types:
Pattern connectives – AND, OR
Wildcard - ? $
Consider the following house example
(type color number_of_stories square_footage)
(contemporary brown 2 2835)
(contemporary ? ? ?sq_footage) ;;a contemporary
house with certain square footage, but don’t care
about its color or number of stories.
(contemporary $ ?sq_footage) ;; $ represents one
or more fields.
UBI 517 Expert Systems
35
Example
CLIPS>
(deftemplate person
(slot name)
(slot eyes)
(slot hair))
(defrule find-blue-eyes
(person (name ?name)
(eyes blue))
(printout t ?name " has
blue eyes." crlf))
(deffacts people
(person (name Jane)
(eyes blue) (hair red) )
(person (name Jack)
(eyes blue) (hair black) )
(person (name Jeff)
(eyes green) (hair brown) ) )
when run
Jack has blue eyes
Jane has blue eyes.
UBI 517 Expert Systems
36
Pattern Matching Systems
3.
Field constraints
(ranch ~red ? ?sq_footage)
(contemporary gray|white ? ?sq_footage)
4.
Mathematical operators
(defrule subtraction
(numbers ?x ?y)
(bind ?answer (- ?x ?y))
(fprintout t “the answer is “ ?answer crlf))
5.
Test feature
(if ((A = B) x y ))
UBI 517 Expert Systems
37
Example
(defrule big-obj
(width ?obj ?w)
(length ?obj ?l)
(height ?obj ?h)
(or
(test (> ?w 50))
(test (> ?l 50))
(test (> ?h 50)))
(fprintout t ?obj “is large object.” crlf))
UBI 517 Expert Systems
38
Evaluation of the Architectures




Rule based systems that use pattern matchers
are flexible and powerful.
They are more applicable for domains where the
possible solutions are either unbound or large in
numbers, such as design, planning and
synthesis.
The use of search to find applicable rules makes
pattern matchers inefficient.
Some knowledge based systems (XCON) and
shells (OPS5, KEE, CLIPS) are based on pattern
matching architectures
UBI 517 Expert Systems
39
Evaluation of the Architectures




Inference networks are useful for domains
where the number of different alternative
solutions is limited (classification, diagnostic
type of problems).
Easier to implement
Less powerful because all the relations need to
be known beforehand.
Allow explanation of solution easily.
UBI 517 Expert Systems
40
Disadvantages of Rule Based Systems

Major problems with rule based systems
are:
1.
2.
3.
infinite chaining,
addition of new, contradictory knowledge,
modification of existing rules.
UBI 517 Expert Systems
41
Infinite Chaining

Results from the myth
“If the system does not work properly, all you
need to do is to add more rules.”
R23: IF
anemia-risk(?person)
THEN anemis-risk(son(?person))
R24: IF
anemia-risk(father(?person))
THEN anemia-risk(?person)
UBI 517 Expert Systems
42
Addition of New, Contradictory
Knowledge
In rule based systems it is possible to introduce new
knowledge to fix some problem in the knowledge base,
which in turn introduces a contradiction.
R107: IF
it is raining
THEN not(weather is sunny)

R109: IF
location is Florida
THEN not(weather is cloudy)
R24:
IF
time of day is late afternoon
THEN weather is sunny or Conclusion is that the
weather is cloudy
Weather is sunny.
FACTS:time of day is late afternoon
location is Florida
UBI 517 Expert Systems
43
Addition of New, Contradictory
Knowledge
R107: IF
it is raining
THEN not(weather is sunny)
R109: IF
location is Florida
THEN not(weather is cloudy)
R96:
IF
THEN
time of day is late afternoon
weather is sunny or
weather is cloudy
R120: IF
time of day is late afternoon and
location is Florida
THEN it is raining
FACTS:time of day is late afternoon
location is Florida
UBI 517 Expert Systems
44
Modifications to Existing Rules
R302: IF
organism = strep or
organism = gonorrhea
THEN prescription = penicillin
Some people are allergic to penicillin
R302: IF
organism = strep or
organism = gonorrhea
THEN indicated-drug = penicillin
R342: IF
indicated-drug = penicillin and
unknown(allergy-to = penicillin)
THEN ask(allergy-to = penicillin)
R367: IF
indicated-drug = penicillin and
not (allergy-to = penicillin)
UBI 517 Expert Systems
THEN prescription = penicillin
45
Modifications to Existing Rules

Patients may be allergic to other drugs.
R342 and R367 can be generalized as
follows
R342: IF
indicated-drug = ?drug and
unknown(allergy-to = ?drug)
THEN ask(allergy-to = ?drug)
R367: IF
indicated-drug = ?drug and
not (allergy-to = ?drug)
THEN prescription = ?drug
UBI 517 Expert Systems
46
Disadvantages
1.
Additional disadvantages of rule based systems
are:
Inefficiency
During every cycle of inference mechanism each rule is
examined to see whether it applies to the current situation
2.
Opacity
It is very difficult to examine a developed knowledge
base and determine what actions are going to occur
when.
3.
Coverage of domain
Some domains contain numerous variations of inputs
which require the storage of tens of thousands of
rules.
UBI 517 Expert Systems
47
Advantages of Rule Based Systems
Significant advantages of rule based systems are:
1.
2.
Separation of knowledge and control
Modularity
Each rule is a distinct separate unit of knowledge that
can be added, modified or removed independent of the
other rules that are present in the knowledge base.
3.
Uniformity
All knowledge in the system is expressed in exactly the
same format.
4.
Naturalness
Rules are a natural format for expressing knowledge
UBI 517 Expert Systems
48