Details of Rule Based Reasoning - PowerPoint PPT Presentation

1 / 73
About This Presentation
Title:

Details of Rule Based Reasoning

Description:

Details of Rule Based Reasoning Chapter 5 The Engineering of Knowledge Based Systems – PowerPoint PPT presentation

Number of Views:185
Avg rating:3.0/5.0
Slides: 74
Provided by: UBE82
Category:

less

Transcript and Presenter's Notes

Title: Details of Rule Based Reasoning


1
Details of Rule Based Reasoning
  • Chapter 5
  • The Engineering of Knowledge Based Systems

2
Introduction
  • Traditionally pattern matching systems have been
    associated with forward reasoning while backward
    reasoning systems typically have been implemented
    as inference networks.
  • This chapter presents examples to forward and
    backward reasoning and examines how these systems
    can be implemented.

3
Forward Reasoning
  • Forward reasoning is the process of working from
    a set of data to toward the conclusions that can
    be drawn from this data.
  • A rule is eligible for execution when its
    premises are satisfied.

4
Forward Reasoning
  • Monitoring and diagnosing real-time process
    control systems where data are continuously being
    acquired, modified and updated are suitable for
    forward reasoning.
  • Other suitable applications can be listed as
  • design
  • planning
  • scheduling
  • The important characteristics of these
    applications are
  • The need for a quick response to changes in data
  • Few predetermined relations existing between the
    input data and the conclusion drawn.

5
Forward Reasoning
  • Implemented as Pattern matching
  • Where synthesis of new facts based on the rules
    conclusions occurs.
  • In these applications there are many potential
    solutions that can be derived from the input
    data. The rules express knowledge as general
    patterns and the precise connections (inference
    chain) between these rules can not be
    predetermined.
  • As a result these systems use forward reasoning
    pattern matching systems due to the implicit
    flexibility of the pattern matching approach.

6
Example 1 of Forward Reasoning
  • Problem Statement.
  • It is discovered that the retirement village is
    under the threat of flooding of Suwannee River.
    An expert system to give alert when a flood
    warning or evacuation order should be given is
    required to be developed.
  • 10 rules and 18 parameters are set to solve this
    problem

7
Example 1 of Forward Reasoning
  • Parameters
  • month any month of the year
  • upstream precipitation none, light, heavy
  • weather forecast sunny, cloudy, stormy
  • river height measurement in feet
  • season dry, wet
  • local rain none, light rain, heavy rain
  • river change none, lower, higher
  • flood warning yes, no
  • evacuation order yes, no

8
Example 1 of Forward Reasoning
  • R1 IF month may oct THEN season wet
  • R2 IF month nov april THEN season dry
  • R3 IF upstream none AND season dry
    THEN change lower
  • R4 IF upstream none AND season wet
    THEN change none
  • R5 IF upstream light THEN change none

R6 IF upstream heavy THEN change
higher R7 IF level low THEN
flood no AND evac no R8 IF change none
lower AND level normal low THEN
flood no AND evac no R9 IF change
higher AND level normal AND
rain heavy THEN flood yes (CF
0.4) AND evac no
9
Example 1 of Forward Reasoning
  • R10 IF change higher AND level normal AND
    rain light THEN flood
    no AND evac no
  • R11 IF change higher AND level high AND
    rain none light THEN flood
    yes (CF0.5) AND evac yes (CF0.2)
  • R12 IF change higher AND level high AND
    rain heavy THEN flood
    yes AND evac yes (CF0.8)

R13 IF heigt lt10 THEN level
low R14 IF heiht gt10 AND lt16 THEN level
normal R15 IF height gt 16 THEN level
high R16 IF forecast sunny THEN rain
none R17 IF forecast cloudy THEN rain
light R18 IF forecast stormy THEN rain heavy
10
Inference Network
Final conclusions
Intermediate conclusions
Input parameters
11
  • The data used by this system can be gathered from
    a set of sensors, requiring no interaction with
    the users of the system.
  • The system must continually monitor the data
    collected by the sensors to determine if a
    warning should be given.

12
Implementation
  • Because all the relations are predetermined an
    internal representation that exploits this
    explicitness is used. This internal
    representation details for each rule
  • The rule number
  • Parameters used within the premises of the rule
    (called upstream elements)
  • Parameters used within the conclusions of the
    rule (called downstream elements)
  • The set of premises
  • The set of conclusions

13
Implementation
  • and for each parameter
  • The name of the parameter
  • A list of rules that derive a value for this
    parameter (called set-by)
  • A list of rules that use this parameter in their
    premises (called premise-for)
  • The value(s) of this parameter (and their
    associated confidence factors) if known

14
Implementation
  • For example, rule R1 and parameter change are
    described internally as
  • Rule R1
  • Upstream-elements month
  • Downstream-elements season
  • Premises month may oct
  • Conclusions season wet

15
Implementation
  • Parameter change
  • Set-by (R3 R4 R5 R6)
  • Premise-for (R8 R9 R10 R11 R12)
  • Values -
  • Two additional lists (input data and conclusions)
    are needed for this approach
  • Input data (month upstream forecast height)
  • Conclusions (flood evac)

16
Implementation
  • Because all the interconnections among the rules
    can be stated explicitly, it is easy to determine
    what actions to take whenever some parameters
    are obtained.
  • The algorithm is basic breadth first search
    technique.

17
Forward Reasoning Inference Network Algorithm
  • Assign values to all input nodes from the
    external sources providing information to the
    knowledge-based system.
  • Form a que containing rules that use the values
    of these input nodes in their premises.
  • Until there are no more rules in Q
  • Examine the first rule in Q, comparing its
    premises with the values of the appropriate
    parameters to decide if the premises of the rules
    are satisfied.
  • If the premises of the rule are not satisfied,
    remove the rule from Q, and go back to a.
  • If the rule is matched
  • Execute the rule, setting the rules downstream
    elements to the values specified by the rule.
  • Decide which rules use the downstream elements
    just set within their premises,
  • Add these rules as the last rules within Q if
    they are not already in Q, even if their
    premises are not fully satisfied.
  • Delete the original rule from the front of the Q,
    and return to step a.
  • Output the values of the hypotheses that have
    been identified as conclusion.
  • If this application involves a real time process
    control, go back to step 1 and start the process
    again.

18
Demonstration of the approach
  • Assume that the following values are obtained
  • month may
  • upstream light
  • forecast cloudy
  • height 15
  • Step 2 requires that we build a queue of rules
  • Q ( R1 R2 R3 R4 R5 R6 R13 R 14 R15 R16 R17 R18)

19
Demonstration of the approach
  • R1 is examined to see if its premises are
    satisfied. month may is satisfied. New
    conclusion season wet is derived.
  • Rules with season premise are R3 and R4 which
    are already in the queue.
  • R1 is removed from the queue
  • R2 is tried. Fails (month nov)
  • R3 R4 also fail

20
Demonstration of the approach
  • R5 is tried. Its premise is satisfied deriving
  • change none
  • The value of the parameter change is used by
  • (R8, R9, R10, R11, and R12).
  • Q becomes
  • Q (R6 R13 R 14 R15 R16 R17 R18 R8 R9 R10 R11
    R12)

21
Demonstration of the approach
  • The known facts are
  • month may
  • upstream light
  • forecast cloudy
  • height 15
  • season wet
  • change none

22
Demonstration of the approach
  • This process continues until Q is empty. At this
    time our database of known facts become
  • month may
  • upstream light
  • forecast cloudy
  • height 15
  • season wet
  • change none
  • level normal
  • rain light
  • flood no
  • evac no

23
Demonstration of the approach
  • If this is a real time application, the system
    repeats the process with new set of acquired
    input parameters.
  • Forward chaining systems implemented as inference
    networks are very good for applications involving
    monitoring and diagnosing real-time process
    control systems where data are continually being
    acquired, modified and updated automatically.

24
Example 2 of Forward Reasoning
  • Statement of the problem
  • Suppose that John is changing apartments and
    needs packing. Some items are much heavier than
    others, some occupy larger space, some are
    fragile and some are malleable.
  • John wants to ensure that all the items survive
    the move unbroken and is not interested in
    finding the optimal scheme for packing all the
    items.

25
Items to be Packed by the Boxer System
ITEM COUNT WEIGHT SIZE FRAGILE PLIABLE
Books 7 heavy 2 no no
Lamp 2 medium 8 yes no
Dishes 1 set medium 5 yes no
Coat 2 light 3 no yes
VCR 1 medium 4 no no
TV 1 heavy 10 yes no
Glasses 1 set medium 4 yes no
Jeans 4 light 2 no yes
Shirts 8 light 1 no yes
26
Boxer System
  • This problem is one of synthesis, since there are
    many possible combinations to use in packing.
  • The process also requires a pattern matcher,
    since the objects and the boxes can be described
    by a list of values that detail the objects
    (boxs)properties.

27
Boxer System
  • John develops four primary steps in his BOXER
    system.
  • Box the fragile items first, taking care to pad
    each of these items.
  • Box the heavy weight items, ensuring that these
    items are not placed with the fragile ones.
  • Box the medium weight items, again ensuring that
    these items are not placed with the fragile ones.
  • Box the light weight items, putting them wherever
    there is room.
  • John has collected enough boxes all of the same
    size (10 space units).

28
Boxer System
  • R1 IF step is box-fragile items
  • there is a fragile item to box
  • there is an empty box or a box
  • containing only fragile items
  • the fragile item has not been padded
  • THEN pad the fragile item
  • R2 IF step is box-fragile items
  • there is a fragile item to box
  • there is an empty box or a box
  • containing only fragile items
  • the fragile item has been padded
  • the boxs free space gt the fragile items size
  • THEN put the fragile item in the box
  • decrease the boxs free space by the fragile
    items size

29
Boxer System
  • R3 IF step is box-fragile items
  • there is a fragile item to box
  • THEN start a fresh box
  • R4 IF step is box-fragile items
  • THEN discontinue box fragile items start box
    heavy items

30
Boxer System
  • R5 IF step is box-heavy-items
  • there is a heavy item
    there is an empty box or a box that does not
  • contain fragile items or a box that
    contains lt4 heavy items
  • the boxs free space gt the items size
    THEN put the heavy item in the box
    decrease the boxs free space by the heavy
    items size
  • R6 IF step is box-heavy-items
  • there is a heavy item THEN start a fresh
    box
  • R7 IF step is box-heavy items
  • THEN discontinue box-heavy-items start
    box-medium-items

31
Boxer System
  • R8 IF step is box-medium-items
  • there is a medium item
    there is an empty box or a box that does not
  • contain fragile items or the boxs free
    space gt the medium items size THEN put the
    medium item in the box decrease the boxs
    free space by the medium items size
  • R9 IF step is box-medium-items
  • there is a medium item THEN start a fresh
    box
  • R10 IF step is box-medium items
  • THEN discontinue box-medium-items start
    box-light-items

32
Boxer System
  • R11 IF step is box-light-items
  • there is a light item
    there is a box whose free space gt the light
    items size THEN put the light item in the box
    decrease the boxs free space by the light
    items size
  • R12 IF step is box-light-items
  • there is a light item THEN start a fresh
    box
  • R13 IF step is box-light items
  • THEN discontinue box-light-items halt

33
Boxer System
  • Important characteristics of these rules are
  • Each rule checks the currently active processing
    step.
  • By keeping track of the steps the system
    subdivides knowledge into smaller groups.
  • Only when all the objects of a certain group have
    been processed the system moves on to the next
    group.
  • The premises of some rules within subgroups are
    also premises of other rules. This means some
    conflict resolution must be employed to determine
    which actual rule to be executed.

34
Boxer System Conflict Resolution
  • The selection is based on two ordered criteria
  • Always select the rule instantiated with the
    largest number of premises
  • Should multiple instantiations still exist,
    select the rule instantiated with the data
    closest to the top of the database.

35
Boxer System Conflict Resolution
State Box fragile items State Box fragile items State Box fragile items State Box fragile items State Box fragile items State Box fragile items
Unboxed Items Number Weight Size Fragile? Pliable?
Book 1 heavy 2 no no
Book 2 heavy 2 No no
Lamp 1 medium 8 yes no
Dishes 1 medium 5 yes no
Coat 1 light 3 no yes
TV 1 heavy 10 yes no
pants 1 light 2 no yes
pants 2 light 2 no yes
Shirt 1 light 1 no Yes
Shirt 2 light 1 no Yes
Box Number Contains Contains Contains Free Space Free Space
36
Boxer System Conflict Resolution
  • The system starts with box-fragile-items.
  • R3 and R4 are instantiated.
  • R3 has the larger number of premises and three
    instantiations (lamp, dishes, TV)
  • R3 for lamp 1
  • R3 for dishes 1
  • R3 for TV 1
  • R4

37
State Box fragile items State Box fragile items State Box fragile items State Box fragile items State Box fragile items State Box fragile items
Unboxed Items Number Weight Size Fragile? Pliable?
Book 1 heavy 2 no no
Book 2 heavy 2 No no
Lamp 1 medium 8 yes no
Dishes 1 medium 5 yes no
Coat 1 light 3 no yes
TV 1 heavy 10 yes no
pants 1 light 2 no yes
pants 2 light 2 no yes
Shirt 1 light 1 no Yes
Shirt 2 light 1 no Yes
Box Number 1 Contains - Contains - Contains - Free Space 10 Free Space 10
Database after execution of R3 with Lamp 1
38
Boxer System Conflict Resolution
  • R1 for lamp 1 and box 1
  • R1 for dishes 1 and box 1
  • R1 for TV 1 1 and box 1
  • R3 for lamp 1
  • R3 for dishes 1
  • R3 for TV 1
  • R4

39
State Box fragile items State Box fragile items State Box fragile items State Box fragile items State Box fragile items State Box fragile items
Unboxed Items Number Weight Size Fragile? Pliable?
Book 1 heavy 2 no no
Book 2 heavy 2 No no
Lamp(padded) 1 medium 8 yes no
Dishes 1 medium 5 yes no
Coat 1 light 3 no yes
TV 1 heavy 10 yes no
pants 1 light 2 no yes
pants 2 light 2 no yes
Shirt 1 light 1 no Yes
Shirt 2 light 1 no Yes
Box Number 1 Contains - Contains - Contains - Free Space 10 Free Space 10
Database after execution of R1 with Lamp 1 and
Box 1
40
Boxer System Conflict Resolution
  • R1 for dishes 1 and box 1
  • R1 for TV 1 1 and box 1
  • R2 for lamp 1 and box 1
  • R3 for dishes 1
  • R3 for TV 1
  • R4

41
State Box fragile items State Box fragile items State Box fragile items State Box fragile items State Box fragile items State Box fragile items
Unboxed Items Number Weight Size Fragile? Pliable?
Book 1 heavy 2 no no
Book 2 heavy 2 No no
Dishes 1 medium 5 yes no
Coat 1 light 3 no yes
TV 1 heavy 10 yes no
pants 1 light 2 no yes
pants 2 light 2 no yes
Shirt 1 light 1 no Yes
Shirt 2 light 1 no Yes
Box Number 1 Contains Lamp(padded) Contains Lamp(padded) Contains Lamp(padded) Free Space 2 Free Space 2
Database after execution of R2 for Lamp 1 and Box
1
42
State Box heavy items State Box heavy items State Box heavy items State Box heavy items State Box heavy items State Box heavy items
Unboxed Items Number Weight Size Fragile? Pliable?
Book 1 heavy 2 no no
Book 2 heavy 2 No no
Coat 1 light 3 no yes
pants 1 light 2 no yes
pants 2 light 2 no yes
Shirt 1 light 1 no Yes
Shirt 2 light 1 no Yes
Box Number 1 2 3 Contains Lamp(padded) 1 Dishes (padded) 1 TV (padded) 1 Contains Lamp(padded) 1 Dishes (padded) 1 TV (padded) 1 Contains Lamp(padded) 1 Dishes (padded) 1 TV (padded) 1 Free Space 2 5 0 Free Space 2 5 0
Database after Boxing all Fragile Items
43
State Box heavy items State Box heavy items State Box heavy items State Box heavy items State Box heavy items State Box heavy items
Unboxed Items Number Weight Size Fragile? Pliable?
Coat 1 light 3 no yes
pants 1 light 2 no yes
pants 2 light 2 no yes
Shirt 1 light 1 no Yes
Shirt 2 light 1 no Yes
Box Number 1 2 3 4 Contains Lamp(padded) 1 Dishes (padded) 1 TV (padded) 1 Book 1, Book2 Contains Lamp(padded) 1 Dishes (padded) 1 TV (padded) 1 Book 1, Book2 Contains Lamp(padded) 1 Dishes (padded) 1 TV (padded) 1 Book 1, Book2 Free Space 2 5 0 6 Free Space 2 5 0 6
Database after Boxing all Heavy Items
44
State Box light items State Box light items State Box light items State Box light items State Box light items State Box light items
Unboxed Items Number Weight Size Fragile? Pliable?
Box Number 1 2 3 4 Contains Lamp(padded) 1, Pants 1 Dishes (padded) 1, coat 1, pants 2 TV (padded) 1 Book 1, Book2, shirt 1, shirt 2 Contains Lamp(padded) 1, Pants 1 Dishes (padded) 1, coat 1, pants 2 TV (padded) 1 Book 1, Book2, shirt 1, shirt 2 Contains Lamp(padded) 1, Pants 1 Dishes (padded) 1, coat 1, pants 2 TV (padded) 1 Book 1, Book2, shirt 1, shirt 2 Free Space 0 0 0 4 Free Space 0 0 0 4
Database after Boxing all light Items
45
The Rete Algorithm
  • As seen in the example, a pattern matcher,
    forward reasoning system is extremely
    inefficient.
  • The match, conflict resolution, and execute cycle
    implies that all of the rules are compared to all
    of the facts in the fact base to decide which
    rules belong in the conflict set.
  • If we have
  • r rules in our knowledge base
  • f facts in our database
  • An average of p premises in each rule
  • we will perform rf p comparisons to our fact
    base on every cycle to determine which rules can
    be executed.

46
The Rete Algorithm
  • The rules that can potentially execute on any
    cycle change very little.
  • Rather than comparing rules to facts to see which
    rules are satisfied we should instead maintain a
    list of satisfied rules and determine how this
    satisfaction list changes due to the addition and
    deletion of facts.
  • This approach is exploited by the Rete Algorithm.

47
The Rete Algorithm
  • The Rete Algorithm involves the development of
    two networks
  • a pattern network and
  • join network.
  • Consider the following rule

TEST 1 IF ((cat ?c small ?h ?n1) (dog ?c ?q
medium ?n2) (cat ?c large ?h ?n3) (dog
?c ?q long ?n4) ) THEN ( . . . )
(animal-type color size hair-length name)
48
The pattern network consists of a set of trees
formed from all of the premises in all of the
rules
TEST 1 IF ((cat ?c small ?h ?n1) (dog ?c ?q
medium ?n2) (cat ?c large ?h ?n3)
(dog ?c ?q long ?n4) ) THEN ( . . . )
The root of each tree is the first item within
each premise pattern
49
The algorithm uses as much of the existing
network as possible.It only creates a new path
within the tree when the existing nodes do not
correspond with the new item from the premise
TEST 1 IF ((cat ?c small ?h ?n1) (dog ?c ?q
medium ?n2) (cat ?c large ?h ?n3)
(dog ?c ?q long ?n4) ) THEN ( . . .
50
The join network connects the various leaf nodes
of the trees together (in the order in which they
occur as clauses) and compares similarly named
values to ensure that they have the same values.
TEST 1 IF ((cat ?c small ?h ?n1) (dog ?c ?q
medium ?n2) (cat ?c large ?h ?n3)
(dog ?c ?q long ?n4) ) THEN ( . . .
The Complete Joint and Pattern Network
51
Rete Algorithm - Example
  • Consider the following database facts
  • (cat yellow large short rebel)
  • (cat calico large short rubble)
  • (cat calico small short kitty)
  • (dog brown medium long charlie)
  • (cat brown small medium prince)
  • (dog brown small short sam)
  • (dog calico medium medium butch)
  • (dog brown large medium star)
  • (dog calico medium long tramp)
  • Each of these facts is first parsed through the
    pattern network.
  • The 6th fact can not be completely parsed down
    the tree.

52
If similar patterns exist with several rules, the
algorithm reuses as much of the existing networks
as is possible.
Facts parsed through the pattern network
53
  • When a rule is executed, its actions can add,
    delete or modify facts on the fact list. Each of
    these actions changes the parsed and joined facts
    within the pattern and join networks. By merely
    updating these facts within the network, a
    forward reasoning system using the Rete Algorithm
    can quickly determine all rules that can execute.

54
Results of passing facts through the joint network
TEST 1 IF ((cat ?c small ?h ?n1) (dog ?c ?q
medium ?n2) (cat ?c large ?h ?n3)
(dog ?c ?q long ?n4) ) THEN ( . . .
55
Conflict Resolution Schemes
  • Conflict resolution schemes can be divided into
    four broad categories based on the following
    criteria
  • Number of rules to execute
  • Order of the rules
  • The lowest numbered rule
  • The first applicable rule following the last
    fired
  • Complexity of the rules
  • Refined rules (with many premises)
  • General rules (with few premises)
  • Order of the data
  • The rule that matches the oldest data
  • The rule that matches the newest data

56
Coding Forward Reasoning
  • Here, simple and concise routines implementing
    forward reasoning are presented.
  • These routines are more similar to the pattern
    matching algorithm because the relationships
    between the rules and the facts are not known
    beforehand.
  • Internal representation format for facts and
    rules are as follows

fact (is attribute value) (numeric-op
attribute value) numeric-op gt lt lt
gt data base (fact ) rule (name if
(fact ) then (fact )) knowledge base (rule
)
57
Coding Forward Reasoning
  • Forward reasoning consists of sequentially
    examining each rule in a knowledge base to find
    the first one capable of deriving new facts that
    are currently not known.
  • Every time such a rule is found it is executed
    immediately and the cycle starts again.
  • Because this code stops searching for a rule to
    execute when it encounters the first satisfied
    rule that has not executed yet, there is never
    more than one eligible rule on the agenda hence
    there is no need for conflict resolution.
  • Execution price paid in return is all rules must
    be examined on each rule execution cycle.

58
Coding Forward Reasoning
  • The Inference process is performed by the
    following five functions
  • forward initiates the forward reasoning process
  • execute-rule searches through the knowledge base
    looking for a rule that derives a new fact
  • eval-rule-f examines an individual rule if it
    executes (all premises are satisfied and calling
    derive-new-fact?)
  • derive-new-fact? examines the rules conclusions
    to see if there is a conclusion not in the
    database
  • display-results prints a message every time a new
    fact is derived.

59
Coding Forward Reasoning
  • forward initiates the forward reasoning process.
    It loops as long as new facts are being derived
    and returns T if any facts are derived.
  • ( defun forward ( )
  • ( let (derived-fact? )
  • (loop
  • (cond ( ( not (execute-rule) )
  • (return derived-fact?) )
  • (t (setq
    derived-fact? T) ) ) ) ) )

loop form Controls no variables, simply
executes its body repeatedly
60
Coding Forward Reasoning
  • execute-rule searches through the knowledge base
    looking for a rule that derives a new fact

(do ((var1 init_value (iteration_form))
var1 init_value (iteration_form var3 .) ((t
ermination test) value_to_be_returned) body)
( defun execute-rule ( ) ( do ( ( rules
rule-list (cdr rules) ) ) ( (null rules)
nil)
(if (eval-rule-f (car rules ) )
(return t) ) ) )
61
Coding Forward Reasoning
  • eval-rule-f examines an individual rule if it
    executes (all premises are satisfied and calling
    derive-new-fact?)
  • (defun eval-rule-f (rule)
  • (do ( ( ifs (caddr rule )
  • ( if (member (car ifs)
  • fact-list test equal )
  • ( cdr ifs)
  • (return nil) ) )
    there is a premise not satisfied
  • ( thens (caddr (cddr rule ))
    ) ) then list of the rule
  • ( ( null ifs)
    (derive-new-fact? thens ) ) ) ) if all the
    premises are
    satisfied look if new fact is going to be derived

62
Coding Forward Reasoning
  • derive-new-fact? examines the rules conclusions
    to see if there is a conclusion not in the
    database.
  • ( defun derive-new-fact? (facts)
  • (do ( (new-fact? nil) initial value for
    new-fact is nil
  • (fact-arg facts (cdr facts-arg)
    ) ) initiate fact-arg to fact and
    iterate over cdr of fact-arg ( ( null
    facts-arg) new-fact?)
  • ( cond ( ( member (car facts-arg)

  • fact-list test equal) return nill)
  • ( t (display-results
    (car facts-arg) )
  • ( setq new-fact? t)
  • ( setq fact-list
  • (cons
    (car facts-arg ) fact_list) ) ) ) ) )

63
Coding Forward Reasoning
  • display-results prints a message every time a new
    fact is derived
  • (defun display-results (derived-fact )
  • (terpri) print new line
  • (princ The value of )
  • (princ (cadr derived-fact) ) second element
    of a list
  • (princ is )
  • (princ (cadr drived-fact) ) )

64
Coding Forward Reasoning
  • (setq rule-list
  • ((R1a IF (( is shape long) (is color
    green )) THEN ((fruit banana)) )
  • (R1b IF (( is shape long) (is color
    yellow)) THEN ( (is fruit banana)) )
  • (R2a IF ((is shape round)
    (gt diameter 4)) THEN ((is fruitclass
    vine)) )
  • (R2b IF ((shape oblong ) (gt diameter 4))
    THEN ((is fruitclass vine)) )
  • R3 IF ((is shape round ) (lt diameter
    4 )) THEN ((is fruitclass tree)) )
  • (R4 IF (( seedcount 1)) THEN ((is
    seedclass stonefruit)) )
  • (R5 IF (( gt seedcount 1))
    THEN ((is seedclass multiple)) )
  • (R6 IF ((is fruitclass vine ) (is
    color green )) THEN ( is fruit
    watermelon)) )
  • (R7 IF ((is fruitclass vine) (is surface
    smooth) (is color yellow ))
    THEN ((fruit honeydew)) )
  • . ) )

65
  • Consider the following fact base
  • (setq fact-list
  • ( ( is color red)
  • ( is shape round)
  • ( seedcount 1)
  • ( lt diameter 4)
  • ) )
  • This fact base causes the following execution
    results to be displayed

The value of FRUITCLASS is TREE The value of
SEEDCLASS is STONEFRUIT The value of FRUIT is
CHERRY T
66
Backward Reasoning
  • Backward chaining is more suited for applications
    having many more inputs than possible
    conclusions. The ability to trace the logic
    backwards from the few conclusions to the many
    inputs make it more efficient than forward
    chaining.
  • Diagnosis and classification problems are well
    suited for backward chaining.

67
Steps in Backward Reasoning
  • Form a temporary stack initially set to the top
    level goals defined in the system.
  • Set the goal to be traced to the top of the
    stack. If the stack is empty halt and announce
    completion.
  • Gather all rules satisfying this goal.
  • Consider each of these rules in turn
  • If all premises are satisfied, then fire this
    rule to derive its conclusions. Do not consider
    any more rules for this goal. Its value is now
    given by the current rules conclusion. If the
    goal being currently traced is a top level goal,
    remove it from the stack and go to step 2. If it
    is a sub goal remove it from the stack and
    continue with the suspended goal.
  • If a value in the database conflicts with the
    premise value fail the rule.
  • If a premise is not satisfied with the facts in
    the database look if it can be derived. If it
    can, consider this parameter as a sub-goal and
    go back to step 2.

68
Steps in Backward Reasoning
  • If step 4c fails then ask the user for its value
    and add it to the database go to step 4a and
    consider the next premise of the rule.
  • If all rules that can satisfy the current goal
    have been attempted and all have failed to derive
    a value, then this goal remains undetermined.
    Remove it from the stack and go back to step 2.

69
Example - Backward ReasoningConsider the
following knowledge base that helps us select
beverage and main course for a meal.
  • R1 IF guest-age lt 21
  • THEN alcohol-indicated no
  • R2 IF guest-age gt 21
  • THEN alcohol-indicated yes
  • R3 IF alcohol-indicatedyes, meal formal
    THEN drink wine
  • R4 IF alcohol-indicatedyes, guest boss
    THEN drink wine
  • R5 IF alcohol-indicatedyes, guest neighbor
    THEN drink beer
  • R6 IF drink wine, dinner
    fish THEN wine-type white
  • R7 IF drink wine, dinner
    red-meat THEN wine-type red
  • R8 IF guest boss day friday
    THEN dinner fish
  • R9 IF guest boss day ltgt friday
    THEN dinner red-meat
  • R10 IF guest-age lt 21
  • THEN dinner pizza
  • R11 IF guest-age gt21
  • THEN dinner fish
  • R12 IF alcohol-indicated no THEN drink soda

70
Example - Backward Reasoning
  • The parameters and their acceptable values are
  • guest-age positive integer between 15 100
  • alcohol-indicated yes/no
  • meal formal/informal
  • drink wine/beer/soda
  • guest boss/neighbor/friend
  • dinner fish/veal/red-meat/poultry/pizza
  • day monday/Tuesday/ . . . /Sunday

71
Example - Backward Reasoning
  • In this approach the system takes the
    responsibility of questioning the user about the
    facts when they are needed for the reasoning
    process.
  • The system starts with no data attached to any of
    the parameters
  • Known Fact Base ( )

A list of goals in the order the developer feels
is best to pursue should be provided to guide the
system. Goals (drink wine-type dinner)
72
Example - Backward Reasoning
  • Suppose that it is Tuesday and we have invited
    our 30-year-old neighbor for a casual meal.
  • If the knowledge base is traced the database will
    include the following values

73
Example - Backward Reasoning
  • Database
  • ( ( dinner fish )
  • ( drink beer)
  • ( guest neighbor)
  • ( meal casual)
  • ( alcohol-indicated yes)
  • (guest-age 30) )
  • Note that the system is unable to derive a value
    for the parameter wine type. Also note that the
    system never asks a value for a day, since this
    premise is only used when the guest is determined
    to be the boss.
Write a Comment
User Comments (0)
About PowerShow.com