Today’s Topics

advertisement
Today’s Topics
• Read (unsupervised ML): Std Algorithm section of
Wikipedia on K- Means (https://en.wikipedia.org/wiki/Kmeans_clustering) and Section 20.3.1 (EM Algorithm)
• Predicate Logic (aka First-Order Predicate Calculus, FOPC;
also First-Order Logic, FOL)
• We’ll covert to logic more complex English sentences
here than for prop logic
debugging tips
situation calculus for rep’ing time
• Next lecture will cover inference in FOPC
11/17/15
CS 540 - Fall 2015 (Shavlik©), Lecture 25, Week 11
1
Deduction in Prop Logic (9)
Another Way to View the Resolution Rule
wff1 ˅ wff2 , ¬ wff2 ˅ wff3
wff1 ˅ wff3
Convert to implications
¬ wff1  wff2 , wff2  wff3
Slide added to
Lecture 24
¬ wff1  wff3
Let wff4 = ¬ wff1
wff4  wff2 , wff2  wff3
wff4  wff3
11/17/15
CS 540 - Fall 2015 (Shavlik©), Lecture 24, Week 11
2
FOPC’s Extensions to
Propositional Logic
TERMS refer to objects in the ‘world’
eg John, Mary, CS540, Democracy
Predicates (aka relations) are propositions with arguments
eg siblings(John, Mary), location(Madison, Wisconsin)
Can quantify over variables
 x valuable(x)
// “Everything is valuable.”
 x valuable(x)
// “Something is valuable.”
Functions take arguments (so look just like predicates),
but refer to other terms
eg motherOf(Sue) is another name for Mary
11/17/15
CS 540 - Fall 2015 (Shavlik©), Lecture 25, Week 11
3
Three Types of Terms
Terms can be
constants such as John and Mary
variables such as x or ?x
functions such as motherOf(?x)
All refer to objects in the ‘domain of discourse’
(ie, the world we are representing)
We cannot use connectives with terms
eg, the following is not a wff: John ˄ Mary
11/17/15
CS 540 - Fall 2015 (Shavlik©), Lecture 25, Week 11
4
First vs Second Order Logic
• In FOPC, we can only quantify
over terms (ie, objects in the world)
 x human(x) → mortal(x)
• In second order logic, we could quantify
over predicates
 p p(Sue) // All properties apply to Sue.
However, 2nd order logic is incomplete (Gödel)
11/17/15
CS 540 - Fall 2015 (Shavlik©), Lecture 25, Week 11
5
Some ‘Syntactic Sugar’
For convenience, we will use
Jon = Jonathan and ?x  Mary
As ‘infix’ (rather than ‘prefix’) shorthand for
equals(John, Jonathan)
 equals(?x, Mary)
Note: = ‘takes’ TERMs (‘same object’)
and ↔ ‘takes’ PREDICATES (‘same truth value’)
11/17/15
CS 540 - Fall 2015 (Shavlik©), Lecture 25, Week 11
6
WFF?
Expression
Mary
Well Formed?
NO, WFF’s are TRUTH VALUED
Could be, but presumably a
FUNCTION, which is not a wff
motherOf(John)
mother(John, Mary)
friends(John ˄ Mary)
NO, arguments must be TERMs
fatherOf(Sue) = brotherOf(Mary)
11/17/15
CS 540 - Fall 2015 (Shavlik©), Lecture 25, Week 11
7
Some Examples of Converting
English to FOPC
(multiple acceptable answers in these examples)
“John and Mary live in Madison.”
“Alice has a brother.”
“Mary has two sisters, Sue and Ellen.”
“Fred is the brother of Al’s mother’s father.”
11/17/15
CS 540 - Fall 2015 (Shavlik©), Lecture 25, Week 11
8
Some Examples of Converting
English to FOPC
“John and Mary live in Madison.”
lives(John, Madison)  lives(Mary, Madison)
“Alice has a brother.”
x human(x)  x = brotherOf(Alice)
“Mary has two sisters, Sue and Ellen.”
sisters(Mary, Sue)  sisters(Mary, Ellen)
“Fred is the brother of Al’s mother’s father.”
brothers(Fred, fatherOf(motherOf(Al)))
11/17/15
CS 540 - Fall 2015 (Shavlik©), Lecture 25, Week 11
9
Scoping Rules
(use paren’s, braces, or brackets to clarify if confusing)
We’ll assume
1. Implications and equivalences ‘grab’
all items to the left and right
p(1)  q(2)  r(3)
is [p(1)  q(2)]  r(3) rather than p(1)  [ q(2)  r(3) ]
2. NOTs grab the next wff
 p(1)  q(2)
is [  p(1) ]  q(2) rather than  [ p(1)  q(2) ]
3. Quantified variables contain all the
following items where the variable appears
x p(x)  q(x)
is x [ p(x)  q(x) ] rather than [ x p(x) ]  q(x)
11/17/15
CS 540 - Fall 2015 (Shavlik©), Lecture 25, Week 11
10
Some Examples of Converting
English to FOPC (2)
“There is a prime larger than 100.”
“There is no largest prime.”
“Every rational number is also real.”
11/17/15
CS 540 - Fall 2015 (Shavlik©), Lecture 25, Week 11
11
Some Examples of Converting
English to FOPC (2)
“There is a prime larger than 100.”
x prime(x)  greaterThan(x, 100)
“There is no largest prime.”
x prime(x)  ( y prime(y)  (y > x) )
“Every rational number is also real.”
x number(x)  rational(x)  real(x)
11/17/15
CS 540 - Fall 2015 (Shavlik©), Lecture 25, Week 11
12
What about …
“Every rational number is also real.”
x number(x)  rational(x)  real(x)
what about irrational numbers? what about non-numbers, etc?
x
number(x) 
rational(x)  real(x)
loses info (ALL became SOME), plus what if NO #’s in our world?
x ¬ number(x) ˅ ¬ rational(x) ˅ real(x)
this one is correct, equiv to (Numb ˄ Rat)→Real
11/17/15
CS 540 - Fall 2015 (Shavlik©), Lecture 25, Week 11
13
Can AND Mean OR????
“Tell me all the sales people in
NYC and LA who had sales of at least $1M.”
“None, because we have no one who works in
both LA and NYC.” This answer seems wrong.
What was meant: “Tell me all the sales people
in NYC or LA who had sales of at least $1M.”
11/17/15
CS 540 - Fall 2015 (Shavlik©), Lecture 25, Week 11
14
Good Rules-of-Thumb
ForAll’s usually involve implications
 x someTestThatSelectsSubsetOfWorldObjects(x)
→
someAdditionalFactsWeCanInferAboutThatSubset(x)
ThereExist’s never involve implications
 x p(x) → q(x)
is equivalent to
 x  p(x)  q(x)
11/17/15
// So true if p(x) ever false!
CS 540 - Fall 2015 (Shavlik©), Lecture 25, Week 11
15
Recall: P → Q as a Venn Diagram
If we know P is true we can also infer Q is true
Knowing Q is false also tells us that P is false
But if P is false, we can’t infer anything about Q
Q
11/17/15
P
CS 540 - Fall 2015 (Shavlik©), Lecture 25, Week 11
16
Some Examples of Converting
English to FOPC (3)
“Everyone likes a dog.”
x human(x)  ( y dog(y)  likes(x, y) )
“There is one dog that every one likes.”
y [ dog(y)  ( x human(x)  likes(x, y) ) ]
“Everyone likes a different dog.”
x human(x)  [ y dog(y)  likes(x, y) 
( z human(z)  likes(z, y)  z = x ) ]
11/17/15
CS 540 - Fall 2015 (Shavlik©), Lecture 25, Week 11
17
Debugging English-to-FOPC
We can show faulty translations
by finding models (ie, ‘worlds’) where
our ‘gut feeling’ understanding
of the English sentence
does not match
the mechanical calculation
of the ‘truth value’ of the sentence
11/17/15
CS 540 - Fall 2015 (Shavlik©), Lecture 25, Week 11
18
Interpretations in FOPC
• In prop calc, we provided the
truth value of each proposition
• Now we need
– List of objects in the world
– Truth value for each grounded predicate
(grounding means replace variables
with constants in all possible ways)
– Map for each grounded function to an object
11/17/15
CS 540 - Fall 2015 (Shavlik©), Lecture 25, Week 11
19
Interpretations in FOPC:
Example
Assume we have predicate related,
function motherOf and objects Al, Eve, NoOne
An interpretation:
related(Al,
Al)=T
related(Al,
Eve)=T
related(Al,
NoOne)=F
related(Eve,
Al)=T
related(Eve,
Eve)=T
related(Eve,
NoOne)=F
related(NoOne, Al)=F
related(NoOne, Eve)=F
motherOf(Al)
= Eve
motherOf(Eve)
= NoOne
related(NoOne, NoOne)=T
motherOf(NoOne) = NoOne
11/17/15
CS 540 - Fall 2015 (Shavlik©), Lecture 25, Week 11
20
Mechanically Determining the Truth
Value of a Compound Sentence:
One Method (‘inference’ is another)
• Assume we have a non-zero, finite number of
objects in our world
(we won’t worry about empty sets in cs540: is ForAll true in empty sets?)
• Replace variables by constants in all possible ways
– Convert FOR ALL’s
to a big AND
– Convert THERE EXIST’s to a big OR
• Use truth tables like with prop logic
11/17/15
CS 540 - Fall 2015 (Shavlik©), Lecture 25, Week 11
21
Debugging English-to-FOPC:
Example
Assume we represented
“There is valuable vase.”
as  x vase(x) → valuable(x)
Consider this interpretation:
objects:
fido
interpretation: vase(fido)=false
valuable(fido)=false
In this world, the English is FALSE,
but the FOPC is TRUE. So buggy!
11/17/15
CS 540 - Fall 2015 (Shavlik©), Lecture 25, Week 11
22
Debugging English-to-FOPC:
Example (Eval’ing the Logic)
Assume we represented “There is valuable vase.”
as  x vase(x) → valuable(x)
objects:
fido
interpretation: vase(fido)=false
valuable(fido)=false
All possible groundings:
 vase(fido)  valuable(fido)
Evaluating:
 false  false
true
Some extra notes: http://pages.cs.wisc.edu/~shavlik/cs540/debuggingEnglishToFOPCtranslations.txt
11/17/15
CS 540 - Fall 2015 (Shavlik©), Lecture 25, Week 11
23
What about …
“Everyone likes a dog.”
What is wrong with:
x y [human(x)  dog(y)]  likes(x, y)
Consider this interpretation
objects: a, d
human(a)=true human(d)=false
dog(a)=false
dog(d)=true
likes(a,a)=true likes(a,d)=false
likes(d,a)=false likes(d,d)=true
11/17/15
CS 540 - Fall 2015 (Shavlik©), Lecture 25, Week 11
English is
FALSE for this
interpretation,
but is the
FOPC also
FALSE?
24
What about …(solution)
“Everyone likes a dog.”
What is wrong with (plug in interpret’s values):
{ [human(a)  dog(a)]  likes(a, a) OR
[human(a)  dog(d)]  likes(a, d) }
AND
{ [human(d)  dog(a)]  likes(d, a) OR
[human(d)  dog(d)]  likes(d, d)
{ [T  F]  T is T OR
[T  T]  F is F }
AND
{ [F  F]  F is T OR
[F  T]  T is T }
T
Consider this interpretation
objects: a, d
human(a)=true human(d)=false
dog(a)=false
dog(d)=true
likes(a,a)=true likes(a,d)=false
likes(d,a)=false likes(d,d)=true
11/17/15
CS 540 - Fall 2015 (Shavlik©), Lecture 25, Week 11
25
Dealing with Change (eg, Time)
“John gave Mary the book IntroToAI.”
A weak solution:
gave(John, Mary, IntroToAI)
Would like to represent:
The ‘711’ is used to
represent a specific,
physical book
“John owned IntroToAI_711.”
“Mary now owns IntroToAI_711.”
11/17/15
CS 540 - Fall 2015 (Shavlik©), Lecture 25, Week 11
26
Dealing with Change (eg, Time)
Another example:
“Moving a block to another changes
the location of the block moved,
but nothing else in the world changes.”
A
B
C
B
Table1
11/17/15
A
C
Table1
CS 540 - Fall 2015 (Shavlik©), Lecture 25, Week 11
27
One Sol’n: Situation Calculus
• TIME STAMP our facts!
• Invented by McCarthy & Hayes, 1969
On(blockA, blockB, s0)
Both facts are true.
No need to delete the
first after the MOVE!
On(blockA, blockC,
result(move(blockA, blockC), s0))
A FUNCTION
A
B
Another function
C
B
Table1
11/17/15
A
C
Table1
CS 540 - Fall 2015 (Shavlik©), Lecture 25, Week 11
28
result(move(blockA, blockC), s0))
• RESULT is a function whose arguments
are an action and a state; refers to the
resulting STATE
• MOVE is a function whose arguments are
two blocks; refers to an ACTION
A
B
C
B
Table1
11/17/15
A
C
Table1
CS 540 - Fall 2015 (Shavlik©), Lecture 25, Week 11
29
Example
A
B
C
Table1
A
C
B
Table1
“Moving a block to another changes
the location of the block moved,
but nothing else in the world changes.”
x y z s
block(x)  block(y)  block(z)  state(s) 
???
→
state(result(move(x, z), s))  ???
11/17/15
CS 540 - Fall 2015 (Shavlik©), Lecture 25, Week 11
30
Example
A
B
C
A
C
B
Table1
Table1
“Moving a block to another changes the location of the block moved,
but nothing else in the world changes.”
x y z s
block(x)  block(y)  block(z)  state(s) 
on(x, y, s)  clearTop(x, s)  clearTop(z, s)  x  z  y  z
→
Could drop clearTop and instead
assume we have this inference
state(result(move(x, z), s)) 
rule:
on(x, z, result(move(x, z), s)) 
“Blocks that are not the first
 on(x, y, result(move(x, z), s)) 
argument to ON have the
property ClearTop.”
clearTop(x, result(move(x, z), s)) 
(to do by you: convert to FOPC)
clearTop(y, result(move(x, z), s)) 
What if A was on the table?
 clearTop(z, result(move(x, z), s))
Or if A moved to the table?
We’d need more inference rules.
11/17/15
CS 540 - Fall 2015 (Shavlik©), Lecture 25, Week 11
31
Example
A
B
C
D
Table1
A
C
B
Table1
“Blocks not involved in a move
stay where they are.”
x y z w u s // We’ll let u be a block or table.
block(x)  block(y)  block(z)  block(w)  state(s) 
???
→
state(result(move(x, y), s))  ???
11/17/15
CS 540 - Fall 2015 (Shavlik©), Lecture 25, Week 11
32
D
Example
A
B
C
D
A
C
B
Table1
D
Table1
“Blocks not involved in a move
stay where they are.”
x y z w u s // We’ll let u be a block or table.
block(x)  block(y)  block(z)  block(w)  state(s) 
on(w, u, s) 
Rules like these are called
xwywzw
frame axioms. They describe
xu yu zu
what doesn’t change between
→
state(result(move(x, z), s)) 
on(w, u, result(move(x, z), s)) )
11/17/15
world states (like the frames
in a movie)
CS 540 - Fall 2015 (Shavlik©), Lecture 25, Week 11
33
EX: “Giving a book to another person
changes who owns the book,
but not the book’s author.”
11/17/15
CS 540 - Fall 2015 (Shavlik©), Lecture 25, Week 11
34
EX: “Giving a book to another person
changes who owns the book,
but not the book’s author.”
x y z w s
human(x)  human(y)  human(z)  book(w)  state(s) 
owns(x, w, s)  z = authorOf(w, s)  x  y
→
Note: we could also
state(result(give(x, w, y), s) 
simply not ‘time stamp’
the author predicate
owns(y, w, result(give(x, w, y), s)) 
 owns(x, w, result(give(x, w, y), s)) 
And the ‘frame axiom’
z = authorOf(w, result(give(x, w, y), s)) should really be a
separate inference rule
(good s/w engineering)
11/17/15
CS 540 - Fall 2015 (Shavlik©), Lecture 25, Week 11
35
The Qualification Problem
Can never list all the preconditions of an action
Example:
Solution: do a
“A car won’t start because
reasonable
its battery is dead or
approximation
it is out of gas or
and live with
imperfections
its starter is broken or
there is banana in the tailpipe or
a meteorite hit it while I was turning the key or
I am using the wrong key or
…”
11/17/15
CS 540 - Fall 2015 (Shavlik©), Lecture 25, Week 11
36
Negation-by-Failure
Common shortcut
– Assume that facts we cannot prove true are false
(called the closed world assumption)
– Not justified logically (failure to prove P is true
is not a proof that P is false)
– But an effective assumption when using logic
to build practical systems
(since most groundings of predicates are false)
– Example: given even(2), even(4)
we cannot prove even(6) but of course it is not false
11/17/15
CS 540 - Fall 2015 (Shavlik©), Lecture 25, Week 11
37
More Practice if Time Permits
(from old cs540 finals)
“Except for BillG, for every person there exists someone richer.”
“Borrowing a book doesn’t change who owns it.”
“Only those trees that are tall have long roots.”
“Every election has a winner.”
“All birds can fly except for penguins and ostriches
or unless they have a broken wing.”
11/17/15
CS 540 - Fall 2015 (Shavlik©), Lecture 25, Week 11
38
Wrapup on
Representation via FOPC
• FOPC has constants, variables, predicates &
functions with arguments, and quantifiers
• Interpretations tell us the truth values or
referents for our atomic symbols
(next lecture: logical inference in FOPC)
– Help debug English translations into FOPC
• Situation calculus deals with time-varying facts
– Frame problem (what does not change)
– Qualification problem (unbound preconditions)
11/17/15
CS 540 - Fall 2015 (Shavlik©), Lecture 25, Week 11
39
Download