Professional Documents
Culture Documents
Rete 3
Rete 3
Rete 3
Lecture 4
Knowledge level:
1.4
concerned with particular tasks and/or goals. concerned with the meaning of the symbols. What knowledge is needed for the task? How can the knowledge be used?
Ai:
conditions (situation, antecedent, LHS) match against database (working memory) obtain from user, or derive from other rules
Knowledge level:
expert-friendly? user-friendly? is it easy to analyse or formalise?
B:
conclusion (action, consequent, RHS) add to working memory more general: an action, e.g. removing something from working memory (situation-action rule)
3 4
(oorzaak-gevolg)
(handeling)
Logical relation
IF temp > 37 THEN fever
(by definition)
6
Advantages
many applications using the same tools flexibility
Disadvantage
source of confusion: e.g. exception handling, abduction, left-to-right ...
PROLOG
Resolution: A V B , A
B
Using Rules
Matching of patterns
check whether a rule is applicable forward reasoning: when its conditions are satisfied backward reasoning: when its conclusion is a (sub)goal
Conflict Resolution
Rule
Execution
Example: Rules
1 IF Shape=long & Color=(green or yellow) THEN Fruit=banana 2 IF Shape=(round or oblong) & Diam>4 THEN Fruitclass=vine 3 IF Shape=round & Diam<4 THEN Fruitclass=tree 4 IF Seedcount=1 THEN Seedclass=stonefruit 5 IF Seedcount>1 THEN Seedclass=multiple 6 IF Fruitclass=vine & Color=green THEN Fruit=watermelon 7 IF Fruitclass=vine & Surface=smooth & Color=yellow THEN Fruit=honeydew 8 IF Fruitclass=vine & Surface=rough & Color=tan THEN Fruit=cantaloupe 9 IF Fruitclass=tree & Color=orange & Seedclass=stonefruit & Diam 3 THEN Fruit=peach 10 IF Fruitclass=tree & Color=orange & Seedclass=multiple THEN Fruit=orange 11 IF Fruitclass=tree & Color=red & Seedclass=stonefruit THEN Fruit=cherry 12 IF Fruitclass=tree & Color=orange & Seedclass=stonefruit & Diam < 3 THEN Fruit=abricot 13 IF Fruitclass=tree & Color=(red or yellow or green) & Seedclass=multiple THEN Fruit=apple 14 IF Fruitclass=tree & Color=purple & Seedclass=stonefruit THEN Fruit=plum
Backward Chaining
start from the condition to test (goal-driven, top-down) apply rules with usable conclusion condition of applied rule is used for selecting another rule
IF A THEN B + IF B THEN C + C? B? A?
13
14
9 (Fruit = apricot?):
9a: Fruitclass = tree? 3
3a: Shape = round? ok 3b: Diameter < 4? ok
6 (Fruit = watermelon?):
Fruitclass = vine? 2
2a: Shape = round? ok 2b: Diameter > 4? fail
Reasoning:
{3, 5} {5} {10} [{applicable rules}
10 (Fruit = orange?):
10a: Fruitclass = tree ok 10b: Color = orange? ok 10c: Seedclass = multiple?
5: Seedcount > 1? ok
7 (Fruit = honeydew?):
Fruitclass = vine? fail
8 (Fruit = cantaloupe?):
Fruitclass = vine? fail
Matching
Fact and (simple) condition match if
condition identical to fact, or condition and fact can be unified by substituting variables Example: IF bird(X) THEN fly(X) bird(Tweety) {X=Tweety}. fly(Tweety) Substitute Tweety for X, so bird(X) matches bird(Tweety),
Matching (2)
Matching complex conditions with connectives:
IF A & B THEN C applicable if A and B match with facts IF A B THEN C applicable if A or B or both match facts
Execution
Forward
Add (substitution instances of) conclusions of applied rules as new facts. Perform the actions of applied rules. Stop if no new rule applicable.
Conflict-Resolution
Examples of conflict-resolution strategies select first applicable rule prefer rules with most conditions (most specific) prefer rules which match most recently added facts select rule with highest priority select rule with highest certainty value reject rules with certainty below some threshold or combinations
19 20
Backward
Replace goal by conditions of applied rule: new (sub)goals. Remove goals matching with facts. Backtrack if some goal cannot be replaced/removed. Stop if no goal is left.
Effects of Conflict-Resolution
Some conflict-resolution strategies only influence
the order in which rules are executed and conclusions are derived.
example: preference for most specific rules
Some Variations
(not used very often)
Backward:
only feasible for a few possible conclusions to reach the goal, typically much data needs to be available (by searching the systems database or questioning the user) focussed
23
Fruit=banana Fruitclass=vine
Forward:
Backward: Classification
determine type/class on basis of properties
Backward:
25
FIRST: generate hypotheses on basis of available data THEN: test hypotheses on basis of acquiring data
26
test hypothesis
Inconsistent rules
{ IF A THEN B, IF B THEN C, IF A & D THEN C }
hypothesis refinement
Unreachable conditions
Repair space
repair + costs
27
Unusable conclusions
28
If I put sugar in my coffee, the coffee will taste sweet, ... provided there is no diesel in my coffee
29
Explanation Generation
U: facts: {Color=orange, Shape = round, Diam = 1.5, seedcount =10 } goal: fruit =X ? S: Fruit = Orange. U: How come? (How questions produce backwards trace.) S: by rule 10 Fruit = Orange, if Fruitclass = tree & Color=orange & seedclass=multiple, and by rule 3 Fruitclass = tree, if Shape = round and Diam < 4, and by rule 5 Seedclass = multiple, if Seedcount > 1, and Color=orange, Shape = round, Diam = 1.5, seedcount=10 are given. U: S: U: S: What kind of fruit is this? (goal: fruit = X ?) Is the shape of the fruit round? (question: Shape=round ?) Why do you ask? (Why questions produce forwards trace.) Because by rule 3 if its shape is round and its diameter is smaller then 4, then it grows on a tree, and by rule 10 if it grows on a tree and its color is orange and it produces many seeds, then it is an Orange. (linguistic output by NL generator) So, is the shape of the fruit round?
31
Problem: many items in WM & many LHSs in rules SO: avoid iterating over WM How?
structural overlap: often the same pattern re-occurs in LHS of many rules temporal redundancy: firing a rule only changes few facts, and few rules are affected by those changes.
RETE: Example
FACTS (has-goal e1 simplify) (expression e1 0 + 3) (has-goal e2 simplify) (expression e2 0 + 5) (has-goal e3 simplify) (expression e3 0 * 2) RULES (R1 (has-goal ?x simplify) (expression ?x 0 + ?y) ==>....) (R2 (has-goal ?x simplify) (expression ?x 0 * ?y) ==>....)
3 one-input nodes
has-goal, expression *, expression +
2 two-input nodes
R1 R2
34
RETE: Example
Root
RETE: evaluation
Nave: match all LHSs against all facts in WM Time Complexity: O(R FP )
R = nr rules, F = nr facts in WM, P = av nr patterns per LHS
X e1 e2 e3
Has-Goal
Expression *
Y 2
Expression +
Time Complexity: O(R F P ) (linear in F) But ... High memory space requirements
R2 X Y e3 2
X Y e1 3 e2 5
R1
35
36
Next Lecture
Reasoning with uncertainty Reasoning with vagueness
Book:
37