Week4 Lect1 RBReasoning Pattern Final'
Week4 Lect1 RBReasoning Pattern Final'
INFERENCE
WORKING ENGINE
MEMORY
PATTERN EXECUTION
MATCHER ENGINE
RULE
BASE
AGENDA
?????
?????
“Hans” “Franz”
“Josef” “Joseph”
?first_name “Joseph”
?last_name “Joseph”
father(X) “Joseph”
father(Y)
father(X)
mother(X)
father(X)
grandfather(X)
father(father(X)) ??
❖ Similarity-based matching
❖ imprecise
❖ partial match
❖ not all requirements specified in the query are met
❖ multi-field wildcard
$?
❖ matches zero or more fields of a fact
?<var>
❖ single field variable
❖ <var> is some word
❖ this symbol matches anything in the corresponding
field of a fact
❖ value matched is bound to ?<var> for scope of rule
❖ examples: ?cat ?color ?machine
$?<var>
❖ multi-field variable
❖ matches zero or more fields of a fact
❖ the value(s) of the matched fields is bound to $?<var> for
the scope of the rule
❖ Very inefficient
❖ roughly (number of rules) * (number of facts)
❖ the actual performance depends on the formulation
of the rules and the contents of the working memory
2. More rules will result in more rules that apply and more
facts being derived that both apply and do not apply
(deftemplate room
(slot number) WMEs
41 (student name Mary gender F placed_in nil
(slot capacity (type INTEGER)(default 4)) special_consideration no)
52 (student name Peter gender M placed_in nil
(slot genderes_are) special_consideration yes)
9 (room number 221 capacity 1 vacancies 1)
(slot vacancies (type INTEGER)) 12 (room number 346 capacity 2 vacancies 1)
(multislot occupants))
a(X,Y) b(X,Z)
a(X,Y) b(X,Z)
Y=1 Y=2
- There is a starting node
and a node for each of the
rule conditions and
conjunctions of conditions.
- Arcs are labeled with a(X,1),b(X,Z) a(X,2),b(X,Z)
variable bindings
a(3,1) is deposited
in the node labeled Y=1 Y=2
a(X,Y) and will
propagate through
the arc labeled Y=1 a(3,1)
a(X,1),b(X,Z) a(X,2),b(X,Z)
Fact a(3,1)
Fact b(3,4) is now added to start
the working memory
b(3,4) is deposited
in the node labeled Y=1 Y=2
b(Y,Z) and will
propagate through
the arcs labeled Y=1 a(3,1),b(3,4) b(3,4)
and Y=2
a(X,1),b(X,Z) a(X,2),b(X,Z)
a(3,2) is deposited
in the node labeled Y=1 Y=2
a(X,Y) and will
propagate through
the arc labeled Y=2 a(3,1),b(3,4) a(3,2),b(3,4)
a(X,1),b(X,Z) a(X,2),b(X,Z)
Pattern x? y? z?
x? y?
Network
Join Network
8 nodes
q
Pattern x? y? z?
Network
R1
Join Network
p R2
6 nodes
q
Pattern x? y? z?
Network
R1
Join Network
p R2
5 nodes
q
message job-def
Alpha memories
Memory support
?y
Test for consistent sizes
Beta memory
Condition relationship
Changes
(C) Copyright 2022 by Prof.Abeer ElKorany to conflict set 38
(defrule show-act WM
(a ?x) (a 1) Initial state of
(b ?x ?y) (b 1 2) (b 2 3) (b 2 4)
(c ?y ) (c 3) (c 2) RETE Network
=> …
show-act
a c select
b
a 1 b 1 2 c 3 Resulting relations
b 2 3 c 2 (alpha memories)
b 2 4
Join x
a 1 b 1 2
Intermediate partial result
(beta memories)
Join y
a 1 b 1 2 c 2
a 1 b 1 2
Intermediate partial result
(beta memories)
+ a 2 b 2 3
+ a 2 b 2 4
Join y
(defrule show-act
a 1 b 1 2 c 2 (a ?x)
(b ?x ?y)
+ a 2 b 2 3 c 3 (c ?y
=> …
Changes
(C) Copyright 2022 by Prof.Abeer ElKorany to conflict set 40
Activity of the RETE Match during a Deletion
- a 2
a c select
b
a 1 b 1 2 c 3 Resulting relations
- a 2 b 2 3 c 2 (alpha memories)
b 2 4
Join x
a 1 b 1 2
Intermediate partial result
(beta memories)
- a 2 b 2 3
- a 2 b 2 4
Join y
(defrule show-act
a 1 b 1 2 c 2 (a ?x)
(b ?x ?y)
- a 2 b 2 3 c 3 (c ?y )
=> …
Changes
(C) Copyright 2022 by Prof.Abeer ElKorany to conflict set 41
Assert and Retract with
Rete
❖ asserting additional facts imposes some more constraints on
the network
Diameter > 4”
Fruit = watermelon
< 4” Fruitclass = vine = honeydew
= cantalope
Surface = smooth
= rough
= apple
= apricot
Color = green
= cherry
= yellow
= peach
= tan
= plum
= orange
= orange
= red
= purple Fruitclass = tree
))
Diameter > 4”
Fruit = watermelon
< 4” Fruitclass = vine = honeydew
= cantalope
Surface = smooth
= rough
= apple
= apricot
Color = green
= cherry
= yellow
= peach
= tan
= plum
= orange
= orange
= red
= purple Fruitclass = tree
Diameter > 4”
Fruit = watermelon
< 4” Fruitclass = vine = honeydew
= cantalope
Surface = smooth
= rough
= apple
= apricot
Color = green
= cherry
= yellow
= peach
= tan
= plum
= orange
= orange
= red
= purple Fruitclass = tree
Diameter > 4”
Fruit = watermelon
< 4” Fruitclass = vine = honeydew
= cantalope
Surface = smooth
= rough
= apple
= apricot
Color = green
= cherry
= yellow
= peach
= tan
= plum
= orange
= orange
= red
= purple Fruitclass = tree
❖ Knowledge Engineer
❖ Tasked with working with the expert to extract
expertise and codify in a set of rules
❖ Has training in the development of expert systems, but not
necessarily in the application domain
❖ Know the capabilities of technology and knows how to apply it
❖ R1: (item ?x) (item ?y) (item ?z) (match ?x ?y ?z) )-> (buy ?x)
❖ R2 : (match ?x ?y ?z) (item ?x) (item ?y) (item ?z) ) -> (buy ?x)
The most specific pattern should be placed toward the front of the
left-hand side of the rule