1 / 73

Details of Rule Based Reasoning

Details of Rule Based Reasoning. Chapter 5 The Engineering of Knowledge Based Systems. Introduction. Traditionally pattern matching systems have been associated with forward reasoning while backward reasoning systems typically have been implemented as inference networks.

zea
Télécharger la présentation

Details of Rule Based Reasoning

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 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 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

  9. Example 1 of Forward Reasoning R13 IF heigt <10 THEN level = low R14 IF heiht >=10 AND <=16 THEN level = normal R15 IF height > 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 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 (CF=0.5) AND evac = yes (CF=0.2) R12 IF change = higher AND level = high AND rain = heavy THEN flood = yes AND evac = yes (CF=0.8)

  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 rule’s 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

  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 object’s (box’s)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 box’s free space >= the fragile item’s size THEN put the fragile item in the box decrease the box’s free space by the fragile item’s 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 <4 heavy items the box’s free space >= the item’s size THEN put the heavy item in the box decrease the box’s free space by the heavy item’s 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 box’s free space >= the medium item’s size THEN put the medium item in the box decrease the box’s free space by the medium item’s 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 >= the light item’s size THEN put the light item in the box decrease the box’s free space by the light item’s 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

  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. 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. 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. Database after execution of R2 for Lamp 1 and Box 1

  42. Database after Boxing all Fragile Items

  43. Database after Boxing all Heavy Items

  44. 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 • rrules in our knowledge base • ffacts in our database • An average of ppremises in each rule we will perform r*f * * 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. cat dog Match value to ?c Match value to ?c small Match value to ?q Match value to ?h medium Match value to ?n1 Match value to ?n2 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

More Related