S P Vimal, Department of CSIS, BITS, Pilani. Agenda EA C461 Artificial Intelligence 2 A quick...

Post on 04-Jan-2016

218 views 0 download

Transcript of S P Vimal, Department of CSIS, BITS, Pilani. Agenda EA C461 Artificial Intelligence 2 A quick...

S P Vimal, Department of CSIS, BITS, Pilani

Agenda

EA C461 Artificial Intelligence

2

A quick review of syntax & semantics Entailment in Propositional LogicDiscussion

Review: Propositional logic: Syntax

EA C461 Artificial Intelligence

3

Propositional logic is the simplest logic

Atomic sentence : A Propositional symbol (written in upper case, just for notational convenience)

W1,3 – Wumpus is in room (1,3) True / False

Review: Propositional logic: Syntax

EA C461 Artificial Intelligence

4

If S is a sentence, S is a sentence (negation) If S1 and S2 are sentences, (S1 S2)is a sentence

(conjunction) If S1 and S2 are sentences, ( S1 S2) is a sentence

(disjunction) If S1 and S2 are sentences, (S1 S2) is a sentence

(implication) If S1 and S2 are sentences, (S1 S2) is a sentence

(biconditional)Precedence , , , ,

Semantics

Defines the rules for defining the truth of a sentence w.r.t a particular model.

Let the sentence in the KB make use of the proposition symbols P12,P22,P31. One possible model is m1 =

{P12=true,P22=false,P31=true}

With these symbols, 8 possible models, can be enumerated automatically.

Rules for evaluating truth with respect to a model m:S is true iff S is false S1 S2 is true iff S1 is true and S2 is trueS1 S2 is true iff S1is true or S2 is trueS1 S2 is true iff S1 is false or S2 is true i.e., is false iff S1 is true and S2 is falseS1 S2 is true iff S1S2 is true and S2S1 is true

Review: Truth tables for connectives

EA C461 Artificial Intelligence

6

Wumpus world sentences

EA C461 Artificial Intelligence

7

Assume a wumpus world without wumpus (??)

Let Pi,j be true if there is a pit in [i, j].

Let Bi,j be true if there is a breeze in [i, j].

R1: P1,1

"Pits cause breezes in adjacent squares"

R2: B1,1 (P1,2 P2,1)

R3: B2,1 (P1,1 P2,2 P3,1)

R4: B1,1R5: B2,1

Truth tables for inference

EA C461 Artificial Intelligence

8

Inference by enumeration

EA C461 Artificial Intelligence

9

Depth-first enumeration of all models is sound and complete

For n symbols, time complexity is O(2n), space complexity is O(n)

Equivalence

Two sentences α and β are equivalent, if they are true in the same set of models, which is written as α <=> β

In other words, α ≡ β if and only if α ╞ β and β ╞ α

Validity

A sentence is valid, if it is true in all models Example : P V ר P Tautologies

Deduction theorem:

For any sentence α and β, α ╞ β if and only if (α ╞ β ) valid

Now, What is inference? Rephrase in terms of Deduction Theorem? All you do is to check the validity of KB╞ α

Conversely???

Conversely, every valid implication represents an inference.

Satisfiablity

A sentence is satisfiable if it is true in some model.

If a sentence α is true in model m, then m satisfies α, or we say m is the model of α.

How do you verify if a sentence is satisfiable? Enumerate the possible models, until one is found

to satisfy.

Many problems in Computer Science can be reduced to a satisfiablity problems Ex. CSP is all about verifying if the constraints are

satisfiable by some assignments

Connection between Validity and Satisfiablity

α is valid iff רα is not satisfiable How do we use this observation for

‘entailment’?Let us phrase it this way

α╞ β if and only if the sentence (α Λ רβ ) is not satisfiable.

Reduction to an absurd thing / Proof by refutation / Proof by contradiction

Proof methods

EA C461 Artificial Intelligence

14

Proof methods divide into (roughly) two kinds: Application of inference rules

Legitimate (sound) generation of new sentences from old Proof = a sequence of inference rule applications

Can use inference rules as operators in a standard search algorithm

Typically require transformation of sentences into a normal form

Model checking truth table enumeration (always exponential in n) improved backtracking, e.g., Davis--Putnam-Logemann-

Loveland (DPLL) heuristic search in model space (sound but incomplete)

e.g., min-conflicts-like hill-climbing algorithms

A property

Monotonicity Set of entailed sentences can only increase as

information is added to the knowledge base. If KB β╞ then KB Λ α β ╞

Inference rules can be applied whenever suitable premises are found in the Knowledge base.

EA C461 Artificial Intelligence

15

Resolution

EA C461 Artificial Intelligence

16

Conjunctive Normal Form (CNF) conjunction of disjunctions of literals

clausesE.g., (A B) (B C D)

Resolution inference rule (for CNF):

li … lk, m1 … mn

li … li-1 li+1 … lk m1 … mj-1 mj+1 ... mn

where li and mj are complementary literals.

E.g., P1,3 P2,2, P2,2

P1,3

Resolution is sound and complete for propositional logic

Resolution algorithm

EA C461 Artificial Intelligence

17

Proof by contradiction, i.e., show KBα unsatisfiable

Resolution example

EA C461 Artificial Intelligence

18

KB = (B1,1 (P1,2 P2,1)) B1,1

α = P1,2

Completeness of Resolution

Resolution Closure (RC) RC(S) – set of clauses derivable by repeated

application of resolution rule to clauses in S or their derivatives

RC(S) must be finiteCompleteness is entailed by “Ground Resolution

Theorem” “If a set of clauses is unsatisfiable, then the

resolution closure of those clauses contains the empty clause ”

EA C461 Artificial Intelligence

19

Any complete search algorithm, applying only resolution can derive any conclusion entailed by any knowledge base in propositional logic

This is true only in restricted sense Resolution can always be used to either

confirm or refute a sentence Resolution cannot be used to enumerate

entailed sentences

Refutation completeness

EA C461 Artificial Intelligence

20

Contd…

Forward and backward chaining

EA C461 Artificial Intelligence

21

Horn Form (restricted)KB = conjunction of Horn clauses

Horn clause = proposition symbol; or (conjunction of symbols) symbol

E.g., C (B A) (C D B) Modus Ponens (for Horn Form): complete for Horn KBs

α1, … ,αn, α1 … αn ββ

Can be used with forward chaining or backward chaining.

These algorithms are very natural and run in linear time

Forward chaining

EA C461 Artificial Intelligence

22

Idea: fire any rule whose premises are satisfied in the KB, add its conclusion to the KB, until query is found

Forward chaining algorithm

EA C461 Artificial Intelligence

23

Forward chaining is sound and complete for Horn KB

Forward chaining example

EA C461 Artificial Intelligence

24

Forward chaining example

EA C461 Artificial Intelligence

25

Forward chaining example

EA C461 Artificial Intelligence

26

Forward chaining example

EA C461 Artificial Intelligence

27

Forward chaining example

EA C461 Artificial Intelligence

28

Forward chaining example

EA C461 Artificial Intelligence

29

Forward chaining example

EA C461 Artificial Intelligence

30

Forward chaining example

EA C461 Artificial Intelligence

31

Proof of completeness

EA C461 Artificial Intelligence

32

FC derives every atomic sentence that is entailed by KB1. FC reaches a fixed point where no new atomic

sentences are derived2. Consider the final state as a model m, assigning

true/false to symbols3. Every clause in the original KB is true in m

a1 … ak b

4. Hence m is a model of KB5. If KB╞ q, q is true in every model of KB, including m

Backward chaining

EA C461 Artificial Intelligence

33

Idea: work backwards from the query q:

to prove q by BC,check if q is known already, or

prove by BC all premises of some rule concluding q

Avoid loops: check if new subgoal is already on the goal stack

Avoid repeated work: check if new subgoal

1. has already been proved true, or

2. has already failed

Backward chaining example

EA C461 Artificial Intelligence

34

Backward chaining example

EA C461 Artificial Intelligence

35

Backward chaining example

EA C461 Artificial Intelligence

36

Backward chaining example

EA C461 Artificial Intelligence

37

Backward chaining example

EA C461 Artificial Intelligence

38

Backward chaining example

EA C461 Artificial Intelligence

39

Backward chaining example

EA C461 Artificial Intelligence

40

Backward chaining example

EA C461 Artificial Intelligence

41

Backward chaining example

EA C461 Artificial Intelligence

42

Backward chaining example

EA C461 Artificial Intelligence

43

Forward vs. backward chaining

EA C461 Artificial Intelligence

44

FC is data-driven, automatic, unconscious processing, e.g., object recognition, routine decisions

May do lots of work that is irrelevant to the goal

BC is goal-driven, appropriate for problem-solving, e.g., Where are my keys? How do I get into a PhD program?

Complexity of BC can be much less than linear in size of KB

Refining model checking

Algorithms checks satisfiability The connection between finding a solution to a

CSP and finding satisfying model for a logical sentence implies the existence of backtracking algorithm

DPLL (Davis, Putnam, Logemann & Loveland)

The DPLL algorithm

EA C461 Artificial Intelligence

46

Determine if an input propositional logic sentence (in CNF) is satisfiable.

Improvements over truth table enumeration:1. Early termination

A clause is true if any literal is true.A sentence is false if any clause is false.

2. Pure symbol heuristicPure symbol: always appears with the same "sign" in all clauses. e.g., In the three clauses (A B), (B C), (C A), A and B are

pure, C is impure. Make a pure symbol literal true.

3. Unit clause heuristicUnit clause: only one literal in the clauseThe only literal in a unit clause must be true.

The DPLL algorithm

EA C461 Artificial Intelligence

47

The WalkSAT algorithm

EA C461 Artificial Intelligence

48

Incomplete, local search algorithm Evaluation function: The min-conflict heuristic of minimizing the

number of unsatisfied clauses Balance between greediness and randomness

The WalkSAT algorithm

EA C461 Artificial Intelligence

49

Hard satisfiability problems

EA C461 Artificial Intelligence

50

Consider randomly generated 3-CNF sentences. e.g.,

(D B C) (B A C) (C B E) (E D B) (B E C)

m = number of clauses

n = number of symbols This CNF has 16 models out of 32 possible assignments. Quite easy to solve. So where are hard problems?

Fix n and keep increasing m,

Hard satisfiability problems

EA C461 Artificial Intelligence

51

Hard satisfiability problems

EA C461 Artificial Intelligence

52

Median runtime for 100 satisfiable random 3-CNF sentences

Inference-based agents in the Wumpus world

EA C461 Artificial Intelligence

53

A wumpus-world agent using propositional logic:

P1,1

W1,1

Bx,y (Px,y+1 Px,y-1 Px+1,y Px-1,y)

Sx,y (Wx,y+1 Wx,y-1 Wx+1,y Wx-1,y)

W1,1 W1,2 … W4,4

W1,1 W1,2

W1,1 W1,3 …

64 distinct proposition symbols, 155 sentences

EA C461 Artificial Intelligence54

Keeping Track of Location and Orientation

EA C461 Artificial Intelligence

55

Should our KB include statements like

L11 Facing Right Forward L 21

What is the problem here?

L111Facing Right1 Forward1 L 21

2

Facing Right TurnLeft 1 FacingUp2

Result : tens of thousands of such sentences

Summary

EA C461 Artificial Intelligence

56

Logical agents apply inference to a knowledge base to derive new information and make decisions

Basic concepts of logic: syntax: formal structure of sentences semantics: truth of sentences wrt models entailment: necessary truth of one sentence given another inference: deriving sentences from other sentences soundness: derivations produce only entailed sentences completeness: derivations can produce all entailed sentences

Wumpus world requires the ability to represent partial and negated information, reason by cases, etc.

Resolution is complete for propositional logicForward, backward chaining are linear-time, complete for Horn clauses

Propositional logic lacks expressive power