Logical Agents: Propositional Logic - PowerPoint PPT Presentation

1 / 58
About This Presentation
Title:

Logical Agents: Propositional Logic

Description:

Department of Mathematics, Statistics, and Computer Science ... Validity. A sentence is valid if it is true in all models. Also known as a tautology. P ... – PowerPoint PPT presentation

Number of Views:330
Avg rating:3.0/5.0
Slides: 59
Provided by: CraigAS7
Category:

less

Transcript and Presenter's Notes

Title: Logical Agents: Propositional Logic


1
Logical Agents Propositional Logic
  • Craig A. Struble, Ph.D.
  • Department of Mathematics, Statistics, and
    Computer Science
  • Marquette University

2
Overview
  • Knowledge Based Agents
  • Logic
  • Propositional Logic
  • Reasoning in Propositional Logic
  • Agents Based on Propositional Logic

3
Knowledge Based Agents
  • Knowledge representation
  • Reasoning with knowledge
  • Determining which action to take
  • Logic deals with both of these
  • For now, definite knowledge
  • Knowledge that is true or false in the world
  • Later, uncertain knowledge

4
Knowledge Based Agents
Percepts
Sensors
State
How the world evolves
What the world is like now
What my actions do
What will it be like if I do action A
Environment
Knowledge Base
Reasoning
What action I should do now
Goals
Actions
Actuators
Agent
5
Knowledge Based Agents
  • The knowledge base (KB) is the central component
  • A set of sentences representing assertions about
    the world
  • Sentences are represented with a knowledge
    representation language
  • Two operations on KBs
  • Tell and Ask
  • Both may involve inferencing, deriving new
    sentences from old

6
KB Agent Program
Update state
Result of action
  • Agent may have some initial sentences in KB
  • Background knowledge

7
Importance of KB Agents
  • Agents are described at knowledge level
  • Tell the agent what it knows and what its goals
    are
  • Agents are independent at the implementation
    level
  • Dont care how the knowledge base is implemented
  • Linked lists, neural networks, etc.

8
Declarative vs. Procedural
  • Declarative programming
  • Design representation language making it easy to
    express knowledge
  • Simplify construction of solution
  • Procedural programming
  • Knowledge is embodied in the algorithms and
    program code itself
  • Potentially more efficient, but more difficult to
    develop solution

9
Logic
  • A logic consists of syntax and semantics
  • Syntax defines well formed sentences
  • (Infix) Arithmetic
  • xy4
  • x4y
  • Semantics defines meaning of sentences
  • In logic, defines the truth of each sentence with
    respect to each possible world
  • Possible World 1 x1, y3
  • Possible World 2 x2, y1

10
Models
  • A model is a mathematical abstraction of a
    possible world
  • Possible worlds represent real environments
  • The phrase m is a model of a means that the
    sentence a is true in model m.
  • Possible models are possible assignments to
    variables
  • Suppose real world is tennis matches. Let x and y
    represent the number of men and women playing
    respectively.
  • What are the possible models?
  • How many of those are a model of xy4?
  • The model fixes the truth or falsehood of every
    relevant sentence.

11
Logical Reasoning
  • Consider logical entailment between sentences a
    and b
  • Definition a b if and only if, in every model
    in which a is true, b is also true
  • Algebra xy4 x4-y

a b
12
Logical Reasoning
  • Extend entailment to knowledge bases
  • Example
  • KB is x1, y3 and a is xy4
  • What if KB is x1? Does KB a?
  • Logical inference, transformations to derive
    conclusions
  • Model checking, enumerate possible models to
    check entailment

KB a
13
Logical Reasoning
  • We derive sentences from an inference algorithm i
  • a is derived from KB by i
  • If i derives only entailed sentences, then i is
    sound or truth-preserving.
  • If i can derive any entailed sentence, then i is
    complete.

KB a
14
Reasoning Process
Sentence
Sentences (KB)
Entails
Representation
Semantics
Semantics
World
Aspects of the real world
Aspect of the real world
Follows
15
Propositional Logic
  • A very simple logic
  • Syntax, Semantics, Inference algorithm
  • Centered around propositions
  • Statements about the world that may be true or
    false
  • e.g., Grass is green Water is wet It snowed
    last Tuesday.

16
Syntax
Precedence negation, conjunction, disjunction,
implication, biconditional
17
Semantics
  • Truth table

18
Semantics
  • Extended to complex sentences through recursive
    process

19
Mine Sweeper
  • Design a logical agent to play minesweeper

20
PEAS Analysis Mine Sweeper
  • Performance measure
  • 1 for each mine correctly identified, -1 for
    incorrectly identifying a mine, -1000 for
    selecting a location containing a mine, 1000 for
    identifying all mines.
  • Environment
  • 9 x 9 board, each square has a mine with
    probability 0.1
  • Actuators
  • Agent can mark a location as containing a mine,
    can mark a location as unknown, or select a
    location for viewing
  • Sensors
  • Agent can sense the number of mines surrounding
    adjacent locations
  • Agent knows number of mines remaining

21
Propositional Logic Representation
  • Let Xi,j be true iff location i,j contains a
    mine.
  • A location adjacent to 3,4 contains a mine
  • There is exactly one mine adjacent to location
    3,4

22
Inference
  • Suppose location 1,1 has exactly one adjacent
    mine, and 1,2 is marked with a mine.
  • KB ?X2,1?
  • KB

23
Inference
  • Enumerate all possible worlds,
  • KB is true (i.e. every sentence is true) iff
    sentence is true

24
Inference
25
Logical Equivalence
  • Two sentences a and b are logically equivalent if
    they are true in the same set of models.
  • P?Q ? Q?P
  • Truth table entries are exactly the same for a
    and b
  • When reasoning, can replace a with b

26
Standard Equivalences
27
Validity
  • A sentence is valid if it is true in all models
  • Also known as a tautology
  • P ? ?P
  • Truth table entries are all true

28
Satisfiability
  • A sentence is satisifiable if it is true in some
    model
  • (P?Q)?R
  • True when Ptrue, Qfalse, Rtrue.
  • Satisfiability was the first problem shown to be
    NP-complete

29
Exercises
  • Smoke?Smoke
  • Smoke?Fire
  • ((Smoke?Heat)?Fire) ? ((Smoke?Fire)?(Heat?Fire))

30
Refutation
  • One important consequence of validity and
    satisfiability is proof by refutation aka proof
    by contradiction
  • This turns out to be useful for inference
    algorithms based on resolution

31
Reasoning Patterns
  • Model checking by enumerating all possible models
    is a kind of uninformed search
  • Considers several possible models that do not
    model the knowledge base
  • What if we could derive statements directly from
    our knowledge base?
  • Would like the algorithm to be sound and complete

32
Reasoning Patterns
  • Standard patterns of inference
  • Derive chains of conclusions leading to goal
  • The patterns of inference are called inference
    rules
  • Idea When a sentence is true, what other true
    sentences can we derive?

33
Modus Ponens
  • Sentences a and b

Sentences in KB
Sentence inferred
WadeScores25 ?LouisvilleLoses WadeScores25
LouisvilleLoses
34
And-Elimination
or b
?MadisonRocks ? MarquetteRocks
?MadisonRocks
35
Logical Equivalences
  • Any logical equivalence can be used as an
    inference rule
  • e.g. De Morgan

36
Proofs
Is a entailed by the KB?
37
Resolution
WadeScores20??LouisvilleWins LouisvilleWins?Marque
tteWins
WadeScores20?MarquetteWins
38
Exercise
  • If the unicorn is mythical, then it is immortal,
    but if it is not mythical, then it is a mortal
    mammal. If the unicorn is either immortal or a
    mammal, then it is horned. The unicorn is magical
    if it is horned.
  • Can you prove its mythical? Magical? Horned?

39
Solution
40
Proofs As Search
  • Initial state
  • Initial KB
  • Successor function
  • Each KB that results from applying one inference
    rule to selected rules in the KB
  • Goal test
  • Does the KB contain the goal sentence
  • Path cost
  • The number of inference rules applied

41
Resolution
  • The resolution inference rule is complete and
    sound when used with a complete search algorithm
  • Its the only rule we need
  • Actually refutation complete
  • Does not enumerate true sentences
  • Does answer whether or not a sentence is true
  • To use resolution only, transform sentences into
    a normal form

42
Conjunctive Normal Form (CNF)
  • Theorem Every sentence in propositional logic is
    logically equivalent to a conjunction of
    disjunction of literals.
  • k-CNF
  • Every sentence can be transformed into 3-CNF.

43
Converting to CNF
  • Eliminate ?, with (a?b)?(b?a)
  • Eliminate ?, with (?a?b)
  • Move ? inwards, double negation, de Morgan
  • Distribute ? over ?

44
Exercise
45
Resolution Algorithm
  • Proof by contradiction
  • KB??a unsatisfiable, i.e. derive empty clause

Resolve each pair of clauses until empty clause
or no new clauses derived.
46
Resolution Algorithm
47
Resolution Algorithm
  • This algorithm is complete
  • Resolution closure is the set of all clauses
    derivable by repeated applications of the
    resolution rule.
  • Theorem If a set of clauses is unsatisfiable,
    then the resolution closure of those clauses
    contains the empty clause.
  • Still exponential, but we can do better if we
    restrict our knowledge base.

48
Horn Clauses
  • Linear time algorithms exist when knowledge bases
    are restricted to Horn clauses
  • A disjunction of literals of which at most one is
    positive

Ok
No!
49
Horn Clauses
  • Often written as a?b?g?d
  • Exercise Show this is equivalent
  • Used in Prolog
  • The positive literal d is the head
  • The negative literals a,b,g form the body
  • A clause with no negative literals (e.g., ?d ) is
    a fact
  • A clause with no positive literals (e.g., a?b?g?
    false) is an integrity constraint

50
Inferencing
  • Forward Chaining
  • Start with the knowledge base and through
    repeated applications of Modus Ponens, derive all
    atomic sentences.
  • Data driven
  • Backward Chaining
  • Start with the query q
  • Find implications that conclude (i.e. have head)
    q
  • If all premises are true, then q is true,
    otherwise use backward chaining on premises with
    unknown values.
  • Goal-directed

51
AND-OR Graphs
Or
And
52
Forward Chaining Algorithm
53
Forward Chaining Example
1
0
2
1
0
2
1
0
0
1
2
2
1
0
54
Backward Chaining Example
55
Forward/Backward Chaining
  • Linear time in size of AND-OR graph
  • Backward chaining can be sub-linear because it
    can ignore premises not involved in query
  • Many problems can be represented with Horn
    clauses only
  • The difficulty is to figure out how!

56
Agents Based on Propositional Logic
function PL-MineSweeper-Agent(percept) returns an
action inputs percept, a list of
(i,j,number) static KB, initially empty
x,y, location of last location probed
plan, an action sequence Tell(KB,
Xx,y) for each p in percept create sentence
representing number mines around i,j Tell(KB,
sentence) if plan is not empty, then action
Pop(plan) else for each location u,v not
probed if Ask(KB, Xu,v) is false then
Push(plan, Probe(u,v)) if plan is not
empty, then action Pop(plan) else action
probe a randomly selected unprobed
location update x,y with location probed in
action return action
57
Problems with PL Agents
  • As board size increases, the number of
    propositions increase dramatically
  • Building the sentences for bombs in surrounding
    squares is tedious
  • Consider situations with agents in time

58
Summary
  • Introduced knowledge based agents
  • Represent and reason with knowledge
  • Logic
  • Formal representations of knowledge and methods
    of inference
  • Propositional Logic
  • Simple logic
  • Restricted expressiveness
  • Many methods of inference
  • Efficient with restricted representations
Write a Comment
User Comments (0)
About PowerShow.com