knowledge representation iv inference in first-order logic cse 473

24
Knowledge Representation IV Inference in First-Order Logic CSE 473

Post on 22-Dec-2015

224 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Knowledge Representation IV Inference in First-Order Logic CSE 473

Knowledge Representation IVInference in First-Order Logic

CSE 473

Page 2: Knowledge Representation IV Inference in First-Order Logic CSE 473

© Daniel S. Weld 2

Logistics

• PS2   Snapshot due today  Final version due in 1 week

• Turn lights down

Page 3: Knowledge Representation IV Inference in First-Order Logic CSE 473

© Daniel S. Weld 3

473 Topics

Agency

Problem Spaces

Search

Knowledge Representation

Perception

NLPMulti-agent

Robotics

Reinforcement

Learning Inference Planning

SupervisedLearning

Logic Probability

Page 4: Knowledge Representation IV Inference in First-Order Logic CSE 473

© Daniel S. Weld 4

Logic-Based KR

Propositional logicSyntax (CNF, Horn clauses, …)Semantics (Truth Tables)Inference (FC, Resolution, DPLL, WalkSAT)Restricted Subsets

First-order logic Syntax (quantifiers, skolem functions, …Semantics (Interpretations)Inference (FC, Resolution, Compilation)Restricted Subsets (e.g. Frame Systems)

Representing events, action & change

Page 5: Knowledge Representation IV Inference in First-Order Logic CSE 473

© Daniel S. Weld 5

Propositional. Logic vs. First Order

Ontology

Syntax

Semantics

Inference Algorithm

Complexity

Objects, Properties, Relations

Atomic sentencesConnectives

Variables & quantificationSentences have structure: termsfather-of(mother-of(X)))

UnificationForward, Backward chaining Prolog, theorem proving

DPLL, GSATFast in practice

Semi-decidableNP-Complete

Facts (P, Q)

Interpretations (Much more complicated)Truth Tables

Page 6: Knowledge Representation IV Inference in First-Order Logic CSE 473

© Daniel S. Weld 6

Prop. Logic: Knowledge Engr

1. Choose Vocabulary

1) One of the women is a biology major2) Lisa is not next to Dave in the ranking3) Dave is immediately ahead of Jim4) Jim is immediately ahead of a bio major 5) Mary or Lisa is ranked first

Universe: Lisa, Dave, Jim, MaryLD = “Lisa is directly ahead of Dave”D = “Dave is a Bio Major”

2. Choose initial sentences (wffs)

1) L M2) LD DL3) DJ4) (JD D) (JL L) (JM M)

Error!

Page 7: Knowledge Representation IV Inference in First-Order Logic CSE 473

© Daniel S. Weld 7

Knowledge Engineering in FOPC

1) One of the women is a biology major2) Lisa is not next to Dave in the ranking3) Dave is immediately ahead of Jim4) Jim is immediately ahead of a bio major 5) Mary or Lisa is ranked first

1. Choose VocabularyObjects, Relations

2. Choose initial sentences

Page 8: Knowledge Representation IV Inference in First-Order Logic CSE 473

© Daniel S. Weld 8

FOL Reasoning

FO Forward & Backward Chaining FO ResolutionMany other types of theorem provingRestricted representations

Description logicsCompilation to SAT

Page 9: Knowledge Representation IV Inference in First-Order Logic CSE 473

© Daniel S. Weld 9

Unification• Match expressions w/ variables

  Denoted ?x

• Unify(x, y) returns “mgu”  Unify(city(?a), city(kent)) returns {?a/kent}

• Substitute(expr, mapping) returns new expr  Substitute(connected(?a, ?b), {?a/kent}) returns connected(kent, ?b)

Page 10: Knowledge Representation IV Inference in First-Order Logic CSE 473

© Daniel S. Weld 10

Unification Example I

• Unify(f(g(?x, dog), ?y)), f(g(cat, ?y), dog)

  Unification ok  Returns {?x / cat, ?y / dog}  When substitute in both expressions, they

match  Each is f(g(cat, dog))

Page 11: Knowledge Representation IV Inference in First-Order Logic CSE 473

© Daniel S. Weld 11

Unification Example II

• Unify(f(g(?x)), f(?x))  They don’t unify binding, such that substitution makes both

expressions the same.  E.g. consider: {?x / g(?x) }   We get f(g(g(?x))) and f(g(?x)) … not equal!

• A variable value may not contain itself   Directly or indirectly

Page 12: Knowledge Representation IV Inference in First-Order Logic CSE 473

© Daniel S. Weld 12

Reminder Resolution

• When trying to prove |=

• Use proof by contracdiction  Show unsatisfiable

• Resolution rule

Page 13: Knowledge Representation IV Inference in First-Order Logic CSE 473

© Daniel S. Weld 13

Propositional Resolution[Robinson 1965]

{ (p ), ( p ) } |-R ( )

Recall Propositional Case: •Literal in one clause•Its negation in the other•Result is disjunction of other literals

}

Page 14: Knowledge Representation IV Inference in First-Order Logic CSE 473

© Daniel S. Weld 14

First-Order Resolution[Robinson 1965]

{ (p(?x) a(a), ( p(q) b(?x) c(?y)) }

|-R

(a(a) b(q) c(?y))

•Literal in one clause•The negation of something which unifies in

the other•Result is disjunction of other literals / mgu

Page 15: Knowledge Representation IV Inference in First-Order Logic CSE 473

© Daniel S. Weld 15

First-Order Resolution

• Is it the case that |= ?• Method

  Let =   Convert to clausal form

• Standardize variables• Move quantifiers to front, skolemize to remove • Replace with and • Demorgan’s laws...

  Resolve until get empty clause

Page 16: Knowledge Representation IV Inference in First-Order Logic CSE 473

© Daniel S. Weld 16

Skolemization• Existential quantifiers aren’t necessary!

  Existential variables can be replaced by• Skolem functions (or constants)• Args to function are all surrounding vars

d t has(d, t)

x y loves(y, x)

  d has(d, f(d) )

  y loves(y, f() )

  y loves(y, f97 )

Page 17: Knowledge Representation IV Inference in First-Order Logic CSE 473

© Daniel S. Weld 17

Example

• Given?x man(?x) => mortal(?x)?x woman(?x) => mortal(?x)?x person(?x) => man(?x) woman(?x)  person(kelly)

• Prove  mortal(kelly)

[m(?x),d(?x)] [w(?y), d(?y)] [p(?z),m(?z),w(?z)] [p (k)][d(k)]

Page 18: Knowledge Representation IV Inference in First-Order Logic CSE 473

© Daniel S. Weld 18

Example Continued[m(?x),d(?x)] [w(?y), d(?y)] [p(?z),m(?z),w(?z)] [p (k)] [d(k)]

[m(k),w(k)]

[w(k), d(k)]

[]

[w(k)]

[d(k)]

Page 19: Knowledge Representation IV Inference in First-Order Logic CSE 473

© Daniel S. Weld 19

May not Terminate

?p ?f P(?p) => P(?f)P(joe)

[ (P(?p), P(F(?p))) (P(joe)) (P(fred)) ]

P(fred)

Given Prove

(P(F(joe)))

(P(F(F(joe))))

(P(F(F(F(joe)))))

Page 20: Knowledge Representation IV Inference in First-Order Logic CSE 473

© Daniel S. Weld 20

Compilation to Prop. Logic I

• Typed Logiccity a,b connected(a,b)

• Universe  Cities: seattle, tacoma, enumclaw

• Equivalent propositional formula:

Cst Cse Cts Cte Ces Cet

Page 21: Knowledge Representation IV Inference in First-Order Logic CSE 473

© Daniel S. Weld 21

Compilation to Prop. Logic II

• Typed Logiccity c biggest(c)

• Universe  Cities: seattle, tacoma, enumclaw

• Equivalent propositional formula:

Bs Bt Be

Page 22: Knowledge Representation IV Inference in First-Order Logic CSE 473

© Daniel S. Weld 22

Compilation to Prop. Logic III

•Universe•Cities: seattle, tacoma, enumclaw•Firms: IBM, Microsoft, Boeing

•First-Order formulafirm f city c HeadQuarters(f, c)

•Equivalent propositional formula

[ (HQis HQit HQie) (HQms HQmt HQme) (HQbs HQbt HQbe) ]

Page 23: Knowledge Representation IV Inference in First-Order Logic CSE 473

© Daniel S. Weld 23

Hey!

• You said FO Inference is semi-decidable• But you compiled it to SAT

  Which is NP Complete • So now we can always do the inference?!?

  Tho it might take exponential time…

• Something seems wrong here….????

Page 24: Knowledge Representation IV Inference in First-Order Logic CSE 473

© Daniel S. Weld 24

Restricted Forms of FO Logic

• Known, Finite Universes  Compile to SAT

• Frame Systems  Ban certain types of expressions

• Horn Clauses  Aka Prolog

• Function-Free Horn Clauses  Aka Datalog