Chapter 9 Rules and Expert Systems Lora Streeter

  • Slides: 24
Download presentation
Chapter 9: Rules and Expert Systems Lora Streeter

Chapter 9: Rules and Expert Systems Lora Streeter

Rules for Knowledge Representation IF. . . THEN. . . rules can be used

Rules for Knowledge Representation IF. . . THEN. . . rules can be used to represent knowledge about objects IF A THEN B or A→B For example: IF name is “Bob” AND weather is cold THEN tell Bob 'Wear a coat'

Rule-Based (or Production) Systems Provide recommendations or diagnoses Determine a course of action in

Rule-Based (or Production) Systems Provide recommendations or diagnoses Determine a course of action in a particular situation Solve a particular problem Consists of: A database of rules (aka knowledge base) A database of facts An interpreter, or inference engine

Rule Based Systems Knowledge base = set of rules that represent the system's knowledge

Rule Based Systems Knowledge base = set of rules that represent the system's knowledge Database of facts = inputs to the system that are used to derive conclusions or to cause actions Interpreter = controls the process of arriving at conclusions

Forward Chaining aka data-driven reasoning Start reasoning from a set of data and ends

Forward Chaining aka data-driven reasoning Start reasoning from a set of data and ends up at the goal Check facts in the fact database and compare to rule database When they match up, that rule is triggered, and its' conclusion added to the facts database

Forward Chaining Example Rule 1: IF on first floor and button is pressed on

Forward Chaining Example Rule 1: IF on first floor and button is pressed on first floor, THEN open door Rule 2: IF on first floor AND button is pressed on second floor, THEN go to second floor Rule 3: IF on first floor AND button is pressed on third floor, THEN go to third floor Rule 4: IF on second floor AND button is pressed on first floor AND already going to third floor, THEN remember to go to first floor later.

Forward Chaining Example We start with these facts in our database: Fact 1: At

Forward Chaining Example We start with these facts in our database: Fact 1: At first floor Fact 2: Button pressed on third floor Fact 3: Today is Tuesday The system see that this matches Rule 3 (IF on first floor AND button is pressed on third floor, THEN go to third floor) The conclusion, “Go to third floor” is added to the database of facts Fact 3 matches none of our rules and is ignored

Forward Chaining Example Later in the day, our facts database now contains the following

Forward Chaining Example Later in the day, our facts database now contains the following information: Fact 1: At first floor Fact 2: Button pressed on second floor Fact 3: Button pressed on third floor Both rules 2 and 3 are triggered! We need to use some conflict resolution to sort this out

Conflict Resolution Consider these rules: IF it is cold, THEN wear a coat IF

Conflict Resolution Consider these rules: IF it is cold, THEN wear a coat IF it is cold, THEN stay at home IF it is cold, THEN turn on the heat Now if we have one fact in our database: It is cold. Clearly three possible outcomes can be derived All three conclusions could easily be followed, but. . .

Conflict Resolution . . . many times conclusions are incompatible! e. g. when prescribing

Conflict Resolution . . . many times conclusions are incompatible! e. g. when prescribing medicines to patients One solution: rules are given priority levels If a conflict arises, highest priority wins IF patient has pain, THEN prescribe painkillers priority 10 IF patient has chest pain, THEN treat for heart disease priority 100

Conflict Resolution Another method is the longest-matching strategy IF patient has pain, THEN prescribe

Conflict Resolution Another method is the longest-matching strategy IF patient has pain, THEN prescribe painkiller IF patient has chest pain AND patient is over 60 AND patient has history of heart conditions, THEN take to emergency room The more specific match would be the rule that fires A further method is to fire the rule that has matched the facts most recently added to the database.

Chaining Forward chaining applies rules/facts to deduce whatever conclusions can be derived Don't know

Chaining Forward chaining applies rules/facts to deduce whatever conclusions can be derived Don't know what conclusions you're trying to prove Can be inefficient by proving conclusions that aren't interesting If we're trying to prove a single specific conclusion, backward chaining is more appropriate

Backward Chaining Start from a conclusion (hypothesis) we want to prove Show it can

Backward Chaining Start from a conclusion (hypothesis) we want to prove Show it can be reached with rules and facts in the database The conclusion we're aiming for is called a goal Reasoning in this way is known as goal-driven reasoning

Forward vs. Backward Chaining Rule 1: A ^ B → C Fact 1: A

Forward vs. Backward Chaining Rule 1: A ^ B → C Fact 1: A Rule 2: A → D Fact 2: B Rule 3: C ^ D → E Fact 3: F Rule 4: B ^ E ^ F → G Rule 5: A ^ E → H Rule 6: D ^ E ^ H → I Goal: Prove H As for conflict resolution, fire the rules in the order they appear in the database

Forward Chaining Rule 1: A^B → C Rule 2: A → D Rule 3:

Forward Chaining Rule 1: A^B → C Rule 2: A → D Rule 3: C^D → E Rule 4: B^E^F → G Rule 5: A^E → H Rule 6: D^E^H → I Facts: A, B, F Goal: H

Backward Chaining Rule 1: A^B → C Rule 2: A → D Rule 3:

Backward Chaining Rule 1: A^B → C Rule 2: A → D Rule 3: C^D → E Rule 4: B^E^F → G Rule 5: A^E → H Rule 6: D^E^H → I Facts: A, B, F Goal: H

Forward vs Backward Chaining Used in many situations A set of facts is available

Forward vs Backward Chaining Used in many situations A set of facts is available Conclusion is not already known Many possible conclusions Few (or even just one) conclusion Many possible facts Not very many are necessarily relevant to the conclusion

Rule-Based Expert Systems Model the behavior of an expert in some field Designed to

Rule-Based Expert Systems Model the behavior of an expert in some field Designed to use the same rules that the expert would use to draw conclusions Involve a number of people End-user: the person who needs the system Knowledge engineer: designer of rules Domain expert: explain to the knowledge engineer how they go about diagnosing the problems

Architecture of an Expert System A typical expert system architecture

Architecture of an Expert System A typical expert system architecture

Architecture of an Expert System Knowledge base has domain specific knowledge represented by rules

Architecture of an Expert System Knowledge base has domain specific knowledge represented by rules Explanation system shows how the inference engine arrived at its conclusions Essential if the advice is of critical nature, such as with a medical diagnosis system Fact database has case-specific data Inference engine uses the rules and facts to derive conclusions Knowledge base editor used to update the information contained in the system

The Rete Algorithm Problems with an expert system? Lots of comparisons between rules and

The Rete Algorithm Problems with an expert system? Lots of comparisons between rules and facts in the database Solution? The Rete Algorithm, an efficient method for solving impractical rule/fact comparisons

The Rete Algorithm Is a directed, acyclic, rooted graph Each path from the root

The Rete Algorithm Is a directed, acyclic, rooted graph Each path from the root node to a leaf in the tree represents the left-hand side of the rule aka a search tree Stores details of which facts have been matched by rules at that point As facts are changed, the new facts are propagated down, changing node info accordingly May add new fact, change info about an old fact, or delete an old fact

The Rete Algorithm Depends on the principle that when using forward chaining, the object

The Rete Algorithm Depends on the principle that when using forward chaining, the object values change relatively infrequently Few changes have to be made to the tree Not particularly efficient where objects are continually changing

Rules and Expert Systems The End

Rules and Expert Systems The End