logical agents copyright, 1996 © dale carnegie & associates, inc. chapter 7 spring 2005

22
Logical Agents Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 7 Spring 2005

Post on 21-Dec-2015

222 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Logical Agents Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 7 Spring 2005

Logical Agents

Copyright, 1996 © Dale Carnegie & Associates, Inc.

Chapter 7

Spring 2005

Page 2: Logical Agents Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 7 Spring 2005

CS 471/598, CBS598 by H. Liu 2

A knowledge-based agentAccepting new tasks in explicit goalsKnowing about its world current state of the world, unseen properties

from percepts, how the world evolves help deal with partially observable

environments help understand “John threw the brick thru the

window and broke it.” – natural language understanding

Reasoning about its possible course of actionsAchieving competency quickly by being told or learning new knowledge

Page 3: Logical Agents Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 7 Spring 2005

CS 471/598, CBS598 by H. Liu 3

Knowledge BaseA knowledge base (KB) is a set of representations (sentences) of facts about the world.TELL and ASK - two basic operations to add new knowledge to the KB to query what is known to the KBInfer - what should follow after the KB has been TELLed.A generic KB agent (Fig 7.1)

Page 4: Logical Agents Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 7 Spring 2005

CS 471/598, CBS598 by H. Liu 4

Three levels of A KB Agent Knowledge level (the most abstract)Logical level (knowledge is of sentences)Implementation level

Building a knowledge base A declarative approach - telling a KB agent what

it needs to know A procedural approach – encoding desired

behaviors directly as program code A learning approach - making it autonomous

Page 5: Logical Agents Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 7 Spring 2005

CS 471/598, CBS598 by H. Liu 5

Specifying the environmentThe Wumpus world (Fig 7.2) in PEAS

Performance: +1000 for getting the gold, -1000 for being dead, -1 for each action taken, -10 for using up the arrow

Goal: bring back gold as quickly as possible Environment: 4X4, start at (1,1) ... Actions: Turn, Grab, Shoot, Climb, Die Sensors: (Stench, Breeze, Glitter, Bump, Scream) It’s possible that the gold is in a pit or surrounded by

pits -> try not to risk life, just go home empty-handed

The variants of the Wumpus world – they can be very difficult

Multiple agents Mobile wumpus Multiple wumpuses

Page 6: Logical Agents Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 7 Spring 2005

CS 471/598, CBS598 by H. Liu 6

Acting & reasoning Let’s play the wumpus game!

The conclusion: “what a fun game!”Another conclusion: If the available information is correct, the conclusion is guaranteed to be correct.

Page 7: Logical Agents Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 7 Spring 2005

CS 471/598, CBS598 by H. Liu 7

RepresentationKnowledge representation Syntax - the possible configurations that can

constitute sentences Semantics - the meaning of the sentences

x > y is a sentence about numbers; or x+y=4; A sentence can be true or false Defines the truth of each sentence w.r.t. each

possible world What are possible worlds for x+y = 4

Entailment: one sentence logically follows another |= , iff is true, is also true Sentences entails sentence w.r.t. aspects

follows aspect (Fig 7.6)

Page 8: Logical Agents Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 7 Spring 2005

CS 471/598, CBS598 by H. Liu 8

ReasoningKB entails sentence s if KB is true, s is true Model checking (Fig 7.5) for two

sentences/models Asking whether KB entails s?

S1 = “There is no pit in [1,2]” -> yes or no? S2 = “There is no pit in [2,2]” -> yes or no?

An inference procedure can generate new valid sentences or verify if a

sentence is valid given KB is sound if it generates only entailed sentences

A proof is the record of operation of a sound inference procedureAn inference procedure is complete if it can find a proof for any sentence that is entailed.

Page 9: Logical Agents Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 7 Spring 2005

CS 471/598, CBS598 by H. Liu 9

InferenceSound reasoning is called logical inference or deduction.A sentence is valid or necessarily true iff it is true under all possible interpretations in all possible worlds (a model is a world). Valid sentences are tautologiesA sentence is satisfiable iff there is some interpretation in some world for which it is true. E.g., in Figure 7.9, there are three true

models for the KB with 5 rules.

Page 10: Logical Agents Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 7 Spring 2005

CS 471/598, CBS598 by H. Liu 10

LogicsA logic consists of the following: A formal system for describing states

of affairs, consisting of syntax (how to make sentences) and semantics (to relate sentences to states of affairs).

A proof theory - a set of rules for deducing the entailments of a set of sentences.

Some examples of logics ...

Page 11: Logical Agents Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 7 Spring 2005

CS 471/598, CBS598 by H. Liu 11

Propositional LogicIn this logic, symbols represent whole propositions (facts)e.g., D means “the wumpus is dead”

W1,1 Wumpus is in square (1,1)S1,1 there is stench in square (1,1).

Propositional logic can be connected using Boolean connectives to generate sentences with more complex meanings, but does not specify how objects are represented.

Page 12: Logical Agents Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 7 Spring 2005

CS 471/598, CBS598 by H. Liu 12

Other logicsFirst order logic represents worlds using objects and predicates on objects with connectives and quantifiers.Temporal logic assumes that the world is ordered by a set of time points or intervals and includes mechanisms for reasoning about time.

Page 13: Logical Agents Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 7 Spring 2005

CS 471/598, CBS598 by H. Liu 13

Other logics (2)Probability theory allows the specification of any degree of belief.Fuzzy logic allows degrees of belief in a sentence and degrees of truth.

Page 14: Logical Agents Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 7 Spring 2005

CS 471/598, CBS598 by H. Liu 14

Propositional logicSyntax A set of rules to construct sentences:

and, or, imply, equivalent, not literals, atomic or complex sentences BNF grammar (Fig 7.7, P205)

Semantics Specifies how to compute the truth value

of any sentence Truth table for 5 logical connectives (Fig

7.8)

Page 15: Logical Agents Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 7 Spring 2005

CS 471/598, CBS598 by H. Liu 15

InferenceTruth tables can be used not only to define the connectives, but also to test for validity:

If a sentence is true in every row, it is valid. What if a truth table for “Premises imply Conclusion”

A simple knowledge base for Wumpus Five rules (P208) What if we write R2 as B1,1 => (P1,2 v P2,1)

KB |= . Let’s check its validity (Fig 7.9) A truth-table enumeration algorithm (Fig 7.10)

There are only finitely many models to examine, but it is exponential in size of the input (n)

A reasoning system should be able to draw conclusions that follow from the premises, regardless of the world to which the sentences are intended to refer.

Page 16: Logical Agents Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 7 Spring 2005

CS 471/598, CBS598 by H. Liu 16

Equivalence, validity, and satisfiability

Logical equivalence requires |= and |= Validity: a sentence is true in all models Valid sentences are tautologies (P v !P) Deduction theorem: for any and , |= iff

the sentence ( ) is valid

Satisfiability: a sentence is satisfiable if it is true in some models If is true in a model m, then m satisfies

Validity and satisfiability: is valid iff ! is unstatisfiable; contrapositively, is satisfiable iff ! is not valid

Page 17: Logical Agents Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 7 Spring 2005

CS 471/598, CBS598 by H. Liu 17

Reasoning Patterns in Prop Logic

|= iff the sentence ( ^ !) is unstatisfiable are known axioms Proof by refutation (or contradiction): assuming is F,

we now need to prove !(^T) is valid, …

Inference rules Modus Ponens, AND-elimination, Bicond-elimination All the logical equivalences in Fig 7.11

A proof is a sequence of applications of inference rules

An example to conclude neither [1,2] nor [2,1] contains a pit

Monotonicity (consistency): the set of entailed sentences can only increase as information is added to KB

For and , if KB |= then KB^ |= Propositional logic and first-order logic are monotonic

Page 18: Logical Agents Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 7 Spring 2005

CS 471/598, CBS598 by H. Liu 18

Resolution – an inference ruleAn example of resolution R11, R12 (new facts added), R13, R14 (derived

from R11, and R12), R15 from R3, R16, R17 – P3,1 (there is a pit in [3,1]) (P213)

Unit resolution: l1 v l2 …v lk, m = !li We have seen examples earlier

Full resolution: l1 v l2 …v lk, m1 v…v mn where li = mj An example: (P1,1vP3,1, !P1,1v!P2,2)/P3,1v!

P2,2Soundness of resolution Considering literal li,

If it’s true, mj is false, then … If it’s false, …

Page 19: Logical Agents Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 7 Spring 2005

CS 471/598, CBS598 by H. Liu 19

Refutation completeness Resolution can always be used to either confirm

or refute a sentenceConjunctive normal form (CNF) A conjunction of disjunctions of literals A sentence in k-CNF has exactly k literals per

clause (l1,1 v … v l1,k) ^…^ (ln,1 v …v ln,k) A simple conversion procedure (turn R2 to

CNF,P. 215)A resolution algorithm (Fig 7.12) An example (KB= R2^R4, to prove !P1,2, Fig.

7.13)Completeness of resolution Ground resolution theorem

Page 20: Logical Agents Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 7 Spring 2005

CS 471/598, CBS598 by H. Liu 20

Horn cluasesA Horn clause is a disjunction of literals of which at most one is positive An example: (!L1,1 v !Breeze V B1,1) An Horn sentence can be written in the form

P1^P2^…^Pn=>Q, where Pi and Q are nonnegated atoms

Deciding entailment with Horn clauses can be done in linear time in size of KB

Inference with Horn clauses can be done thru forward and backward chaining Forward chaining is data driven Backward chaining works backwards from the query,

goal-directed reasoning

Page 21: Logical Agents Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 7 Spring 2005

CS 471/598, CBS598 by H. Liu 21

An Agent for WumpusThe knowledge base (p208)Finding pits and wumpus using logical inferenceKeeping track of location and orientationTranslating knowledge into action A1,1^EastA^W2,1=>!Forward

Problems with the propositional agent too many propositions to handle (“Don’t go

forward if…”) hard to deal with change (time dependent

propositions)

Page 22: Logical Agents Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 7 Spring 2005

CS 471/598, CBS598 by H. Liu 22

SummaryKnowledge is important for intelligent agentsSentences, knowledge basePropositional logic and other logicsInference: sound, complete; valid sentencesPropositional logic is impractical for even very small worlds Therefore, we need to continue our AI class ...