1 / 69

Rule Based Expert System

Rule Based Expert System. دكترمحسن كاهاني http://www.um.ac.ir/~kahani/. Introduction.

gavan
Télécharger la présentation

Rule Based Expert System

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. Rule Based Expert System دكترمحسن كاهاني http://www.um.ac.ir/~kahani/

  2. Introduction • Knowledge is a theoretical or practical understanding of a subject or a domain. Knowledge is also the sum of what is currently known, and apparently knowledge is power. Those who possess knowledge are called experts. • 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. The area of the domain may be limited. In general, an expert is a skilful person who can do things other people cannot. سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  3. Introduction • The human mental process is internal, and it is too complex to be represented as an algorithm. However, 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 سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  4. Rules as a knowledge representation technique • The term rule in AI can be defined as an IF-THEN structure that relates given information or facts in the IF part to some action in the THEN part. • Any rule consists of two parts: • IF part, called the antecedent (premise or condition) • THEN part called the consequent (conclusion or action). IF <antecedent> THEN <consequent> سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  5. Rules (cont.) • 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> سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  6. Rules (cont.) • The antecedent of a rule incorporates two parts: • an object (linguistic object) • its value. • The object and its value are linked by an operator. • The operator identifies the object and assigns the value. • Expert systems can also use mathematical operators to define an object as numerical and assign it to the numerical value. IF ‘age of the customer’ < 18 AND ‘cash withdrawal’ > 1000 THEN ‘signature of the parent’ is required سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  7. Rule Types • Relation IF the ‘fuel tank’ is empty THEN the car is dead • Recommendation IF the season is autumn AND the sky is cloudy AND the forecast is drizzle THEN the advice is ‘take an umbrella’ سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  8. Rule Types(cont.) • Directive IF the car is dead AND the ‘fuel tank’ is empty THEN the action is ‘refuel the car’ • 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 سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  9. Rule Types (cont.) • Heuristic IF the spill is liquid AND the ‘spill pH’ < 6 AND the ‘spill smell’ is vinegar THEN the ‘spill material’ is ‘acetic acid’ سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  10. The main players in the development team • There are five members of the expert system development team: the domain expert, the knowledge engineer, the programmer, the project manager and the end-user. • The success of their expert system entirely depends on how well the members work together. سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  11. The main players in the development team سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  12. Structure of a rule-based expert system • In the early seventies, Newell and Simon from Carnegie-Mellon University proposed a production system model, the foundation of the modern rule based expert systems. • The production model is based on the idea that humans solve problems by applying their knowledge (expressed as production rules) to a given problem represented by problem-specific information. • The production rules are stored in the long-term memory and the problem-specific information or facts in the short-term memory. سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  13. Production system model سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  14. Basic structure of a rule-based expert system سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  15. Elements of a rule-based expert system • The knowledge base contains the domain knowledge useful for problem solving. In a rule based expert system, the knowledge is represented as a set of rules. • The database includes a set of facts used to match against the IF (condition) parts of rules stored in the knowledge base. • The inference engine carries out the reasoning whereby the expert system reaches a solution. It links the rules given in the knowledge base with the facts provided in the database. سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  16. Elements of a rule-based expert system • The explanation facilitiesenable the user to ask the expert system howa particular conclusion is reached and whya specific fact is needed. • The user interfaceis the means of communication between a user seeking a solution to the problem and an expert system. سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  17. Complete structure of a rule-based expert system سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  18. Characteristics of an expert system • An expert system is built to perform at a human expert level in a narrow, specialised domain. Thus, the most important characteristic of an expert system is its high-quality performance. No matter how fast the system can solve a problem, the user will not be satisfied if the result is wrong. • On the other hand, the speed of reaching a solution is very important. Even the most accurate decision or diagnosis may not be useful if it is too late to apply, for instance, in an emergency, when a patient dies or a nuclear power plant explodes. سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  19. Characteristics of an expert system • Expert systems apply heuristics to guide the reasoning and thus reduce the search area for a solution. • A unique feature of an expert system is its explanation capability. It enables the expert system to review its own reasoning and explain its decisions. • Expert systems employ symbolic reasoning when solving a problem. Symbols are used to represent different types of knowledge such as facts, concepts and rules. سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  20. Can expert systems make mistakes? • Even a brilliant expert is only a human and thus can make mistakes. This suggests that an expert system built to perform at a human expert level also should be allowed to make mistakes. • But we still trust experts, even we recognize that their judgments are sometimes wrong. Likewise, at least in most cases, we can rely on solutions provided by expert systems, but mistakes are possible and we should be aware of this. سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  21. Can expert systems make mistakes? • In expert systems, knowledge is separated from its processing (the knowledge base and the inference engine are split up). • A conventional program is a mixture of knowledge and the control structure to process this knowledge. • When an expert system shell is used, a knowledge engineer or an expert simply enters rules in the knowledge base. Each new rule adds some new knowledge and makes the expert system smarter. سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  22. Comparison سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  23. Comparison (cont.) سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  24. Forward chaining and backward chaining • domain knowledge is represented by a set of IF-THEN production rules • data is represented by a set of facts about the current situation. • The inference engine compares each rule stored in the knowledge base with facts contained in the database. • When the IF (condition) part of the rule matches a fact, the rule is fired and its THEN (action) part is executed. • The matching of the rule IF parts to the facts produces inference chains. The inference chain indicates how an expert system applies the rules to reach a conclusion. سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  25. Inference engine cycles via a match-fire procedure سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  26. An example of an inference chain سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  27. Forward chaining • Forward chaining is the data-driven reasoning. The reasoning starts from the known data and proceeds forward with that data. Each time only the topmost rule is executed. When fired, the rule adds a new fact in the database. Any rule can be executed only once. The match-fire cycle stops when no further rules can be fired. سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  28. Forward chaining سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  29. Forward chaining • Forward chaining is a technique for gathering information and then inferring from it whatever can be inferred. • However, in forward chaining, many rules may be executed that have nothing to do with the established goal. • Therefore, if our goal is to infer only one particular fact, the forward chaining inference technique would not be efficient. سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  30. Backward chaining • Backward chaining is the goal-driven reasoning. In backward chaining, an expert system has the goal (a hypothetical solution) and the inference engine attempts to find the evidence to prove it. • First, the knowledge base is searched to find rules that might have the desired solution. Such rules must have the goal in their THEN (action) parts. If such a rule is found and its IF (condition) part matches data in the database, then the rule is fired and the goal is proved. However, this is rarely the case. سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  31. Backward chaining • Thus the inference engine puts aside the rule it is working with (the rule is said to stack) and sets up a new goal, a subgoal, to prove the IF part of this rule. • Then the knowledge base is searched again for rules that can prove the subgoal. • The inference engine repeats the process of stacking the rules until no rules are found in the knowledge base to prove the current subgoal. سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  32. Backward chaining سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  33. How do we choose between forward and backward chaining? • 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. • However, if your expert begins with a hypothetical solution and then attempts to find facts to prove it, choose the backward chaining inference engine. سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  34. Pattern Matching • used to match rules with appropriate facts in working memory • rules for which facts can be found are satisfied • the combination of a rule with the facts that satisfy it is used to form activation records • one of the activation records is selected for execution سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  35. Simplistic Pattern Matching • go through the list of rules, and check the antecedent (LHS) of each rule against the facts in working memory • create an activation record for each rule with a matching set of facts • repeat after each rule firing • very inefficient • roughly (number of rules) * (number of facts)(number of patterns) • the actual performance depends on the formulation of the rules and the contents of the working memory سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  36. Rete Algorithm • in most cases, the set of rules in a rule-based system is relatively constant • the facts (contents of working memory) change frequently • most of the contents of working memory, however, don’t change every time • optimization of the matching algorithm • remember previous results • change only those matches that rely on facts that changed • the Rete algorithm performs an improved matching of rules and facts • invented by Charles Forgy in the early 80s • basis for many rule-based expert system shells سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  37. Rete Network • the name comes from the latin word rete • stands for net • consists of a network of interconnected nodes • each node represents one or more tests on the LHS of a rule • input nodes are at the top, output nodes at the bottom • pattern nodes have one input, and check the names of facts • join nodes have two inputs, and combine facts • terminal node at the bottom of the network represent individual rules • a rule is satisfied if there is a combination of facts that passes all the test nodes from the top to the output node at the bottom that represents the rule • the Rete network effectively is the working memory for a rule-based system سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  38. Rete Network Example 1 (deftemplate x (slot a)) (deftemplate y (slot b)) (defrule example-1 (x (a ?v1)) (y (b ?v1)) ==> ) ?=x ?=y ?v1 ?v1 Left.0.a ?= Right.b ?v1 = ?v1 example-1 سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  39. Rete Left and Right Memories • left (alpha) memory • contains the left input of a join node • right (beta) memory • contains the right input of a join node • notation:Left.p.q ?= Right.r • compare the contents of slot q in fact p from the left memory with slot r in the fact from the right memory (deftemplate x (slot a)) (deftemplate y (slot b)) (defrule example-1 (x (a ?v1)) (y (b ?v1)) ==> ) ?=x ?=y ?v1 ?v1 Left.0.a ?= Right.b ?v1 = ?v1 example-1 سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  40. Running the Network • only facts xand y are considered • all facts where x.a==y.b pass the join network • all {x, y} tuples are forwarded to the next node • compare the contents of slot q in fact p from the left memory with slot r in the fact from the right memory (deftemplate x (slot a)) (deftemplate y (slot b)) (defrule example-1 (x (a ?v1)) (y (b ?v1)) ==> ) ?=x ?=y ?v1 ?v1 Left.0.a ?= Right.b ?v1 = ?v1 example-1 سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  41. Rete Network Example 2 • shares some facts with Example 1 (deftemplate x (slot a)) (deftemplate y (slot b)) (deftemplate z (slot c)) (defrule example-2 (x (a ?v2)) (y (b ?v2)) (z) ==> ) ?=x ?=y ?=z ?v2 ?v2 Left.0.a ?= Right.b ?v2 = ?v2 ?v2 example-2 سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  42. Rete Network Example 2 with Assert • additional fact asserted (deftemplate x (slot a)) (deftemplate y (slot b)) (deftemplate z (slot c)) (defrule example-2 (x (a ?v2)) (y (b ?v2)) (z) ==> ) (assert (z (c 17)) ?=x ?=y ?=z ?v2 ?v2 17 Left.0.a ?= Right.b ?v2 = ?v2 ?v2 ?v2= 17 example-2 سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  43. Assert and Retract with Rete • asserting additional facts imposes some more constraints on the network • retracting facts indicates that some previously computed activation records are not valid anymore, and should be discarded • in addition to the actual facts, tags are sent through the networks • ADD to add facts (i.e. for assert) • REMOVE to remove facts (i.e. for retract) • CLEAR to flush the network memories (i.e. for reset) • UPDATE to populate the join nodes of newly added rules • already existing join nodes can neglect these tokens سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  44. Rete Network Optimization • networks with shared facts can be combined (deftemplate x (slot a)) (deftemplate y (slot b)) (deftemplate z (slot c)) (defrule example-1 (x (a ?v1)) (y (b ?v1)) ==> ) (defrule example-2 (x (a ?v2)) (y (b ?v2)) (z) ==> ) ?=x ?=y ?=z Left.0.a ?= Right.b example-1 example-2 سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  45. Further Optimizations • sophisticated data structures to optimize the network • hash table to presort the tokens before running the join node tests • fine-tuning via parameters • frequently trade-off between memory usage and time سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  46. Special Cases for Pattern Matching • additional enhancements of the Rete network can be used to implement specific methods • backward chaining • requires a signal indicating to the network that a particular fact is needed • not conditional element • indicates the absence of a fact • requires special join nodes and special fields in the tokens passing through the network • test conditional element • uses a special join node that ignores its right input • the result of the function is passed on سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  47. Rule Formulation • Pattern Order • General vs. Specific Rules • Simple vs. Complex Rules • Loading and Saving Facts سيستمهاي خبره و مهندسي دانش-دكتر كاهاني [Giarratano & Riley 1998]

  48. Pattern Order • since Rete saves information about rules and facts, it can be critical to order patterns in the right way • otherwise a potentially huge number of partial matches can be generated سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  49. (deffacts information (find-match a c e g) f1 (item a) f2 (item b) f3 (item c) f4 (item d) f5 (item e) f6 (item f) f7 (item g)) f8 (defrule match-1 (find-match ?x ?y ?z ?w) P1 (item ?x) P2 (item ?y) P3 (item ?z) P4 (item ?w) P5 ==> (assert (found-match ?x ?y ?z ?w)) (deffacts information (find-match a c e g) (item a) (item b) (item c) (item d) (item e) (item f) (item g)) (defrule match-1 (item ?x) (item ?y) (item ?z) (item ?w) (find-match ?x ?y ?z ?w) ==> (assert (found-match ?x ?y ?z ?w)) Example Pattern Order سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

  50. full matches P1: f1 P2: f2,f3,f4,f5,f6,f7,f8 P3: f2,f3,f4,f5,f6,f7,f8 P4: f2,f3,f4,f5,f6,f7,f8 P5: f2,f3,f4,f5,f6,f7,f8 partial matches P1: [f1] P1-2: [f1,f2] P1-3: [f1,f2,f4] P1-4: [f1,f2,f4,f6] P1-5: [f1,f2,f4,f6,f8] Total: 29 full, 5 partial matches full matches P1: f1 P2: f2,f3,f4,f5,f6,f7,f8 P3: f2,f3,f4,f5,f6,f7,f8 P4: f2,f3,f4,f5,f6,f7,f8 P5: f2,f3,f4,f5,f6,f7,f8 partial matches P1: [f2,f3,f4,f5,f6,f7,f8] P1-2: [f2,f2],[f2,f3],[f2,f4],[f2,f5], [f2,f6],[f2,f7],[f2,f8], [f3,f2],[f3,f3],[f3,f4],[f3,f5], [f3,f6],[f3,f7],[f3,f8], ... P1-3, P1-4: ... P1-5: [f2,f4,f6,f8, f1] Total: 29 full, 2801 partial matches Pattern Matches سيستمهاي خبره و مهندسي دانش-دكتر كاهاني

More Related