0% found this document useful (0 votes)
19 views9 pages

PropositionalLogic1 6pp

The document describes knowledge-based agents and provides an example of the Wumpus World environment. Knowledge-based agents can represent and reason with general knowledge in flexible ways to solve different problems. The Wumpus World simulates a 4x4 grid world with hazards and a goal for an agent to complete. The agent uses sensors to perceive its environment and logical reasoning over its knowledge base to determine the best actions despite not knowing the full configuration of the world.

Uploaded by

salman khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views9 pages

PropositionalLogic1 6pp

The document describes knowledge-based agents and provides an example of the Wumpus World environment. Knowledge-based agents can represent and reason with general knowledge in flexible ways to solve different problems. The Wumpus World simulates a 4x4 grid world with hazards and a goal for an agent to complete. The agent uses sensors to perceive its environment and logical reasoning over its knowledge base to determine the best actions despite not knowing the full configuration of the world.

Uploaded by

salman khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Knowledge-based Agents

• Can represent knowledge


• And reason with this knowledge
CS 331: Artificial Intelligence
• How is this different from the knowledge
Propositional Logic I used by problem-specific agents?
– More general
– More flexible

1 2

Outline Knowledge-based Agents


1. Knowledge-based Agents • Knowledge of problem solving agents is
2. The Wumpus World specific and inflexible
• Knowledge-based agents can benefit from
3. Logic knowledge expressed in very general forms,
combining information in different ways to
suit different purposes
• Knowledge-based agents can combine
general knowledge with current percepts to
infer hidden aspects of the current state

3 4

Knowledge-based Agents Knowledge is definite


Flexibility of knowledge-based agents: • Knowledge of logical agents is always definite
• Accept new tasks in the form of explicitly • That is, each proposition is entirely true or entirely
false
described goals
• Agent may be agnostic about some propositions
• Achieve competence quickly by being told
• Logic doesn’t handle uncertainty well
or learning new knowledge about the
environment
• Adapt to changes in the environment by
updating the relevant knowledge

5 6

1
The Knowledge Base (KB) The Knowledge Base (KB)
TELL
• A knowledge base is a set • Need to add new
of “sentences” sentences to the
• Each sentence is knowledge base (this task
Knowledge Base:
expressed in a knowledge Knowledge Base: is called TELL)
Sentence 1 Sentence 1
Sentence 2 representation language Sentence 2 • Need to query what is
: :
Sentence N and represents some Sentence N known (this task is called
assertion about the world ASK)

ASK
7 8

Knowledge Base Example Inference


TELL
• Inference: deriving new sentences from old
ones
• Must obey fundamental requirement: when
Knowledge Base: one ASKs a question of the knowledge
Murderer wasn’t Colonel Mustard
Murderer wasn’t Miss Scarlett When you discover a new base, answer should follow from what has
Weapon wasn’t the Gun fact like “The murder room been TELLed to the KB previously
Weapon wasn’t the Candlestick wasn’t the study”, you would
Room wasn’t the Library
TELL the KB
You can then ASK the KB
what to ask next
ASK
9 10

A Generic Knowledge-based Agent A Generic Knowledge-based Agent


Input: Percept Input: Percept
Starts out with
background
knowledge

Knowledge Knowledge
Base Base

Output: Action Output: Action

11 12

2
A Generic Knowledge-based Agent The Wumpus World
Input: Percept
• Wumpus eats anyone
that enters its room
1. TELL the KB what it • Wumpus can be shot
perceives by an agent, but agent
Knowledge 2. ASK the KB what action has one arrow
Base it should perform • Pits trap the agent (but
3. TELL the KB that the not the wumpus)
action was executed
• Agent’s goal is to pick
up the gold
Output: Action

13 14

The Wumpus World The Wumpus World


• Performance measure: • Actuators:
– +1000 for picking up gold, -1000 for death (meeting a – Movement:
live wumpus or falling into a pit)
– -1 for each action taken, -10 for using arrow
• Agent can move forward
• Environment: • Turn 90 degrees left or right
– 4x4 grid of rooms – Grab: pick up an object in same square
– Agent starts in (1,1) and faces right – Shoot: fire arrow in straight line in the direction
– Geography determined at the start: agent is facing
• Gold and wumpus locations chosen randomly
• Each square other than start can be a pit with
probability 0.2
15 16

The Wumpus World The Wumpus World


• Sensors: • Biggest challenge: Agent is ignorant of the
– Returns a 5-tuple of five symbols eg. [stench, breeze, configuration of the 4x4 world
glitter, bump, scream] (note that in this 5-tuple, all five
things are present. We indicate absence with the value • Needs logical reasoning of percepts in order
None) to overcome this ignorance
– In squares adjacent to the wumpus, agent perceives a
stench • Note: retrieving gold may not be possible
– In squares adjacent to a pit, agent perceives a breeze due to randomly generated location of pits
– In squares containing gold, agent perceives a glitter • Initial knowledge base contains:
– When agent walks into a wall, it perceives a bump
– Agent knows it is in [1,1]
– When wumpus is killed, it emits a woeful scream that is
perceived anywhere – Agent knows it is a safe square

17 18

3
The Wumpus World Environment
Wumpus World Example
Properties
• Fully or Partially observable?
• Deterministic or stochastic?
• Episodic or sequential?
• Static or dynamic?
• Discrete or continuous?
• Single agent or multiagent?

19 20

Wumpus World Example Wumpus World Example


1st percept is: 2nd percept is:
[None, None, None, None, None] [None, Breeze, None, None, None]
(Corresponding to [Stench, Breeze, Glitter, Must be a pit at [2,2] or [3,1] or both. We
Bump, Scream]) mark this with a P?.
Agent concludes squares [1,2], [2,1] are Only one square that is OK, so the agent
safe. We mark them with OK. A cautious goes back to [1,1] and then to [1,2]
agent will move only to a square that it
knows is OK.

Agent now moves to [2,1]

21 22

Wumpus World Example Wumpus World Example


3rd percept is: Note the difficulty of this inference:
[Stench, None, None, None, None] • Combines knowledge gained at different
times and at different places.
Wumpus must be nearby. Can’t be in [1,1]
(by rules of the game) or [2,2] (otherwise • Relies on the lack of a percept to make
agent would have detected a stench at one crucial step
[2,1])
Therefore, Wumpus must be in [1,3].
At this point, the agent moves to [2,2].
Indicate this by W!.
Lack of breeze in [1,2] means no pit in
[2,2], so pit must be in [3,1].

23 24

4
Wumpus World Example Logic
We’ll skip the agent’s state of knowledge
at [2,2] and assume it goes to [2,3].
Logic must define:
Agent detects a glitter in [2,3] so it grabs
1. Syntax of the representation language
the gold and ends the game • Symbols, rules, legal configurations
2. Semantics of the representation language
Note: In each case where the agent • Loosely speaking, this is the “meaning” of the
draws a conclusion from the sentence
available information, that conclusion • Defines the truth of each sentence with
is guaranteed to be correct if the
respect to each possible world
available information is correct
• Everything is either true or false, no in
between
25 26

Models Entailment
• We will use the word model instead of “possible α |= β means α entails β i.e. β follows
world”
logically from α, where α and β are
• “m is a model of α” means that sentence α is true
in model m sentences
• Models are mathematical abstractions which fix
the truth or falsehood of every relevant sentence Mathematically, α |= β if and only if in every
• Think of it as the possible assignments of values model in which α is true, β is also true.
to the variables
– E.g. the possible models for x + y = 4 are all possible
assignments of numbers to x and y such that they add
up to 4 Another way: if α is true, then β must also be
true.
27 28

Entailment Applied to the Wumpus Entailment Applied to the Wumpus


World World
23 = 8 possible models
• Suppose the agent moves to [2,1] because [1,2], [2,2] and
• Agent knows there is nothing in [3,1] can take each take
[1,1] and a breeze in [2,1] values true or false that
there is a pit there
• These percepts, along with the
agent’s knowledge of the rules of
the wumpus world constitute the
KB
• Given this KB, agent is interested
if the adjacent squares [1,2], [2,2] The 3 models inside the
and [3,1] contain pits. line marked KB are
those in which the KB
is true

29 30

5
Entailment Applied to the Wumpus Entailment applied to the Wumpus
World World Now let us consider the
Let us consider the models that models that support the
support the conclusion α1 = conclusion α2 = “There
“There is no pit in [1,2].” We is no pit in [2,2].” We
draw a line marked with α1 draw a line marked
around these models with α2 around these
models
In every model in which
KB is true, α1 is also true.
In some models in
Therefore KB |= α1
which KB is true, α2 is
false. Therefore KB
|≠ α2 and the agent
cannot conclude that
there is no pit in [2,2]

31 32

Logical inference Modified Wumpus World


• Entailment can be applied to derive conclusions • Breeze occurs in squares directly or
(we call this carrying out logical inference) diagonally adjacent to a pit
• Model checking: enumerates all possible models
to check that α is true in all models in which KB is
true
• If an inference algorithm i can derive α from the
KB, we write KB |- i α
• The above is pronounced “α is derived from KB
by i” or “i derives α from KB”

33 34

Modified Wumpus Exercise Soundness


• KB includes modified rules plus: • An inference algorithm that derives only
2,1 2,2 2,3 entailed sentences is called sound or truth-
S preserving
V
OK • Soundness is a good thing!
1,1 1,2
B,S
1,3 • If an inference algorithm is unsound, you
V
V can make things up as it goes along and
OK
OK derive basically anything it wants to
This (unsoundness)
• Want to reason about squares [2,2], [2,3], [1,3] is most illogical
35 36

6
Completeness In Summary
• An inference algorithm is complete if it can • Soundness: i is sound if whenever KB |- i α,
derive any sentence that is entailed it is also true that KB |= α
• For some KBs, the number of sentences can • Completeness: i is complete if whenever KB
be infinite |= α, it is also true that KB |-i α
• Can’t exhaustively check all of them, need
to rely on proving completeness

37 38

Syntax: Backus-Naur Form grammar


of sentences in propositional logic
Sentence → AtomicSentence | ComplexSentence
AtomicSentence → True | False | Symbol
Symbol → P | Q | R | …
Propositional Logic: Syntax and ComplexSentence → ¬ Sentence
Semantics | ( Sentence  Sentence )
| ( Sentence  Sentence )
| ( Sentence  Sentence )
| ( Sentence  Sentence )

39 40

Atomic Sentences Complex Sentences


• The indivisible syntactic elements • Made up of sentences (either complex or atomic)
• Consist of a single propositional symbol • 5 common logical connectives:
– ¬ (not): negates a literal
e.g. P, Q, R that stands for a proposition
–  (and): conjunction e.g. P  Q where P and Q are
that can be true or false e.g. P=true, Q=false called the conjuncts
• We also call an atomic sentence a literal –  (or): disjunction e.g. P  Q where P and Q are called
the disjuncts
• 2 special propositional symbols:
–  (implies): e.g. P  Q where P is the
– True (the always true proposition) premise/antecedent and Q is the conclusion/consequent
– False (the always false proposition) –  (if and only if): e.g. P  Q is a biconditional

41 42

7
Precedence of Connectives Semantics (Are sentences true?)
• In order of precedence, from highest to • Defines the rules for determining if a sentence is
lowest: ¬, , , ,  true with respect to a particular model
• E.g. ¬P  Q  R  S is equivalent to • For example, suppose we have the following
((¬P)  (Q  R))  S model: P=true, Q=false, R=true
• You can rely on the precedence of the • Is (P  Q  R) true?
connectives or use parentheses to make the I want the
order explicit truth!
• Parentheses are necessary if the meaning is
ambiguous
43 44

Semantics Note on implication


For atomic sentences: • P  Q seems weird…doesn’t fit intuitive
• True is true, False is false understanding of “if P then Q”
• A symbol has its value specified in the model • Propositional logic does not require causation or
relevance between P and Q
For complex sentences (for any sentence S and model m): • Implication is true whenever the antecedent is
• S is true in m iff S is false in m false (remember P  Q can be translated as  P 
• S1  S2 is true in m iff S1 is true in m and S2 is true in m Q)
• S1  S2 is true in m iff S1 is true in m or S2 is true in m – Implication says “if P is true, then I am claiming that Q
• S1  S2 is true in m iff S1 is false in m or S2 is true in m is true. Otherwise I am making no claim”
i.e., can translate it as S1  S2 – The only way for this to be false is if P is true but Q is
• S1  S2 is true iff S1S2 is true in m and S2S1 is true in m false

45 46

The Wumpus World KB (only


Truth Tables for the Connectives
dealing with knowledge about pits)
P Q P Q P Q P Q P Q
For each i, j:
P P false false false false true true Let Pi,j be true if there is a pit in [i, j]
false true false true false true true false Let Bi,j be true if there is a breeze in [i, j]
true false true false false true false false
true true true true true true The KB contains the following sentences:
1. There is no pit in [1,1]:
R1: P1,1
With the truth tables, we can compute the truth value of any 2. A square is breezy iff there is a pit in a neighboring
sentence with a recursive evaluation e.g. square: (not all sentences are shown)
R2: B1,1  P1,2  P2,1
Suppose the model is P=false, Q=false, R=true
R3: B2,1  (P1,1  P2,2  P3,1)
P  (Q  R) = true  (false  true) = true  true = true :

47 48

8
The Wumpus World KB Inference
• How do we decide if KB |= ?
3. We add the percepts for the first two • Enumerate the models, check that  is true in every model
in which KB is true
squares ([1,1] and [2,1]) visited in the
Wumpus World example: B1,1 B2,1 P1,1 P1,2 P2,1 P2,2 P3,1 R1 R2 R3 R4 R5 KB
false false false false false false false true true true true false false
R4: B1,1 false false false false false false true true true false true false false
R5: B2,1 : : : : : : : : : : : : :
false true false false false false false true true false true true false
false true false false false false true true true true true true true
The KB is now a conjunction of sentences R1 false true false false false true false true true true true true true
 R2  R3  R4  R5 because all of these false true false false false true true true true true true true true
sentences are asserted to be true. false true false false true false false true false false true true false
: : : : : : : : : : : : :
true true true true true true true false true true false true false
49

Inference Things you should know


• Suppose we want to know if KB |= P1,2?
• Properties of a knowledge-based agent
• In the 3 models in which KB is true, P1,2 is also true
B1,1 B2,1 P1,1 P1,2 P2,1 P2,2 P3,1 R1 R2 R3 R4 R5 KB
• What a knowledge-base is
false false false false false false false true true true true false false • What entailment and inference mean
false false false false false false true true true false true false false
: : : : : : : : : : : : : • Desirable properties of inference algorithms
false true false false false false false true true false true true false such as soundness and completeness
false true false false false false true true true true true true true
false true false false false true false true true true true true true
false true false false false true true true true true true true true
false true false false true false false true false false true true false
: : : : : : : : : : : : :
true true true true true true true false true true false true false
51 52

You might also like