Sei sulla pagina 1di 30

241-320 Design Architecture and Engineering for Intelligent System Suntorn Witosurapot

Contact Address: Phone: 074 287369 or Email: wsuntorn@coe.psu.ac.th

December 2010

Lecture 12: Knowledge Representation and Reasoning Part 3 (Rule based Systems)

Preview:
So far, we have learned how to represent knowledge in a relatively declarative, static way (as a bunch of things that are true) via PL, Semantic Nets or Frames. Here, we will learn how to represent knowledge in terms of a bunch of rules that tell you what you should do or what you could conclude in different situations.
KR can be classified into 3 categories : 1. Logic-based representation ()
Propositional Logic Semantic Networks, Frames

2. Object-based representation () 3. Rule-based representation ()


241-320 Design Architecture & Engineering for Intelligent System

This lecture
3

Knowledge Representation and Reasoning - part 3 (Rule-based)

Preview: (cont.)
These rules can be called Production Rules Expert systems that use a knowledge base consisting of production rules are called rule-based systems that 1) can express heuristic knowledge Heuristics vs. rigid rules Heuristic: A rule of thumb; a guideline. Most domain knowledge is in the form of heuristics, rather than rigid rules Ex: , rather than: > 10 =
241-320 Design Architecture & Engineering for Intelligent System

Knowledge Representation and Reasoning - part 3 (Rule-based)

Preview: (cont.)
2) Can capture a domain experts knowledge in propositional, qualitative form Procedural vs. propositional Most programming languages are procedural: first do this, then this, then this Most human expert knowledge is propositional: If A is true, then B is true So, conventional programming languages are not necessarily the most intuitive way to represent domain knowledge.
241-320 Design Architecture & Engineering for Intelligent System

Knowledge Representation and Reasoning - part 3 (Rule-based)

Preview: (cont.)
3) Can capture a domain experts knowledge in propositional, qualitative form Quantitative vs. qualitative Humans tend to represent their knowledge qualitatively, e.g. John is tall, but Jim is taller. As opposed to quantitative: Johns height is 65. Jims height is 68. So, probably a good idea to represent expert knowledge that way.
Knowledge Representation and Reasoning - part 3 (Rule-based)

241-320 Design Architecture & Engineering for Intelligent System

Preview: (cont.)
4) Can separate the knowledge from the reasoning (inference) and from the specific facts 5) easy to understand (i.e. `knowledge' is visible). Reasoning + knowledge + facts Human expertise typically breaks down into: Ability to reason Knowledge about the domain (e.g. migraines) Facts about the particular situation (e.g. this patients symptoms) => Able to Explan the reasoning (e.g. Why do you think I have a
migraine? Well, because you have a frequent, intense pain in ..)
241-320 Design Architecture & Engineering for Intelligent System

Knowledge Representation and Reasoning - part 3 (Rule-based)

Outline
Rule-Based Systems Production Rules vs. Logic Advantages & disadvantages Visualising the rule base Reasoning with a rule base Forward chaining Backward chaining

241-320 Design Architecture & Engineering for Intelligent System

Knowledge Representation and Reasoning - part 3 (Rule-based)

Rule-Based Systems
In Logic (and semantic nets) we represent knowledge in a declarative, static way - as some facts and rules that are true. Rules in Logic say what is TRUE when some conditions are given. Rule-based systems are based on rules that say what to do, given various conditions. IF <this is the case> THEN <do this> A special engine will take control when rules are invoked.
241-320 Design Architecture & Engineering for Intelligent System

Knowledge Representation and Reasoning - part 3 (Rule-based)

Production Rules vs Logic


In simple examples, rules are very similar to the relation syntax ( ) in logic (meaning imply), but less formal IF <antecedent> THEN <consequent> E.g. IF fish is floating THEN fish is dead Alternate syntax: Fish is floating fish is dead Less concern about precise semantics & sound inference More about programmed operations based on the knowledge

241-320 Design Architecture & Engineering for Intelligent System

Knowledge Representation and Reasoning - part 3 (Rule-based)

10

Production Rules vs Logic (cont.)


The antecedent part can be multiple in rules Rules: IF <antecedent> THEN <consequent> A rule that contains two clauses in the antecedent connected by logical OR can re-written as two rules IF weather is hot OR temperature is high THEN ice-cream sales are high could be re-written as IF weather is hot THEN ice-cream sales are high IF temperature is high THEN ice-cream sales are high
241-320 Design Architecture & Engineering for Intelligent System

Knowledge Representation and Reasoning - part 3 (Rule-based)

11

Check your understanding


Q: Can you explain how the if then pattern in the production rules and in the conditional statements found in conventional programming languages are different? A: Rules in programming language tell you what is TRUE when some conditions are given, but Rules in the production rules tell you what TO DO, given various conditions, since they are just simply represent the knowledge based on heuristics or experiential reasoning.
241-320 Design Architecture & Engineering for Intelligent System

Knowledge Representation and Reasoning - part 3 (Rule-based)

12

Simple Example: Small KBS for weather prediction


R1 IF the ambient temperature is above 35 C THEN the weather is hot R2 IF the relative humidity is greater than 65% THEN the atmosphere is humid R3 IF the weather is hot AND the atmosphere is humid THEN thunderstorms are likely to happen An alternative is to write one rule (R1 & R2 are placed directly in the premise of R3).
However we may wish to use the statements, the weather is hot and the atmosphere is humid, for other purposes in the knowledge base.
241-320 Design Architecture & Engineering for Intelligent System

Knowledge Representation and Reasoning - part 3 (Rule-based)

13

Advantages & disadvantages


Advantages

easy to understand the knowledge `content'. explanation for the reasoning is easily shown i.e. a list of which rules fired (and in which order) during reasoning. maintenance (or modification) is easy, provided the rule base structured well. uncertainty can incorporated into the knowledge base.
Disadvantages (or limitations)

rule bases can be very large (thousands of rules) rules may not reflect the actual decision making the only structure in the KB is through the rule chaining
241-320 Design Architecture & Engineering for Intelligent System

Knowledge Representation and Reasoning - part 3 (Rule-based)

14

Outline
Rule-Based Systems Production Rules vs. Logic Advantages & disadvantages Visualising the rule base Reasoning with a rule base Forward chaining Backward chaining

241-320 Design Architecture & Engineering for Intelligent System

Knowledge Representation and Reasoning - part 3 (Rule-based)

15

Visualising the rule base


An and/or graph visualises the rule base as a tree structure The nodes are facts [as expressed by the rule clauses] and the lines (or arcs) represent condition-action pairs [i.e. where one node appears in the antecedent (LHS)
and the other in the consequent (RHS) of a rule].

A logical AND between any two or more rule clauses is shown by joining the arcs. If there is no join then a logical OR is assumed. To simplify the structure of the graph, the nodes will be represented abstractly [using letters etc].
241-320 Design Architecture & Engineering for Intelligent System

Knowledge Representation and Reasoning - part 3 (Rule-based)

16

Visualising the rule base: Example 1


The and/or graph for the following rule base (1) IF A and B and C THEN E (2) IF D THEN F (3) IF E and F and G THEN H

goal

241-320 Design Architecture & Engineering for Intelligent System

Knowledge Representation and Reasoning - part 3 (Rule-based)

17

Visualising the rule base: Example 2


(1) (2) (3) (4) (5) (6) (7) IF A and B and C THEN D IF A1 and A2 and A3 THEN A IF A11 and A12 THEN A1 IF A21 and A22 THEN A2 IF C1 and C2 and C3 THEN C IF B1 and B2 THEN B IF C21 and C22 THEN C2 Goal D

241-320 Design Architecture & Engineering for Intelligent System

Knowledge Representation and Reasoning - part 3 (Rule-based)

18

Outline
Rule-Based Systems Production Rules vs. Logic Advantages & disadvantages Visualising the rule base Reasoning with a rule base Forward chaining Backward chaining

241-320 Design Architecture & Engineering for Intelligent System

Knowledge Representation and Reasoning - part 3 (Rule-based)

19

Reasoning with a rule base


How are the rules processed? In general, the pattern-matching cycles is performed For each cycle .... the left-hand side(s) of the rules are compared with the current facts. when all conditions of a rule is met, (called it is 'fired) and the value of the conclusion (action part) is added to working memory. on the next cycle, further rules may fire and so the process goes on. The issue becomes What strategies and controls should be in place to guide rule selection?
241-320 Design Architecture & Engineering for Intelligent System

Knowledge Representation and Reasoning - part 3 (Rule-based)

20

Reasoning with a rule base (cont.)


Two main control strategies: Forward chaining ( ) Data Driven Search starts with the facts, and sees what rules apply (and hence what should be done) given the facts. Backward chaining ( ) Goal Driven Search starts with something to find out, and looks for rules that will help in answering it given current fact (or requiring new inputs, eg. Diagnostic tests).
241-320 Design Architecture & Engineering for Intelligent System

Knowledge Representation and Reasoning - part 3 (Rule-based)

21

Forward chaining: Example visualization


An example (1) IF A THEN C (2) IF A and B THEN D (3) IF D and B THEN G (4) IF D and C THEN F (5) IF C THEN E (6) IF E and F THEN H (7) IF F and G and K THEN J (8) IF F and G THEN I Note: H, I and J are root nodes A, B and K are `inputs' E A D B G C F I H

J K

241-320 Design Architecture & Engineering for Intelligent System

Knowledge Representation and Reasoning - part 3 (Rule-based)

22

Forward chaining:
Advantages & DisAdvantage
Good for answering What is the situation? kind of questions (e.g. What kind of animal is this?) Fires a lot of rules, and generates a lot of facts that might be irrelevant to the problem

241-320 Design Architecture & Engineering for Intelligent System

Knowledge Representation and Reasoning - part 3 (Rule-based)

23

Backward Chaining (goal driven search)


Same rules/facts may be processed differently, using backward chaining engine. Start with possible hypothesis (e.g. The patient has type I diabetes) and tries to prove it Find rules that consequents that match the goal. If antecedents match the facts, stop. If not, make the antecedents the new subgoals, and repeat.

241-320 Design Architecture & Engineering for Intelligent System

Knowledge Representation and Reasoning - part 3 (Rule-based)

24

Backward chaining: Example visualization


Using example 2
(1) (2) (3) (4) (5) (6) (7) IF A and B and C THEN D IF A1 and A2 and A3 THEN A IF A11 and A12 THEN A1 IF A21 and A22 THEN A2 IF C1 and C2 and C3 THEN C IF B1 and B2 THEN B IF C21 and C22 THEN C2

The graph clearly shows that fact D is root of the tree. Hence, the objective is to determine this fact. Note also that the leaf nodes (A11, A12, A21, A22, A3, B1, B2, C1, C21, C22, C3) represent `facts' that cannot be inferred from the rule base but instead have to be 'asked for' (in other words they are inputs)
241-320 Design Architecture & Engineering for Intelligent System

Knowledge Representation and Reasoning - part 3 (Rule-based)

25

Applications
Backward chaining systems have been fairly widely used in E.g., medical expert systems, where start with set of hypotheses on possible diseases - try to prove each one, asking additional diagnostic questions when fact is unknown.

241-320 Design Architecture & Engineering for Intelligent System

Knowledge Representation and Reasoning - part 3 (Rule-based)

26

Backward chaining:
Advantages & DisAdvantage
Efficient way to prove or disprove a particular hypothesis. Sometimes more efficient with a small set of hypotheses Less efficient than forward chaining if large number of hypotheses

241-320 Design Architecture & Engineering for Intelligent System

Knowledge Representation and Reasoning - part 3 (Rule-based)

27

Forward vs. backward chaining


Forward chaining best for analysis and interpretation (e.g. Determination of molecular structure of soil sample). Backward chaining best for diagnosis (e.g. Diagnoses of infectious blood diseases).

241-320 Design Architecture & Engineering for Intelligent System

Knowledge Representation and Reasoning - part 3 (Rule-based)

28

Forward + backward chaining


Most real expert systems use both Primary inference is backward chaining, and switches to forward chaining when new data is added This aims to minimizes pointless queries to user (backward chaining), but exploits any facts that are acquired

241-320 Design Architecture & Engineering for Intelligent System

Knowledge Representation and Reasoning - part 3 (Rule-based)

29

Reading 6 (Resoning and


Inference)
6.2

241-320 Design Architecture & Engineering for Intelligent System

Knowledge Representation and Reasoning - part 3 (Rule-based)

30

Potrebbero piacerti anche