Outline Knowledge base Propositional logic Syntax and semantics - - PDF document

outline
SMART_READER_LITE
LIVE PREVIEW

Outline Knowledge base Propositional logic Syntax and semantics - - PDF document

Outline Knowledge base Propositional logic Syntax and semantics Propositional Logic Inference Backtracking (DPLL) CS 486/686 Resolution Sept 23, 2008 Local search (GSAT, WALKSAT) University of Waterloo 1 2


slide-1
SLIDE 1

1

CS486/686 Lecture Slides (c) 2008 P. Poupart

1

Propositional Logic

CS 486/686 Sept 23, 2008 University of Waterloo

CS486/686 Lecture Slides (c) 2008 P. Poupart

2

Outline

  • Knowledge base
  • Propositional logic

– Syntax and semantics

  • Inference

– Backtracking (DPLL) – Resolution – Local search (GSAT, WALKSAT)

CS486/686 Lecture Slides (c) 2008 P. Poupart

3

Introduction

  • Many tasks can be formalized as search

problems

  • How to design search algorithms that are

general, yet efficient?

  • Generality: problem independent algorithm
  • Efficiency: exploit domain knowledge

– Heuristic function – Constraints

  • Is there a good language for this?

CS486/686 Lecture Slides (c) 2008 P. Poupart

4

Logic

  • General language

– Can encode any kind of deterministic and discrete knowledge – Well defined syntax and semantics – Knowledge base: store domain knowledge

  • General algorithms

– Search by inference – Can infirm or confirm conclusions

CS486/686 Lecture Slides (c) 2008 P. Poupart

5

Declarative Approach

  • Do not program the solution
  • Just describe the problem
  • Knowledge base

– Set of logic sentences

  • Goal:

– Logical formula to be confirmed/infirmed

  • Solution

– Inference algorithm

CS486/686 Lecture Slides (c) 2008 P. Poupart

6

Syntax of a very simple logic

  • Sentence AtomicSentence | ComplexSentence
  • AtomicSentence True | False | Symbol
  • Symbol P | Q | R | …
  • ComplexSentence ¬Sentence

| (Sentence ∧ Sentence ) | (Sentence ∨ Sentence) | (Sentence ⇒ Sentence ) | (Sentence ⇔ Sentence) Symbols are binary variables

slide-2
SLIDE 2

2

CS486/686 Lecture Slides (c) 2008 P. Poupart

7

Logical connector semantics

true true true true false true true false false true false false false true false true true false true true false true true false false true false false P ⇔ Q P ⇒ Q P ∨ Q P ∧ Q ¬P Q P

CS486/686 Lecture Slides (c) 2008 P. Poupart

8

Recall the Street Puzzle

1 2 3 4 5

Ni = {English, Spaniard, Japanese, Italian, Norwegian} Ci = {Red, Green, White, Yellow, Blue} Di = {Tea, Coffee, Milk, Fruit-juice, Water} Ji = {Painter, Sculptor, Diplomat, Violinist, Doctor} Ai = {Dog, Snails, Fox, Horse, Zebra} The Englishman lives in the Red house The Spaniard has a Dog The Japanese is a Painter The Italian drinks Tea The Norwegian lives in the first house on the left The owner of the Green house drinks Coffee The Green house is on the right of the White house The Sculptor breeds Snails The Diplomat lives in the Yellow house The owner of the middle house drinks Milk The Norwegian lives next door to the Blue house The Violinist drinks Fruit juice The Fox is in the house next to the Doctor’s The Horse is next to the Diplomat’s

Who owns the Zebra? Who drinks Water? Who owns the Zebra? Who drinks Water?

CS486/686 Lecture Slides (c) 2008 P. Poupart

9

Example – Street Puzzle

  • Symbols: Vin, Vic, Vid, Vij, Via

i ∈ {1,2,3,4,5} n ∈ {English, Spaniard, Japanese, Italian, Norwegian} c ∈ {Red, Green, White, Yellow, Blue} d ∈ {Tea, Coffee, Milk, Fruit-juice, Water} j ∈ {Painter, Sculptor, Diplomat, Violinist, Doctor} a ∈ {Dog, Snails, Fox, Horse, Zebra}

  • Example:

V2red = true: the 2nd house is red V2red = false: the 2nd house is not red

CS486/686 Lecture Slides (c) 2008 P. Poupart

10

Example – Street Puzzle

  • Constraint: the Spaniard has a dog
  • Constraint: the green house is on the

immediate left of the red house (V1spaniard ⇔ V1dog) ∧ (V2spaniard ⇔ V2dog) ∧ (V3spaniard ⇔ V3dog) ∧ (V4spaniard ⇔ V4dog) ∧ (V5spaniard ⇔ V5dog) ¬V1red ∧ (V1green ⇔ V2red) ∧ (V2green ⇔ V3red) ∧ (V3green ⇔ V4red) ∧ (V4green ⇔ V5red) ∧ ¬V5green

CS486/686 Lecture Slides (c) 2008 P. Poupart

11

Example: 4-Queens problem

  • Symbols: Qij i,j∈{1,2,3,4}
  • Qij = true: queen at

location (i,j)

  • Qij = false: no queen at

location (i,j)

1 2 3 4 1 2 3 4

CS486/686 Lecture Slides (c) 2008 P. Poupart

12

Example: 4-Queens problem

  • At least one queen in row 1:
  • At most one queen in row 1:

1 2 3 4 1 2 3 4

Q11 ∨ Q12 ∨ Q13 ∨ Q14 Q11 ⇒ ¬Q12 ∧ ¬Q13 ∧ ¬Q14 Q12 ⇒ ¬Q11 ∧ ¬Q13 ∧ ¬Q14 Q13 ⇒ ¬Q11 ∧ ¬Q12 ∧ ¬Q14 Q14 ⇒ ¬Q11 ∧ ¬Q12 ∧ ¬Q13

slide-3
SLIDE 3

3

CS486/686 Lecture Slides (c) 2008 P. Poupart

13

Knowledge Base (KB)

  • Knowledge base

– Encode problem description and any knowledge that could help solve the problem – Database of facts and constraints – Possible language: propositional logic

  • Entailment

– What can we derive/conclude from KB? – KB |= α: α follows from KB

CS486/686 Lecture Slides (c) 2008 P. Poupart

14

Semantics

  • Semantics

– define the “meaning” of each sentence – define the truth of each sentence with respect to each possible world

  • Model:

– a possible world – each possible configuration of the variables

  • Examples:

– P, Q, R: 8 models (all possible configurations of P, Q and R) – 4-queens problem: 216 models – Street puzzle: 225 models

CS486/686 Lecture Slides (c) 2008 P. Poupart

15

Semantics

  • Entailment: KB |= α

– α is true in all the models in which KB is true

models KB

α

models KB

α

models KB

α KB |= α KB |≠ α KB |≠ α

CS486/686 Lecture Slides (c) 2008 P. Poupart

16

Inference

  • Process of verifying the truth of a

formula

  • Simple inference algorithm:

– Build a truth table that enumerates all models – Verify that formula is true in all models where KB is true

CS486/686 Lecture Slides (c) 2008 P. Poupart

17

Truth table

false false true true false false true true Q false false true false true false false false false true true false true false false false true true false false true false true true KB R P KB: P ⇒ Q, Q ⇒ R, ¬Q KB |= P? KB |= ¬P? KB |= Q? KB |= ¬Q? KB |= R? KB |= ¬R? no yes no yes no no

CS486/686 Lecture Slides (c) 2008 P. Poupart

18

Efficiency

  • Building a truth table is inefficient:

exponential in the number of variables

  • Alternative: backtracking search

– Rewrite “KB |= α?” as KB’ = (KB and ¬α) – Show that KB’ is not satisfiable (e.g., there doesn’t exist any model for which KB is true, but α is false)

slide-4
SLIDE 4

4

CS486/686 Lecture Slides (c) 2008 P. Poupart

19

Convenience

  • KB may contain any formula that follows the

syntax of our simple logic.

– Inconvenient: too many possible formula – Can we simplify syntax?

  • Conjunctive normal form (CNF)

– Only use ∧, ∨, ¬ – Conjunction of clauses, where each clause is a disjunction of (possibly negated) literals – Example: (V1 ∨ V2 ∨ V3) ∧ (¬V1 ∨ V2) ∧ (¬V3 ∨ V2)

CS486/686 Lecture Slides (c) 2008 P. Poupart

20

Logical equivalence

  • How do we transform a KB in CNF?
  • Logical equivalence rules

– ¬(¬A) ≡ A – (A ⇒ B) ≡ ¬A ∨ B – (A ⇔ B) ≡ (A ⇒ B) ∧ (B ⇒ A) – ¬(A ∨ B) ≡ (¬A ∧ ¬B) – ¬(A ∧ B) ≡ (¬A ∨ ¬B) – (A ∨ (B ∧ C)) ≡ ((A ∨ B) ∧ (A ∨ C))

  • Can every KB be transformed in CNF in polynomial

time and space?

– No: last rule may yield exponentially many clauses

CS486/686 Lecture Slides (c) 2008 P. Poupart

21

Inference Properties

  • Soundness: an inference algorithm that

derives only entailed sentence is sound

  • Completeness: an inference algorithm is

complete if it can derive any sentence that is entailed

  • Time and space complexity
  • Backtracking search and truth table building

are sound and complete

CS486/686 Lecture Slides (c) 2008 P. Poupart

22

Resolution

  • Idea: generate new sentences by implications

– Unit resolution: A ∧ (A ⇒ B) |= B – General resolution: (A ⇒ B) ∧ (B ⇒ C) |= (A ⇒ C)

  • How do we do this with KB in CNF?

– Unit resolution: A ∧ (¬A ∨ B) |= B – General resolution: (¬A ∨ B) ∧ (¬B ∨ C) |= (¬A ∨ C)

CS486/686 Lecture Slides (c) 2008 P. Poupart

23

Resolution

  • Algorithm: apply resolution to every possible

pair of clauses until

– Empty clause is generated: false KB – No more clauses can be generated: all generated clauses are entailed

  • Complete? Yes
  • Sound? Yes

CS486/686 Lecture Slides (c) 2008 P. Poupart

24

Local Search

  • Idea: start with a variable configuration and

flip the truth values of some variables until a satisfiable assignment is found

  • Examples:

– GSAT: greedy SAT – WALKSAT: randomized version of GSAT

slide-5
SLIDE 5

5

CS486/686 Lecture Slides (c) 2008 P. Poupart

25

GSAT

  • Goal: maximize number of satisfied clauses
  • Algorithm:

– Start with a variable configuration – Repeat until configuration satisfies KB

  • Flip truth assignment of variable that yields that highest

number of satisfied clauses

  • Space: O(N) where N = # of variables
  • Complete? No, can get stuck in local optima

CS486/686 Lecture Slides (c) 2008 P. Poupart

26

WALKSAT

  • Randomized GSAT
  • Algorithm:

– Start with a variable configuration – Repeat until configuration satisfies KB

  • Pick random unsatisfied clause
  • Flip truth value of variable in the clause that yields the highest

# of satisfied clauses if # of satisfied clauses increases

  • Otherwise, with probability p, flip best variable and probability

1-p, flip random variable.

  • Space: O(N) where N = # of variables
  • Complete? No, requires an infinite amount of time

CS486/686 Lecture Slides (c) 2008 P. Poupart

27

Effectiveness of SAT solvers

  • SAT is NP-Complete
  • Surprisingly, WALKSAT and Backtracking

search are quite effective in practice. Why?

  • Most problems are easy:

– High probability of satisfiability – High probability of unsatisfiability

CS486/686 Lecture Slides (c) 2008 P. Poupart

28

Effectiveness of SAT solvers

CS486/686 Lecture Slides (c) 2008 P. Poupart

29

Next class

  • First-order logic

– Russell and Norvig, Chapter 8