50 likes | 188 Views
Ch. 9 – FOL Inference. Supplemental slides for CSE 327 Prof. Jeff Heflin. Backward Chaining. function FOL-BC-ASK ( KB , goals , ) returns a set of substitutions local answers, a set of substitutions, initially empty
E N D
Ch. 9 – FOL Inference Supplemental slides for CSE 327 Prof. Jeff Heflin
Backward Chaining function FOL-BC-ASK (KB, goals, ) returns a set of substitutionslocalanswers, a set of substitutions, initially empty if goals is empty then return { }q’ SUBST( ,FIRST(goals))for each sentence rin KB where STANDARDIZE-APART(r) = (p1… pn q) and ’ UNIFY(q,q’) succeedsnew_goals PREPEND([p1,…,pn],REST(goals))answers FOL-BC-ASK(KB, new_goals, COMPOSE(’, )) answersreturnanswers From Figure 9.6, p. 288
Backward Chaining Example Set of sentences: S1: x1,y1 child(x1,y1) parent(y1,x1) S2: x2,y2 parent(x2,y2) female(x2) mother(x2,y2) S3: child(Lisa,Homer) S4: child(Lisa,Marge) S5: female(Marge) Note: variables have already been standardized apart using subscripts Query: x mother(x,Lisa)
Backward Chaining Search Tree mother(x0,Lisa) match rule S2’={x2/x0, y2/Lisa} parent(x0,Lisa), female(x0) match rule S1’={y1/x0, x1/Lisa} child(Lisa,x0), female(x0) match S4 ’={x0/Marge} match S3 ’={x0/Homer} female(homer) female(marge) matches S5 ’={ x0/Marge} no matches answers={} (FAIL!) answers={ x0/Marge}
Forward Chaining function FOL-FC-ASK (KB,) returns a substitution or falselocalnew, the new sentences inferred on each iteration repeat until new is emptynew {}for each sentence rin KBdo (p1… pn q ) STANDARDIZE-APART(r)for each such that SUBST( , p1… pn)= SUBST( , p1’ … pn’) for some p1’ ,…, pn’ in KBq’ SUBST( ,q)if q’ is not a renaming of some sentence already in KB or newthen do add q’ to new UNIFY(q’, ) if is not failthen return add new to KBreturnanswers From Figure 9.3, p. 282