Artificial Intelligence CS 165A Thursday, November 8, 2007 Inference in FOL (Ch 9) Brief midterm review.
Download
Report
Transcript Artificial Intelligence CS 165A Thursday, November 8, 2007 Inference in FOL (Ch 9) Brief midterm review.
Artificial Intelligence
CS 165A
Thursday, November 8, 2007
Inference in FOL (Ch 9)
Brief midterm review
1
What we’ve been talking about
• Complete and sound inference procedures
• New inference rules:
– Universal Instantiation (gets rid of )
– Existential Instantiation (gets rid of )
– Existential Introduction (adds )
• Generalized Modus Ponens
• Generalized (First-Order) Resolution
– Complete but semidecidable
• Unification
– Finds the substitution(s) necessary to make two sentences match
• Conjunctive normal form (CNF)
2
FOL example
• Domain elements: {Bob, Alice, Carol, Ted}
• x Sleepy(x)
– Sleepy(Bob) Sleepy(Alice) Sleepy(Carol) Sleepy(Ted)
• x Hungry(x)
– Hungry(Bob) Hungry(Alice) Hungry(Carol) Hungry(Ted)
• Universal Instantiation: x Sleepy(x)
– Sleepy(Alice)
• Existential Instantiation: x Hungry(x)
– Hungry(k) where k is a constant (not a variable!)
• Existential Introduction: AtHome(Ted)
– x AtHome(x)
3
Two versions of Generalized Resolution
For literals pi and qi , where UNIFY(pj , qk) =
p1 p j pm
Disjunctions
q1 qk qn
SUBST( , p1 pm q1 qn ) except p j and qk
For atomic sentences pi, qi, ri, si , where UNIFY(pj , qk) =
p1 p j pn1 r1 rn2
s1 sn3 q1 qk qn4
Implications
SUBST( , p1 pn1 s1 sn3 r1 rn2 q1 qn4 ) except p j and qk
4
Thursday quiz
Note: Everyone gets a 100% for last Thursday!
1. If the domain is natural numbers (0, 1, 2, ...), what is a
general unifier (if one exists) for these two atomic
sentences:
GreaterThan (x, 7)
GreaterThan (Squared (y), y)
E.g., = { a/13, b/4 }
2. What new (to us) dimension does situational calculus
allow us to represent and reason about?
5
Conjunctive normal form (CNF)
• First we must convert all sentences to Conjunctive Normal
Form (CNF)
– A CNF sentence is a disjunctions of literals
Literals: Possibly negated propositions, variables, constants, or
predicates
– So each sentence in the KB is a disjunction of literals, e.g.:
P(x) Q(y)
Dog(x) Cat(y)
Big(x) Slow(x) Young(x)
– The KB itself is a conjunction of disjunctions of literals, e.g.:
P(x)Q(y) Dog(x)Cat(y) Big(x)Slow(x)Young(x)
6
Another “canonical” form: INF
• Implicative Normal Form (INF)
– Each sentence in the KB is an implication with a conjunction of
atoms on the left and a disjunction of atoms on the right, e.g.:
P(x) Q(x)
P(x) Q(x) R(x) S(x)
• INF and CNF are logically equivalent
7
Conversion to Conjunctive Normal Form (CNF)
• Replace (P Q) with (P Q) and (Q P)
• Eliminate implications: Replace (P Q) with (P Q)
• Move inwards: , , , (P Q), (P Q)
• Standardize variables apart: x P(x) x Q(x) becomes
x1 P(x1) x2 Q(x2) [Give all variables different names]
• Move quantifiers left in order: x P(x) y Q(y) becomes
x y P(x) Q(y)
• Eliminate by “Skolemization” (coming)
• Drop universal quantifiers
• Distribute over , e.g.: (P Q) R becomes (P R)
(Q R)
[What about (P Q) R ?]
• Flatten nesting: (P Q) R becomes P Q R
8
Conversion to Implicative Normal Form (INF)
• First convert to CNF
• Convert disjunctions to implications: negative literals to
the left, positive literals to the right
P Q R S becomes P Q R S
P Q becomes
P Q False
R S becomes True R S
Remember that P(x) is logically equivalent to True P(x)
and P(x) is logically equivalent to P(x) False
9
Skolemization
• To “Skolemize” is to remove existential quantifiers by
elimination
– Existential elimination when x is on the outside
x Sleepy(x) …becomes… Sleepy(RipVanWinkle) [If what?]
– More complicated when inside a universal quantifier
x Person(x) y Heart(y) Has(x, y)
“Everyone has a heart”
x Person(x) Heart(H1) Has(x, H1)
“Everyone has the heart H1”
– Rather, introduce a “Skolem function” H(x)
x Person(x) Heart(H(x)) Has(x, H(x))
where H() does not appear elsewhere in the KB
– Arguments of the Skolem function: all enclosing universally
quantified variables
10
Skolemization examples
By Existential Elimination,
y MajorsIn(y, Sociology)
MajorsIn(Somedude, Sociology)
But it’s not true that
x y MajorsIn(y, x)
x MajorsIn(Somedude, x)
Rather,
x y MajorsIn(y, x)
x MajorsIn(P(x), x)
where P(x) refers to a different constant for every x
x y Student(x) TakesCourses(x) KnowsAbout(x, y)
x Student(x) TakesCourses(x) KnowsAbout(x, S(x))
11
Simple examples
• How to put these into CNF and INF?
CNF
INF
P(x) Q(x)
P(x) Q(x)
P(x) Q(x)
P(x)
P(x)
True P(x)
P(x) Q(x)
P(x) Q(x)
True P(x) Q(x)
P(x) Q(y)
P(x) Q(y)
True P(x) Q(y)
P(x) Q(y)
P(x) Q(y)
Q(y) P(x)
P(x) Q(x)
P(x), Q(x)
True P(x), True Q(x)
In practice, we can leave out the “True ”
in these sentences
12
Moving inwards
• x S(x)
– x S(x)
(is equivalent to…)
x Hungry(x) x Hungry(x)
• x S(x)
– x S(x)
x Hungry(x) x Hungry(x)
• (P Q)
– (P Q)
• (P Q)
– (P Q) [In CNF that’s two sentences!]
13
Generalized (first-order) resolution
For literals pi and qi , where UNIFY(pj , qk) =
p1 p j pm
Disjunctions
q1 qk qn
SUBST( , p1 pm q1 qn ) except p j and qk
Note:
Examples:
• p and q do not unify
pj: Engineer(x)
pj: Loves(x, Broccoli)
qj: Engineer(Bill)
qj: Loves(Joe, y)
= { x/Bill }
= { x/Joe, y/Broccoli }
• Rather, p and q unify
14
Generalized resolution example
• KB:
Rich(x) Famous(x)
Rich(x) Content(x)
Famous(x) Happy(x)
Content(x) Happy(x)
Rich(Bob)
• Is Bob happy?
– ASK(KB, Happy(Bob))
– GMP can’t answer this
– GR can
First put KB in CNF
• KB in CNF:
Rich(x) Famous(x)
Rich(x) Content(x)
Famous(x) Happy(x)
Content(x) Happy(x)
Rich(Bob)
and the negated query:
Happy(Bob)
What’s this method called?
- Proof by contradiction
- Refutation
15
Rich(x) Famous(x)
Rich(x) Content(x)
Famous(x) Happy(x)
Content(x) Happy(x)
Rich(Bob)
Happy(Bob)
Example (cont.)
,
Rich(x) Content(x)
Content(x) Happy(x)
{}
Rich(x) Happy(x)
Rich(Bob)
{x/Bob}
Happy(Bob)
Happy(Bob)
{}
False
QED
16
Forward and Backward Chaining
• A reasoning program needs
– A language for representing knowledge – First-Order Logic
– Rules – just one, Generalized Resolution
– Control mechanism– ???
• Two general approaches to control
– Start with the KB and generate new conclusions (which can enable
more inferences to be made)
E.g., when a new fact is added to the KB
– Given what we want to prove, find implication sentences that
would allow us to conclude it, and attempt to establish their
premises
E.g., when a goal is to be proved
17
Forward and Backward Chaining
Forward chaining
S
G
Backward chaining
S
G
18
Forward and Backward Chaining
• Forward chaining
– Data driven or data directed
– New version of TELL(KB, p)
Add the sentence p, then apply inference rules to the updated
KB until no more rules apply (“chaining” – “chain reaction”)
• Backward chaining
–
–
–
–
Goal oriented
ASK(KB, q)
If SUBST(, q) is in KB, return q' = SUBST(, q)
Else, find implication sentences p q then set p as a subgoals
Keep doing this, working “backwards”
If p is not in KB, look for r p, then set r as a subgoal
Etc…..
– Backward chaining is the basis for logic programming (e.g., Prolog)
19
Midterm Review
• Tuesday during class
– Please be on time!
• Closed book exam
– You may bring one sheet of paper with notes (8.5” x 11”, both
sides)
– Test paper will be supplied (don’t need to bring your own)
– Calculator not necessary
• What are you responsible for?
– Possibly anything that has been covered in the reading (textbook
through Ch. 8 and articles), lectures, discussion sessions, and
homework assignments
– But you should probably focus on the lectures….
20
You will be given…
• Inference rules for Propositional logic
– Modus ponens, and-elimination, and-introduction, or-introduction,
double-negation elimination, unit resolution, resolution
• FOL
– Universal elimination, existential elimination, existential
introduction
– Generalized modus ponens
– Generalized (first-order) resolution
• Procedure to convert logic sentences to CNF
These are posted on the course web
21
Examples of things you might be asked
• Which search algorithm(s) would be most appropriate in this particular
situation?
• What are the main difference(s) between these two search algorithms
• What does it mean for a search alg. to be optimal? To be complete?
• Are these heuristics admissible or not?
• Do {iterative deepening search, A*, minimax, expectimax, …} on this
problem.
• Show the truth table for this propositional logic sentence.
• Are these logic sentences satisfiable, unsatisfiable, or valid?
• What does it mean for an inference procedure to be optimal? To be
complete?
• Does the KB entail this sentence S?
• How are these terms unified?
• Apply certain inference rules to this KB.
22