330 likes | 437 Views
Chapter 9. Rules and Expert Systems. Comp3710 Artificial Intelligence Computing Science Thompson Rivers University. Course Outline. Part I – Introduction to Artificial Intelligence Part II – Classical Artificial Intelligence, and Searching Knowledge Representation Searching
E N D
Chapter 9.Rules and Expert Systems Comp3710 Artificial Intelligence Computing Science Thompson Rivers University
Course Outline • Part I – Introduction to Artificial Intelligence • Part II – Classical Artificial Intelligence, and Searching • Knowledge Representation • Searching • Search Methodologies • Advanced Search • Genetic Algorithms (relatively new study area) • Knowledge Represenation and Automated Reasoning • Propositinoal and Predicate Logic • Inference and Resolution for Problem Solving • Rules and Expert Systems • Part III – Machine Learning • Part IV – Advanced Topics Rules and Expert Systems
Chapter Objectives • Rule-based expert systems • Do forward chaining with example rules and facts • Do backward chaining with example rules and facts • Explain what a rule-based expert system consists of • List the two parts in expert systems, which can not be easily solved Rules and Expert Systems
Chapter Outline • Rules for Knowledge Representation • Rule-Based Systems • Forward Chaining • Backward Chaining • Rule-Based Expert Systems Rules and Expert Systems
Rules for Knowledge Representation • Here are some interesting quotes. • Each problem that I solved became a rule which served afterwards to solve other problems.- Rene Descartes • As a rule we disbelieve all the facts and theories for which we have no use. - William James Rules and Expert Systems
Rules for Knowledge Representation • Hell, there are no rules here -- we're trying to accomplish something. - Thomas A. Edison • Get your facts first, and then you can distort them as much as you please. - Mark Twain • If the facts don't fit the theory, change the facts. - Albert Einstein Rules and Expert Systems
Rules for Knowledge Representation • [Q] How do you want to represent our knowledge? • [Q] How do we do [logical] reasoning? • Facts and rules: • IF… THEN rules can be used to represent knowledge: • IF it rains, THEN you will get wet • Rules can also be recommendations or actions: • IF it rains, THEN you should wear a coat Rules and Expert Systems
Topics Rules for Knowledge Representation • A rule consists of an antecedent and a consequence (action, conclusion). • IF A THEN B, or A -> B • When there are more than one antecedent, • AND (&), OR (|), NOT (~), ... or • , , , ... (conjunction, disjunction, negation) • Truth table? (T F) (T F) T -> F ??? • In general, the antecedent of a rule compares an object [variable] with a possible value, using an operator. I.e., the antecedent of a rule is a Boolean expression. • IF x 3 • IF name is “Bob” • IF weather is cold • IF name is “Bob” weather is cold THEN tell “Bob” ‘Wear a coat’ Rules and Expert Systems
Topics Rule-Based Systems • A rule-based system or production system is a system that uses knowledge in the form of rules to provide diagnoses or advice on the basis of input data (facts). • The system consists of • a database of rules (knowledge base), • a database of facts, and • an inference engine which reasons about the facts using the rules to draw conclusions. • Conclusions are often derived using deduction (deductive reasoning). • Forward chaining: using deduction to reach a conclusion from a set of antecedents (i.e., facts) • Backward chaining: starts from a conclusion (i.e., hypothesis) and tries to show it by following a logical path backward from the conclusion to a set of antecedents that are in the database of facts Rules and Expert Systems
Forward Chaining • Forward chaining is a reasoning model that works from a set of facts and rules towards a set of conclusions, diagnoses or recommendations. • Also known as data-driven reasoning • When a fact matches the antecedent of a rule, the rule fires, and the conclusion of the rule is added to the database of facts. • Take the facts from the database. • See if any combination of these matches all the antecedents of one of the rules in the database. This step takes some time. • When all the antecedents of a rule are matched by facts, then this rule is triggered. • When a rule is triggered, it is then fired, which means its conclusion is added to the facts database. Rules and Expert Systems
Forward Chaining • Example of elevator • Rule 1: IF floor = first & button = first THEN open door • Rule 2: IF floor = first & button = second THEN goto second floor • Rule 3: IF floor = first & button = third THEN goto third floor • Rule 4: IF floor = second & button = first & going to third floor = T THEN remember to goto first floor • Fact 1: floor = first • Fact 2: button = third • Fact 3: day = Tuesday • The facts match Rule ??? and the conclusion ??? is added to the database of facts Rules and Expert Systems
Forward Chaining • Example of elevator – cont • Rule 1: IF floor = first & button = first THEN open door • Rule 2: IF floor = first & button = second THEN goto second floor • Rule 3: IF floor = first & button = third THEN goto third floor • Rule 4: IF floor = second & button = first & going to third floor = T THEN remember to goto first floor • Fact 1: floor = second (<- first) • Fact 2: button = • Fact 3: day = Tuesday • Fact 4: going to third floor = T Rules and Expert Systems
Forward Chaining • Example of elevator – cont • Rule 1: IF floor = first & button = first THEN open door • Rule 2: IF floor = first & button = second THEN goto second floor • Rule 3: IF floor = first & button = third THEN goto third floor • Rule 4: IF floor = second & button = first & going to third floor = T THEN remember to goto first floor • Fact 1: floor = second (<- first) • Fact 2: button = first • Fact 3: day = Tuesday • Fact 4: going to third floor = T Rules and Expert Systems
Forward Chaining • Example of elevator – cont • Rule 1: IF floor = first & button = first THEN open door • Rule 2: IF floor = first & button = second THEN goto second floor • Rule 3: IF floor = first & button = third THEN goto third floor • Rule 4: IF floor = second & button = first & going to third floor = T THEN remember to goto first floor • Fact 1: floor = second (<- first) • Fact 2: button = first • Fact 3: day = Tuesday • Fact 4: going to third floor = T • Rule 4 is fired. • [Q] What if someone pressed the button on the second floor? Rules and Expert Systems
Forward Chaining • Example of elevator – cont • Fact 1: floor = third • Fact 2: button = second • Fact 3: button = first • There are more than one possible conclusion, i.e., there can be multiple rules matching with the facts. • Conflict resolution needs to be applied to decide which rule to fire. Rules and Expert Systems
Conflict Resolution • Sometimes more than one rule will fire at once, and a conflict resolution strategy must be used to decide which conclusion[s] to use. • Some ideas: • Give rules priorities and to use the conclusion that has the highest priority. • The rule with the longest antecedent is applied. • The rule that matches with the most recently added facts is applied. Rules and Expert Systems
Topics Meta Rules • The rules that determine the conflict resolution strategy are called meta rules. • Meta rules define knowledge about how the system will work. • For example, meta rules might define that knowledge from Expert A is to be trusted more than knowledge from Expert B. • Meta rules are treated by the system like normal rules, but are given higher priority. Rules and Expert Systems
Backward Chaining • In cases where a particular conclusion, i.e., hypothesis, is to be proved, backward chaining can be more appropriate. • Works back from a conclusion towards the original facts. • When a conclusion matches the conclusion of a rule in the database, the antecedents of the rule are compared with facts in the database. • The process looks like a recursion. Rules and Expert Systems
Backward Chaining • Example: • Rule 1 A B -> C • Rule 2 A -> D • Rule 3 C D -> E • Rule 4 A E F -> G • Rule 5 A E -> H • Rule 6 D E H -> I • Fact 1 A • Fact 2 B • Fact 3 F • [Q] What do we want to do with the above databases? • Goal to prove H • [Q] Do we humans use Forward Chaining or Backward Chaining? Rules and Expert Systems
Topics Backward Chaining Using forward chaining: Facts Rules triggered Rule fired A, B, F 1, 2 1 A, B, C, F 2 2 A, B, C, D, F 3 3 A, B, C, D, E, F 4, 5 4 A, B, C, D, E, F, G 5 5 A, B, C, D, E, F, G, H 6 STOP Using backward chaining: Facts Goals Matching rules A, B, F H 5 A, B, F E 3 A, B, F (C, D) 1 A, B, C, F (T, D) 2 A, B, C, D, F (T, T) STOP • Rule 1 A B -> C • Rule 2 A -> D • Rule 3 C D -> E • Rule 4 A E F -> G • Rule 5 A E -> H • Rule 6 D E H -> I • Fact 1 A • Fact 2 B • Fact 3 F • Goal to prove H • [Q] Which one is better??? • [Q] Use both of them??? • [Q] Prove or disprove G. Rules and Expert Systems
Types of Expert Systems • Rule-Based Systems • The 70s and 80s • Neural Networks • Belief (Bayesian) Networks • Blackboard Systems • Case-Based Reasoning • ... Rules and Expert Systems
Architecture of Expert Systems • End users; domain experts; knowledge engineers • An expert system uses expert knowledge derived from human experts to diagnose illnesses, provide recommendations and solve other problems. Rules and Expert Systems
Architecture of Expert Systems • Knowledge base: database of rules (domain knowledge). • Explanation system: explains the decisions the system makes. • User Interface: the means by which the end user interacts with the expert system. • Knowledge base editor: allows domain experts or knowledge engineers to edit the information in the knowledge base. • Inference engine Rules and Expert Systems
Expert System Shells • The part of an expert system that does not contain any domain specific or case specific knowledge is the expert system shell. • A single expert system shell can be used to build a number of different expert systems. • Examples of an expert system shell are CLIPS (C Language Interpreted Production System) and JESS (The Java Expert System Shell) Rules and Expert Systems
Example: CLIPS • CLIPS is C Language Integrated Production System – an expert system shell. • CLIPS uses a LISP-like notation to enter rules. Rules and Expert Systems
Knowledge Engineering • A knowledge engineer takes knowledge from experts and inputs it into the expert system. • A knowledge engineer will usually choose which expert system shell to use. • The knowledge engineer is also responsible for entering meta-rules. • [Q] Is it the most difficult part in the development of an expert system? Rules and Expert Systems
Backward Chaining in Expert Systems • A common method for building expert systems is to use a rule-based system with backward chaining. • Typically a user enters a set of facts into the system, and • the system tries to see if it can prove any of the possible hypotheses using these facts. • In some cases it will need additional facts, in which case the system will often ask the user questions, to ascertain facts that could enable further rules to fire. • Backward chaining is often used in expert systems that are designed for medical diagnosis. Rules and Expert Systems
Backward Chaining in Expert Systems • Algorithm: For each hypothesis, H: • If H is in the facts database, it is proved. • Otherwise, if H can be determined by asking a question, then enter the user’s answer in the facts database. Hence, it can be determined whether H is true or false, according to the user’s answer. • Otherwise, find a rule whose conclusion is H. Now apply this algorithm to try to prove this rule’s antecedents. recursion • If none of the above applies, we have failed to prove H. Rules and Expert Systems
Backward Chaining in Expert Systems • Usually backward chaining is used in conjunction with forward chaining. • Forward chaining to derive new facts and asks questions in order to carry out its backward chaining analysis. • E.g., • Rule 1: IF tired and headache THEN diagnose glandular fever • Rule 2: IF tired and sore throat THEN diagnose tonsillitis • Fact: headache • => Forward chaining -> Hypothesis 1: G.F. -> backward chaining • => ask if tired Rules and Expert Systems
Example: CYC • A frame based production system. • Uses a database of over 1,000,000 facts and rules, encompassing all fields of human knowledge. • CYC can answer questions about all kinds of knowledge in its database, and can even understand analogies, and other complex relations. Rules and Expert Systems
Topics The Last Questions • [Q] Which part is difficult to implement? • [Q] Have expert systems been successful? • [Wikipedia] The expert system has a major flaw which explains its low success although the principle has existed for 70 years: knowledge collection and interpretation into rules, the knowledge engineering. • Most developers have no method to perform this task. • They work manually what opens to many possibilities for errors. • [Q] How to handle uncertainty and ambiguity? • E.g., IF name is “Bob” weather is cold THEN tell “Bob” ‘Wear a coat’ Rules and Expert Systems