430 likes | 668 Views
DT228/3 Intelligent Systems Development. Rule-Based Expert Systems. Contents. In this lecture we will review rule-based expert systems What do we mean by rule-based expert systems? Architecture of a rule-based expert system Inference in rule-based expert systems Forward chaining
E N D
DT228/3 Intelligent Systems Development Rule-Based Expert Systems
Contents In this lecture we will review rule-based expert systems • What do we mean by rule-based expert systems? • Architecture of a rule-based expert system • Inference in rule-based expert systems • Forward chaining • Backward chaining • Limitations of rule-based expert systems
What is an Expert System? An expert system is a computer system that: • Performs functions similar to those normally performed by a human expert • Uses a representation of human expertise in a specialist domain to perform functions similar to a human domain expert • Operates by applying an inference mechanism to a body of specialist expertise represented in a knowledge base
What is a Rule-Based Expert System? If you had to explain to somebody how to cross a road you could do it with simple rules Statements in this IF-THEN form are referred to as production rules A rule-based expert system captures the knowledge of an expert in a set of production rules and combines these with observed data to generate inferences IF: the traffic light is green THEN: the action is go IF: the traffic light is red THEN: the action is wait
Production Rules Production rules • IF-THEN expressions • IF some condition(s) exists THEN perform some action(s) Condition-action pair • Condition: pattern that determines when a rule may be applied to problem instance • Action: defines associated problem solving step Antecedent – Consequent • IF <antecedent> THEN <consequent>
Production Rules (cont…) Rule can have multiple antecedents • Conjunction AND • Disjunction OR • Or a combination of both IF <antecedent0> AND <antecedent1> … AND <antecedentn> THEN <consequent> IF <antecedent0> OR <antecedent1> … OR <antecedentn> THEN <consequent> IF <antecedent0> AND <antecedent1> … AND <antecedentn> OR <antecedent0> OR <antecedent1> … OR <antecedentn> THEN <consequent>
Production Rules (cont…) Consequents can also have multiple clauses Some production rule examples IF <antecedent> THEN <consequent0>, <consequent1>, …<consequentn-1>,<consequentn> IF the fuel tank is empty THEN the car is dead IF patient has stomach pains AND (temperature > 98 OR patient is nauseous) THEN diagnosis is appendicitis, action is call the surgeon IF the season is autumn AND the sky is cloudy AND the forecast is drizzle THEN advice is take an umbrella
Rule-Based Expert System Model Long Term Memory Working Memory Fact Production Rule Inference Engine Production System Explanation Facilities User Interface User
Production System Model Long Term Memory Working Memory Fact Production Rule Inference (Reasoning) Conclusion
Production System Long-term memory • Stores the production rules used to make inferences Working memory • Current state of world • Pattern that is matched against the condition part of rules to select appropriate problem-solving actions • Actions may alter working memory
Production System (cont…) Inference cycle (Recognize-Act Cycle) • Working memory is initialized at start of reasoning • Current state is maintained as set of patterns in working memory • Patterns matched against conditions in rules to find a satisfied rule • Fire the selected rule • An action is performed changing working memory • Repeat until working memory no longer matches rule conditions
Data Driven Search Strategy Forward Chaining: Begins with problem description and infers new knowledge from the data Applies rules of inference to current description of world and adds inferred results to problem description • Many rules may be executed that have nothing to do with the goal Rule matching continues until the goal has been reached May not be efficient
Data-Driven: How Does it Work? Data-driven search proceeds in cycles Inference cycle matches the current state of the world against the sets of production rules • The current state of the world is the data that is assumed to be true or deduced as true from previously fired production rules Action of a rule adds new fact(s) to the working memory when fired Cycle stops when no further rules can be fired
Forward Chaining Example Database A C B D E Knowledge Base Y & D → Z X & B & E → Y A → X C → L L & M → N Suppose that we know the facts A, B, C, D, E and the rules shown in the knowledge base to the left What facts can we infer from this?
Forward Chaining Example Database A C B D E X Knowledge Base Y & D → Z X & B & E → Y A → X C → L L & M → N Inference Cycle 1
Forward Chaining Example Database A C B D E X L Knowledge Base Y & D → Z X & B & E → Y A → X C → L L & M → N Inference Cycle 1
Forward Chaining Example Database Database A C B D E A C B D E X X L L Knowledge Base Knowledge Base Y & D → Z Y & D → Z X & B & E → Y X & B & E → Y A → X A → X C → L C → L L & M → N L & M → N Inference Cycle 1 Inference Cycle 2
Forward Chaining Example Database Database A C B D E A C B D E X X L Y L Knowledge Base Knowledge Base Y & D → Z Y & D → Z X & B & E → Y X & B & E → Y A → X A → X C → L C → L L & M → N L & M → N Inference Cycle 1 Inference Cycle 2
Forward Chaining Example Database Database Database A C B D E A C B D E A C B D E X X L Y L X L Y Knowledge Base Knowledge Base Knowledge Base Y & D → Z Y & D → Z Y & D → Z X & B & E → Y X & B & E → Y X & B & E → Y A → X A → X A → X C → L C → L C → L L & M → N L & M → N L & M → N Inference Cycle 1 Inference Cycle 2 Inference Cycle 3
Forward Chaining Example Database Database Database A C B D E A C B D E A C B D E X X L Y L X L Y Z Knowledge Base Knowledge Base Knowledge Base Y & D → Z Y & D → Z Y & D → Z X & B & E → Y X & B & E → Y X & B & E → Y A → X A → X A → X C → L C → L C → L L & M → N L & M → N L & M → N Inference Cycle 1 Inference Cycle 2 Inference Cycle 3
Forward Chaining Example Database Database Database A C B D E A C B D E A C B D E After inferring facts X, L, Y and Z there are no more rules that can be fired X X L Y L X L Y Z Knowledge Base Knowledge Base Knowledge Base Y & D → Z Y & D → Z Y & D → Z X & B & E → Y X & B & E → Y X & B & E → Y A → X A → X A → X C → L C → L C → L L & M → N L & M → N L & M → N Inference Cycle 1 Inference Cycle 2 Inference Cycle 3
Goal-Driven Search Strategy Backward Chaining: A desired goal is placed in working memory, inference cycle attempts to find evidence to prove it Search knowledge base for rules that might lead to goal • Rules that have the goal in their action parts If condition of such rule matches fact in working memory then rule is fired and goal is proved
Goal Driven: How Does it Work? Goal driven search proceeds in cycles Stack rule • Set up sub-goal to prove condition • Search for rules to prove sub-goal • Continue process of stacking until no rules found that can prove sub-goal Most efficient when want to infer one particular fact User may be asked to input additional facts
Backward Chaining Example Database A C B D E Suppose that we know the facts A, B, C, D, E and the rules shown in the knowledge base to the left Can we infer the fact Z? Knowledge Base Y & D → Z X & B & E → Y A → X C → L L & M → N
Backward Chaining Example Database A C B D E Z Knowledge Base Y & D → Z X & B & E → Y A → X C → L L & M → N Goal: Z
Backward Chaining Example Database A C B D E Z Knowledge Base Y & D → Z X & B & E → Y A → X C → L L & M → N Goal: Z
Backward Chaining Example Database Database A A C C B B D D E E ? Z Y Knowledge Base Knowledge Base Y & D → Z Y & D → Z X & B & E → Y X & B & E → Y A → X A → X C → L C → L L & M → N L & M → N Goal: Z Sub-goal: Y
Backward Chaining Example Database Database A A C C B B D D E E ? Z Y Knowledge Base Knowledge Base Y & D → Z Y & D → Z X & B & E → Y X & B & E → Y A → X A → X C → L C → L L & M → N L & M → N Goal: Z Sub-goal: Y
Backward Chaining Example Database Database Database A A A C C C B B B D D D E E E ? ? Z Y X Knowledge Base Knowledge Base Knowledge Base Y & D → Z Y & D → Z Y & D → Z X & B & E → Y X & B & E → Y X & B & E → Y A → X A → X A → X C → L C → L C → L L & M → N L & M → N L & M → N Goal: Z Sub-goal: Y Sub-goal: X
Backward Chaining Example Database Database Database A A A C C C B B B D D D E E E ? ? Z Y X Knowledge Base Knowledge Base Knowledge Base Y & D → Z Y & D → Z Y & D → Z X & B & E → Y X & B & E → Y X & B & E → Y A → X A → X A → X C → L C → L C → L L & M → N L & M → N L & M → N Goal: Z Sub-goal: Y Sub-goal: X
Backward Chaining Example Database Database A A C C B B D D E E Database A C B D E X ? Z Y Knowledge Base Knowledge Base Knowledge Base Y & D → Z Y & D → Z Y & D → Z X & B & E → Y X & B & E → Y X & B & E → Y A → X A → X A → X C → L C → L C → L L & M → N L & M → N L & M → N Goal: Z Sub-goal: Y Sub-goal: X
Backward Chaining Example Database A C B D E Database Database A C B D E A C B D E X Y X Z Knowledge Base Knowledge Base Knowledge Base Y & D → Z Y & D → Z Y & D → Z X & B & E → Y X & B & E → Y X & B & E → Y A → X A → X A → X C → L C → L C → L L & M → N L & M → N L & M → N Goal: Z Sub-goal: Y Sub-goal: X
Backward Chaining Example Database Database Database A C B D E A C B D E A C B D E X Y Z X Y X Knowledge Base Knowledge Base Knowledge Base Y & D → Z Y & D → Z Y & D → Z X & B & E → Y X & B & E → Y X & B & E → Y A → X A → X A → X C → L C → L C → L L & M → N L & M → N L & M → N Goal: Z Sub-goal: Y Sub-goal: X
Backward Chaining Example Database Database Database A C B D E A C B D E A C B D E Backward chaining inferred Z from the facts and rules that were available X Y Z X Y X Knowledge Base Knowledge Base Knowledge Base Y & D → Z Y & D → Z Y & D → Z X & B & E → Y X & B & E → Y X & B & E → Y A → X A → X A → X C → L C → L C → L L & M → N L & M → N L & M → N Goal: Z Sub-goal: Y Sub-goal: X
Data Driven Vs. Goal Driven Data-driven reasoning is appropriate when there exist many equally acceptable goal states, a narrow body of facts and rules and a single initial state • Required facts are available • It is difficult to form a goal to verify Goal directed inference is relevant when:- • Relevant data must be acquired during the inference process • Large number of applicable rules exist • An obvious goal to verify is available
Conflict Resolution What if more than one rule matches a in a particular situation? We have actually already seen this in one of our examples What should we do? Database A C B D E Knowledge Base Y & D → Z X & B & E → Y A → X C → L L & M → N
Conflict Resolution What if more than one rule matches a in a particular situation? We have actually already seen this in one of our examples What should we do? • The answer is referred to as conflict resolution Database A C B D E X L ? ? Knowledge Base Y & D → Z X & B & E → Y A → X C → L L & M → N
Conflict Resolution (cont..) What if more than one rule matches a in a particular situation? • Patterns are matched against conditions in rules to produce a set of satisfied rules • These rules are known as the conflict set • Conflict Resolution • One rule is selected and fired • Action is performed which changes working memory • Repeat until working memory no longer matches rule conditions
Conflict Resolution (cont..) How do you choose which rule from the conflict set to fire? • Rule Ordering • Choose the first rule in the text, ordered top-to-bottom. • Recency • Prefers rules that use facts most recently added • Focuses on single line of reasoning • Specificity • More specific rules are preferable to more general • A rule is more specific if it has more conditions - implies a rule will match fewer potential working memory patterns
Conflict Resolution (cont..) • Refraction • Once a rule has fired it may not fire again until working memory elements that match its conditions have been modified • Discourages looping Structure of rules and the conflict resolution scheme used controls the fashion in which the space is searched Allows us to encode heuristics into production rules
Summary In this lecture we have covered • What is a rule-based expert systems? • Overall architecture of rule-based expert systems • How inference works in a rule-based expert system