rule-based systems: mechanisms & efficiency artificial intelligence cmsc 25000 january 10, 2002

23
Rule-based Systems: Mechanisms & Efficiency Artificial Intelligence CMSC 25000 January 10, 2002

Upload: dwayne-patrick

Post on 29-Jan-2016

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Rule-based Systems: Mechanisms & Efficiency Artificial Intelligence CMSC 25000 January 10, 2002

Rule-based Systems:Mechanisms & Efficiency

Artificial Intelligence

CMSC 25000

January 10, 2002

Page 2: Rule-based Systems: Mechanisms & Efficiency Artificial Intelligence CMSC 25000 January 10, 2002

Agenda

• Rule-based systems– Backward-chaining II:

• Variables, unification, and search

– RETE method:• Relational model: Databases

• Efficient rule-based reasoning

• Conclusions

Page 3: Rule-based Systems: Mechanisms & Efficiency Artificial Intelligence CMSC 25000 January 10, 2002

Rule-based Systems

• Represent knowledge as:– Assertions: (mother-of ?x ?y), (female ?x)– Rules:

• If (parent-of ?x ?y) Antecedent – (female ?x)

• then (mother-of ?x) Consequent

• Manipulate knowledge with:– Rule interpreter:

• Forward-Chain: Rules & assertions => New assertions

• Backward-Chain: Hypothesis (consequent)=>Antecedents

Page 4: Rule-based Systems: Mechanisms & Efficiency Artificial Intelligence CMSC 25000 January 10, 2002

Rule Manipulation w/Variables

• Forward-chaining:– Match antecedents with variables to assertions

WITHOUT variables– Match (bind) variables to constants

• Backward-chaining:– Match hypothesis to consequent

• May contain variables: e.g. (grandparent A ?x)

– Match variables to constants AND variables!– Requires general unification

Page 5: Rule-based Systems: Mechanisms & Efficiency Artificial Intelligence CMSC 25000 January 10, 2002

Backward Chaining with Variables

R1: if (parent ?x ?y) (parent ?y ?z) then (grandparent ?x ?z)

R2: if (father ?v1 ?w1) then (parent ?v1 ?w1)

R3: if (mother ?v2 ?w2) then (parent ?v2 ?w2)

Assertions:(father A B) (mother B C)

Hypothesis: (grandparent A ?m)

(grandparent ?x ?z) ?x:A?z:?m

(parent ?x ?y) (parent ?y ?z)

(parent ?v1 ?w1) (parent ?v2 ?w2)

?x:A?z:?m?y:??

?x:A?z:?m?y:?w1:B

(father ?v1 ?w1)

?x:A:?v1 ?z:?m ?y:??:?w1

(mother ?v2 ?w2)

?x:A:?v1 ?z:?m:?w2 ?y:?w1:?v2:B

(father A B)?x:A:?v1 ?z:?m ?y:?w1:B (mother B C)

?x:A:?v1 ?z:?m:?w2:C ?y:w1:?v2:B

Page 6: Rule-based Systems: Mechanisms & Efficiency Artificial Intelligence CMSC 25000 January 10, 2002

Unification: Variable Renaming

• Matching: (grandparent A ?m) (grandparent ?x ?z)– No problem: bind ?x=A, ?z=?m– If match hypothesis (grandparent A ?y)

• (grandparent ?x ?z) => (parent ?y ?y): Problem!!!

• Just an artefact, though, so

• Without loss of generality, rename variables– if (parent ?x1 ?y1)

• (parent ?y1 ?z1)

– then (grandparent ?x1 ?z1)

Page 7: Rule-based Systems: Mechanisms & Efficiency Artificial Intelligence CMSC 25000 January 10, 2002

Unification: Occurs Check

• How do we unify:

(?z likes ?z) (?y likes (house-of ?x))

Need (?z = ?y) and (?z = (house-of ?x)),

Implies (?y = (house-of ?x)): FINE• Now, how do we unify:

(?z likes ?z) (?x likes (house-of ?x))• Need (?z = ?x) and (?z = (house-of ?x))

– Implies (?x = (house-of ?x)) : problematic.

• In unification, a variable cannot be assigned to an expression where that variable occurs (called the “occurs check”).

Page 8: Rule-based Systems: Mechanisms & Efficiency Artificial Intelligence CMSC 25000 January 10, 2002

RETE Method

• Rule chaining problem: Efficiency!

• For each rule,– For each antecedent,

• For each assignment of variables to assertions

• Assert consequent

– E.g. for grandparent example,• k=2 antecedents, n=4 assertions: 16 steps

– Worst case: n^k!!!!

• Different representation & implementation

Page 9: Rule-based Systems: Mechanisms & Efficiency Artificial Intelligence CMSC 25000 January 10, 2002

(parent ?x ?y) (parent ?y ?z) (grand-parent ?x ?z) (x:A y:B) (y:A z:B) conflict in y (y:A z:C) conflict in y (y:B z:D) (x:A y:B z:D) (y:C z:E) conflict in y

(x:A y:C) (y:A z:B) conflict in y (y:A z:C) conflict in y (y:B z:D) conflict in y (y:C z:E) (x:A y:C z:E)

(x:B y:D) (y:A z:B) conflict in y (y:A z:C) conflict in y (y:B z:D) conflict in y (y:C z:E) conflict in y

(x:C y:E) (y:A z:B) conflict in y (y:A z:C) conflict in y (y:B z:D) conflict in y (y:C z:E) conflict in y

Forward Chaining with variables IF (parent ?x ?y) (parent A B) (parent ?y ?z) (parent A C) THEN (grand-parent ?x ?z) (parent B D) (parent C E)

Page 10: Rule-based Systems: Mechanisms & Efficiency Artificial Intelligence CMSC 25000 January 10, 2002

Rule System as Relational DB

• Working memory: relations in database table

• Rules and rule interpretations as relational database operations

R1: if (parent ?x ?y) (parent ?y ?z) (is ?x female) then (grandmother ?x ?z)

(parent A B)(parent A C)(parent B D)(parent C E)(is A female)

Page 11: Rule-based Systems: Mechanisms & Efficiency Artificial Intelligence CMSC 25000 January 10, 2002

Working Memory as Database TableFirst Second Third

Parent A B

Parent A C

Parent B D

Parent C E

Is A female

Columns: Fields (Header: field name); Rows: records: assertionsRelation: Database Table “data”

Page 12: Rule-based Systems: Mechanisms & Efficiency Artificial Intelligence CMSC 25000 January 10, 2002

Pattern Matching as Relational DB Ops

• Which rules triggered? – Which antecedents match? What bindings apply?

• “Select” matching assertions

• “Project” new bindings

• “Join” bindings across antecedents

Page 13: Rule-based Systems: Mechanisms & Efficiency Artificial Intelligence CMSC 25000 January 10, 2002

Selecting Assertions

First Second Third

Parent A B

Parent A C

Parent B D

Parent C E

(parent ?x ?y) => Select data with First = parent

Page 14: Rule-based Systems: Mechanisms & Efficiency Artificial Intelligence CMSC 25000 January 10, 2002

Projecting Bindings

X Y

A B

A C

B D

C E

A1 = Project result over Second and Third

Page 15: Rule-based Systems: Mechanisms & Efficiency Artificial Intelligence CMSC 25000 January 10, 2002

Projecting Bindings

Y Z

A B

A C

B D

C E

A2 = Project [Select Data with First=parent] over Second and Third

Page 16: Rule-based Systems: Mechanisms & Efficiency Artificial Intelligence CMSC 25000 January 10, 2002

Joining for Consistency

X Y Z

A B D

A C E

Join tables for consistency: B1= Join A1 and A2 with Y=Y

Page 17: Rule-based Systems: Mechanisms & Efficiency Artificial Intelligence CMSC 25000 January 10, 2002

Produce Consequent

X ZA DA E

XA

A3 =Project [Select Data with First=Is and Third=Female] over Second

B2= Project [Join B1 and A3 with X = X] over X and Z

(Grandmother A D)(Grandmother A E)

Page 18: Rule-based Systems: Mechanisms & Efficiency Artificial Intelligence CMSC 25000 January 10, 2002

Analysis

• Relational database representation performs forward-chaining– Finds all new assertions based on rules, assertions

• But, still expensive:– n antecedents =>– n selects +n projects + n-1 joins + n-1 projects– PER RULE! – Also Joins very expensive - others linear in table

Page 19: Rule-based Systems: Mechanisms & Efficiency Artificial Intelligence CMSC 25000 January 10, 2002

Incremental Efficiency

• Solution: Compile out rules+interpreter into– RETE: Network to incrementally process each

assertion• At any time, operate on SUBSET of relations

• Steps:– Each assertion/relation passed thru Select filters– Project to alpha node = store in table– Joins represented by beta nodes

• Only small # of comparisons at each stage

Page 20: Rule-based Systems: Mechanisms & Efficiency Artificial Intelligence CMSC 25000 January 10, 2002

Compiled Out ReteAssertions:

Parent A BFirst 2nd 3rd Select new with First=Parent

Select new with First=Parent

Select new with First=is and 3rd=female

A1 A2 A3X YA B

Y ZA B

XA

B1B2

Page 21: Rule-based Systems: Mechanisms & Efficiency Artificial Intelligence CMSC 25000 January 10, 2002

Compiled Out ReteAssertions:

Parent A C First 2nd 3rd Select new with First=Parent

Select new with First=Parent

Select new with First=is and 3rd=female

A1 A2 A3X YA BA C

Y ZA BA C

XA

B1B2

Page 22: Rule-based Systems: Mechanisms & Efficiency Artificial Intelligence CMSC 25000 January 10, 2002

Compiled Out ReteAssertions:

Parent B DFirst 2nd 3rd Select new with First=Parent

Select new with First=Parent

Select new with First=is and 3rd=female

A1 A2 A3X YA BA CB D

Y ZA BA CB D

XA

B1B2

X Y ZA B D

X ZA D ETC..

Page 23: Rule-based Systems: Mechanisms & Efficiency Artificial Intelligence CMSC 25000 January 10, 2002

Summary

• Rule-based systems: Mechanisms

• Unification supports matching patterns to constants AND variables– Variable renaming preserves generality

• RETE method– Relational databases and operations– Incremental processing

• Efficient rule-based reasoning