Chapter 9. Rules and Expert Systems Fall 2013 Comp3710 Artificial Intelligence Computing Science...

32
Chapter 9. Rules and Expert Systems Fall 2013 Comp3710 Artificial Intelligence Computing Science Thompson Rivers University

description

TRU-COMP3710 Rules and Expert Systems3 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

Transcript of Chapter 9. Rules and Expert Systems Fall 2013 Comp3710 Artificial Intelligence Computing Science...

Page 1: Chapter 9. Rules and Expert Systems Fall 2013 Comp3710 Artificial Intelligence Computing Science Thompson Rivers University.

Chapter 9.Rules and Expert Systems

Fall 2013

Comp3710 Artificial IntelligenceComputing Science

Thompson Rivers University

Page 2: Chapter 9. Rules and Expert Systems Fall 2013 Comp3710 Artificial Intelligence Computing Science Thompson Rivers University.

TRU-COMP3710 Rules and Expert Systems 2

Course Outline Part I – Introduction to Artificial Intelligence Part II – Classical Artificial Intelligence

Knowledge Representation Searching 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

Page 3: Chapter 9. Rules and Expert Systems Fall 2013 Comp3710 Artificial Intelligence Computing Science Thompson Rivers University.

TRU-COMP3710 Rules and Expert Systems 3

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

Page 4: Chapter 9. Rules and Expert Systems Fall 2013 Comp3710 Artificial Intelligence Computing Science Thompson Rivers University.

TRU-COMP3710 Rules and Expert Systems 4

Chapter Outline1. Rules for Knowledge Representation2. Rule-Based Systems3. Forward Chaining4. Backward Chaining5. Rule-Based Expert Systems

Page 5: Chapter 9. Rules and Expert Systems Fall 2013 Comp3710 Artificial Intelligence Computing Science Thompson Rivers University.

TRU-COMP3710 Rules and Expert Systems 5

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

Page 6: Chapter 9. Rules and Expert Systems Fall 2013 Comp3710 Artificial Intelligence Computing Science Thompson Rivers University.

TRU-COMP3710 Rules and Expert Systems 6

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 2E mc

Page 7: Chapter 9. Rules and Expert Systems Fall 2013 Comp3710 Artificial Intelligence Computing Science Thompson Rivers University.

TRU-COMP3710 Rules and Expert Systems 7

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

Page 8: Chapter 9. Rules and Expert Systems Fall 2013 Comp3710 Artificial Intelligence Computing Science Thompson Rivers University.

TRU-COMP3710 Rules and Expert Systems 8

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

Topics

Page 9: Chapter 9. Rules and Expert Systems Fall 2013 Comp3710 Artificial Intelligence Computing Science Thompson Rivers University.

TRU-COMP3710 Rules and Expert Systems 9

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

Topics

Page 10: Chapter 9. Rules and Expert Systems Fall 2013 Comp3710 Artificial Intelligence Computing Science Thompson Rivers University.

TRU-COMP3710 Rules and Expert Systems 10

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

Page 11: Chapter 9. Rules and Expert Systems Fall 2013 Comp3710 Artificial Intelligence Computing Science Thompson Rivers University.

TRU-COMP3710 Rules and Expert Systems 11

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

Page 12: Chapter 9. Rules and Expert Systems Fall 2013 Comp3710 Artificial Intelligence Computing Science Thompson Rivers University.

TRU-COMP3710 Rules and Expert Systems 12

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 = TTHEN remember to goto first floor

Fact 1: floor = second (<- first) Fact 2: button = Fact 3: day = Tuesday Fact 4: going to third floor = T

Page 13: Chapter 9. Rules and Expert Systems Fall 2013 Comp3710 Artificial Intelligence Computing Science Thompson Rivers University.

TRU-COMP3710 Rules and Expert Systems 13

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

Page 14: Chapter 9. Rules and Expert Systems Fall 2013 Comp3710 Artificial Intelligence Computing Science Thompson Rivers University.

TRU-COMP3710 Rules and Expert Systems 14

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 = TTHEN 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?

Page 15: Chapter 9. Rules and Expert Systems Fall 2013 Comp3710 Artificial Intelligence Computing Science Thompson Rivers University.

TRU-COMP3710 Rules and Expert Systems 15

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.

Page 16: Chapter 9. Rules and Expert Systems Fall 2013 Comp3710 Artificial Intelligence Computing Science Thompson Rivers University.

TRU-COMP3710 Rules and Expert Systems 16

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:

1. Give rules priorities and to use the conclusion that has the highest priority.

2. The rule with the longest antecedent is applied.3. The rule that matches with the most recently added facts is applied.

Page 17: Chapter 9. Rules and Expert Systems Fall 2013 Comp3710 Artificial Intelligence Computing Science Thompson Rivers University.

TRU-COMP3710 Rules and Expert Systems 17

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.

Topics

Page 18: Chapter 9. Rules and Expert Systems Fall 2013 Comp3710 Artificial Intelligence Computing Science Thompson Rivers University.

TRU-COMP3710 Rules and Expert Systems 18

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.

Page 19: Chapter 9. Rules and Expert Systems Fall 2013 Comp3710 Artificial Intelligence Computing Science Thompson Rivers University.

TRU-COMP3710 Rules and Expert Systems 19

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?

Page 20: Chapter 9. Rules and Expert Systems Fall 2013 Comp3710 Artificial Intelligence Computing Science Thompson Rivers University.

TRU-COMP3710 Rules and Expert Systems 20

Backward Chaining 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???

Using forward chaining:Facts Rules triggered Rule firedA, B, F 1, 2 1A, B, C, F 2 2A, B, C, D, F 3 3A, B, C, D, E, F 4, 5 4A, B, C, D, E, F, G 5 5A, B, C, D, E, F, G, H 6 STOP

Using backward chaining:Facts Goals Matching

rulesA, B, F H 5A, B, F E 3A, B, F C, D 1A, B, C, F D 2A, B, C, D, F STOP

Topics

Page 21: Chapter 9. Rules and Expert Systems Fall 2013 Comp3710 Artificial Intelligence Computing Science Thompson Rivers University.

TRU-COMP3710 Rules and Expert Systems 21

Types of Expert Systems Rule-Based Systems in this textbook

The 70s and 80s

Neural Networks Belief (Bayesian) Networks Blackboard Systems Case-Based Reasoning ...

Page 22: Chapter 9. Rules and Expert Systems Fall 2013 Comp3710 Artificial Intelligence Computing Science Thompson Rivers University.

TRU-COMP3710 Rules and Expert Systems 22

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.

Page 23: Chapter 9. Rules and Expert Systems Fall 2013 Comp3710 Artificial Intelligence Computing Science Thompson Rivers University.

TRU-COMP3710 Rules and Expert Systems 23

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

Page 24: Chapter 9. Rules and Expert Systems Fall 2013 Comp3710 Artificial Intelligence Computing Science Thompson Rivers University.

TRU-COMP3710 Rules and Expert Systems 24

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)

Page 25: Chapter 9. Rules and Expert Systems Fall 2013 Comp3710 Artificial Intelligence Computing Science Thompson Rivers University.

TRU-COMP3710 Rules and Expert Systems 25

Example: CLIPS CLIPS is C Language Integrated

Production System – an expert system shell.

CLIPS uses a LISP-like notation to enter rules.

Page 26: Chapter 9. Rules and Expert Systems Fall 2013 Comp3710 Artificial Intelligence Computing Science Thompson Rivers University.

TRU-COMP3710 Rules and Expert Systems 26

The Rete Algorithm One potential problem with expert systems is the number of

comparisons that need to be made between rules and facts in the database, when there are many rules and facts.

[Q] How to solve? Any good data structure?

A rete is a directed, acyclic, rooted graph (a sort of tree). A path from the root node to a leaf represents the left hand side of a

rule. Each node stores details of which facts have been matched so far. As facts are changed, the changes (adding, updating, deleting) are

propagated through the tree. This makes an efficient way for expert systems to deal with

environments which change often.

Page 27: Chapter 9. Rules and Expert Systems Fall 2013 Comp3710 Artificial Intelligence Computing Science Thompson Rivers University.

TRU-COMP3710 Rules and Expert Systems 27

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?

Page 28: Chapter 9. Rules and Expert Systems Fall 2013 Comp3710 Artificial Intelligence Computing Science Thompson Rivers University.

TRU-COMP3710 Rules and Expert Systems 28

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.

Page 29: Chapter 9. Rules and Expert Systems Fall 2013 Comp3710 Artificial Intelligence Computing Science Thompson Rivers University.

TRU-COMP3710 Rules and Expert Systems 29

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.

If none of the above applies, we have failed to prove H.

Page 30: Chapter 9. Rules and Expert Systems Fall 2013 Comp3710 Artificial Intelligence Computing Science Thompson Rivers University.

TRU-COMP3710 Rules and Expert Systems 30

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 gladular fever Rule 2: IF tired and sore throat THEN diagnose tonsilitis Fact: headache => Forward chainging -> Hypothesis 1: G.F. -> backward

chaining => ask if tired

Page 31: Chapter 9. Rules and Expert Systems Fall 2013 Comp3710 Artificial Intelligence Computing Science Thompson Rivers University.

TRU-COMP3710 Rules and Expert Systems 31

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.

Page 32: Chapter 9. Rules and Expert Systems Fall 2013 Comp3710 Artificial Intelligence Computing Science Thompson Rivers University.

TRU-COMP3710 Rules and Expert Systems 32

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? E.g., IF name is “Bob” weather is cold THEN tell “Bob” ‘Wear a coat’

Topics