0% found this document useful (0 votes)
27 views71 pages

Unit 3

The document discusses knowledge-based agents and their components including a knowledge base and inference mechanism. It also describes the Wumpus World environment as an example domain for a knowledge-based agent, including the agent's sensors, actuators, and performance measures.

Uploaded by

Prateek Mehta
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)
27 views71 pages

Unit 3

The document discusses knowledge-based agents and their components including a knowledge base and inference mechanism. It also describes the Wumpus World environment as an example domain for a knowledge-based agent, including the agent's sensors, actuators, and performance measures.

Uploaded by

Prateek Mehta
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/ 71

Unit-3

Knowledge-Base agent
•A knowledge-based agent can combine general knowledge
with current percepts to infer hidden aspects of the current
state prior to selecting actions.
•The central component of a knowledge-based agent is its
knowledge base, or KB. Informally, a knowledge base is a set
of sentences.
•Each sentence is expressed in a language called a knowledge
representation language and some assertion about the
world.
A knowledge-based agent is composed of:

1. Knowledge base: domain-specific content.

2. Inference mechanism: domain-independent


algorithms.
Knowledge based agent
The agent must be able to:
• Represent states, actions, etc.
• Incorporate new percepts
• Update internal representations of the world
• Deduce hidden properties of the world
• Deduce appropriate actions

Declarative approach to building an agent:


• Add new sentences: Tell it what it needs to know
• Query what is known: Ask itself what to do – answers should follow
from the KB
THE WUMPUS WORLD
• The wumpus world is a cave consisting of rooms connected by
passageways.
• Lurking somewhere in the cave is the wumpus, a beast that eats
anyone who enters its room.
• The wumpus can be shot by an agent, but the agent has only one
arrow
• Some rooms contain bottomless pits that will trap anyone who
wanders into these rooms (except for the wumpus, which is too big
to fall in).
THE WUMPUS WORLD

• 4 X 4 grid of rooms
• Squares adjacent to Wumpus are smelly
• Squares adjacent to pit are breezy
• Glitter iff gold is in the same square
• Shooting kills Wumpus if you are facing it
• Wumpus emits a horrible scream when it is killed
that can be heard anywhere
• Shooting uses up the only arrow
• Grabbing picks up gold if in same square
• Releasing drops the gold in same square
THE WUMPUS WORLD PEAS
Performance measure:
gold +1000, death (eaten or falling in a pit) -1000,
-1 per action taken, -10 for using the arrow.
The games ends either when the agent dies or
comes out of the cave.
Environment:
• 4 X 4 grid of rooms
• Agent starts in square [1,1] facing to the right
• Locations of the gold, and Wumpus are chosen
randomly with a uniform distribution from all
squares except [1,1]
• Each square other than the start can be a pit
with probability of 0.2
THE WUMPUS WORLD PEAS

Actuators:
Left turn, Right turn, Forward, Grab, Release,
Shoot
Sensors:
Stench, Breeze, Glitter, Bump, Scream
Represented as a 5-element list
Example: [Stench, Breeze, None, None, None]
Wumpus World Characterization
Observable? No—only local perception

Deterministic? Yes—outcomes exactly specified

Episodic? No—sequential at the level of actions

Static? Yes—Wumpus and Pits do not move

Discrete? Yes

Single-agent? Yes—Wumpus is essentially a natural feature


Exploring Wumpus world
Exploring Wumpus world
Logic
• When most people say ‘logic’, they mean either propositional
logic or first-order predicate logic
Any ‘formal system’ can be considered a logic if it has:
– a well-defined syntax;
– a well-defined semantics; and
– a well-defined proof-theory.

• The syntax of a logic defines the syntactically acceptable objects


of the language, which are properly called well-formed formulae
(wff).
• The semantics of a logic associate each formula with a meaning.
• Inference procedures (or a proof theory) define a means of
deriving formulas from other formulas.
th
Propositional Logic (0 Order logic)
Definition: A proposition is a statement that can be either true or
false; it must be one or the other, and it cannot be both.
Definition: A proposition is a declarative sentence that is either true
(denoted either T or 1) or false (denoted either F or 0)
EXAMPLES. The following are propositions:
– the reactor is on;
– the wing-flaps are up;
– John Major is prime minister.
whereas the following are not:
– are you going out somewhere?
– Did John go to the store?
– x is greater than 2
– Look out!
th
Propositional Logic (0 Order logic)
•Variables are used to represent propositions. The most
common variables used are p, q, and r.
Logical Operators:
•Unary Operator negation: “not p”, ¬p.
•Binary Operators:
(a) conjunction: “p and q”, p ∧ q.
(b) disjunction: “p or q”, p ∨ q.
(c) exclusive or: “exactly one of p or q”, “p xor q”, p ⊕ q.
(d) implication: “if p then q”, p → q.
(e) biconditional: “p if and only if q”, p iff q, p ↔ q.
Negation Operator, “not”, has symbol ¬
• The negation operator is a unary operator which, when applied to a
proposition p, changes the truth value of p.
• if p is true, its negation is false
Example:
p: This book is interesting.
¬p can be read as:
This book is not interesting.
This book is uninteresting.
It is not the case that this book is interesting.
• Another notation commonly used for the negation of p is ∼ p.
Conjunction Operator, “and”, has symbol ∧.
The conjunction operator is the binary operator which, when
applied to two propositions p and q, yields the proposition “p and
q”, denoted p∧ q. The conjunction p∧ q of p and q is the
proposition that is true when both p and q are true and false
otherwise.
Disjunction Operator: “or”, has symbol ∨
• The disjunction operator is the binary operator which, when applied to
two propositions p and q, yields the proposition “p or q”, denoted p ∨ q.
The disjunction p ∨ q of p and q is the proposition that is true when
either p is true, q is true, or both are true, and is false otherwise.
Exclusive Or. Exclusive Or Operator, “xor”, has symbol ⊕
• The exclusive or is the binary operator which, when applied to two
propositions p and q yields the proposition “p xor q”, denoted p ⊕ q,
which is true if exactly one of p or q is true, but not both. It is false if both
are true or if both are false.
.

Implication Operator, “if...then...”, has symbol →


We will write p q for the conditional “if p then q”
In this conditional, the thing before the (p in the example) is called the antecedent, premise,
or hypothesis. The thing after the (q in the example) is called the conclusion or consequence .
“If p then q” is false precisely when p is true but q is false.

Equivalent Forms of “If p then q”:


• p implies q
• If p, q
• p only if q
• p is a sufficient condition for q
• q if p
• q whenever p
• q is a necessary condition for p
.

Implication Operator, “if...then...”, has symbol →


For the compound statement p → q :
• p is called the premise, hypothesis, or the antecedent.
• q is called the conclusion or consequent.
• q → p is the converse of p → q.
• ¬p → ¬q is the inverse of p → q.
• ¬q → ¬p is the contrapositive of p → q.
Biconditional Operator, ”if and only if”, has symbol ↔
• The biconditional statement is equivalent to (p → q) ∧ (q → p). In
other words, for p ↔ q to be true we must have both p and q true or
both false.
NAND and NOR Operators
• NAND (that is, not and), is a binary connective, written symbolically as p I q

• The NOR Operator (not or), which has symbol ↓ , written symbolically p ↓ q
Tautology and Contradiction
Definitions:
A compound proposition that is always true for all possible truth values of
the propositions is called a tautology.
A compound proposition that is always false is called a contradiction.
A proposition that is neither a tautology nor contradiction is called a
contingency.
Example: p ∨ ¬p is a tautology.
Tautology and Contradiction
Definitions:
A compound proposition that is always true for all possible truth values of
the propositions is called a tautology.
A compound proposition that is always false is called a contradiction.
A proposition that is neither a tautology nor contradiction is called a
contingency.
Example: p ∧ ¬p is a contradiction.
Logical equivalence
DeMorgan's Laws:
1) ¬( p ∨ q ) <=> ¬p ∧ ¬q
2) ¬( p ∧ q ) <=> ¬p ∨ ¬q
Equivalence
Equivalent statements are important for logical reasoning since they can be
substituted and can help us to:
(1) make a logical argument, and (2) infer new propositions
Example: p q is equivalent to ¬q ¬p (contrapositive)
Important logical equivalences
• Identity • Double negation • Distributive
p ∧ T <=> p ¬(¬p) <=> p P ∨ (q ∧ r) <=> (p ∨ q) ∧ (p
p ∨ F <=> p • Commutative ∨ r)
• Domination p ∨ q <=> q ∨ p p ∧ (q ∨ r) <=> (p ∧ q) ∨ (p
p ∨ T <=> T ∧ r)
p ∧ q <=> q p
p ∧ F <=> F • Other useful equivalences
• Associative
• Idempotent p ∨ ¬p <=> T
(p ∨ q) ∨ r <=> p ∨ (q ∨
p ∨ p <=> p p ∧ ¬p <=> F
r)
p ∧ p <=> p
(p ∧ q) ∧ r <=> p ∧ (q ∧p q <=> (¬p ∨ q)
r)
Show that ¬[p ∨ ¬(¬q ∨ ¬r)] is logically equivalent to (p ∨ q) → ¬(p ∨
r)
Entailment (|=)
• Entailment means that one thing follows from another:
• Knowledge base KB entails sentence α if and only if:
❖ α is true in all interpretations/worlds in which KB is true
❖ if KB is true then α must be true
Write KB |= α for KB entails α, So:
KB |= α iff for every interpretation I, if I |= KB then I |= α.
Or
If M(α) is the set of all models of α, then KB |= α iff M(KB) ⊆ M(α)
Entailment (|=)
Entailment means that one thing follows from another:
Consider:
If it rains John takes an umbrella
If John takes an umbrella he doesn’t get wet
If it doesn’t rain then John doesn’t get wet.

Show:
John doesn’t get wet.

Propositions :
r: It rains
u: John takes an umbrella
w: John gets wet.

Query {r u, u ¬w, ¬r ¬w} |= ¬w


Now Prove that {r u, u ¬w, ¬r ¬w} |= ¬w
Solving logical inference problem
How to design the procedure that answers:
Three approaches:
1) Truth-table approach
2) Inference rules
3) Conversion to the inverse SAT problem
– Resolution-refutation
Properties of inference solutions
1) Truth-table approach:
– Blind
– Exponential in the number of variables
2) Inference rules:
– More efficient
– Many inference rules to cover logic
3) Conversion to SAT - Resolution refutation:
– More efficient
– Sentences must be converted into CNF
– One rule – the resolution rule - is sufficient to perform
all inferences
Truth table approach:
A two steps procedure:
1. Generate table for all possible interpretations
2. Check whether the sentence α evaluates to true whenever KB evaluates to true
Example: KB= (A ∨ C) ∧ (B ∨ ~C) α=(A ∨ B)
Problem with the truth table approach:
The truth table is exponential in the number of propositional
symbols (we checked all assignments)
Observation: KB is true only on a small subset interpretations

Solution:
Inference rules approach
-Start from entries for which KB is True.
-Generate new sentences from the existing ones
Inference rules approach:
Approach:
• Start from KB
• Infer new sentences that are true from existing KB sentences
• Repeat till α is proved (inferred true) or no more sentences can be proved

Rules:
(i) Equivalence rules: Logical equivalence rules
(ii) Inference rules:

Logical equivalences are discussed in the previous slides


Inference Rules
Inference Rules
Inference Rules
• Logical inference creates new sentences that logically follow
from a set of sentences (KB)
• An inference rule is sound if every sentence X it produces from
a KB logically follows from the KB
–i.e., inference rule creates no contradictions
• An inference rule is complete if it can produce every expression
that logically follows from (is entailed by) the KB
–Note analogy to complete search algorithms
Inference rules approach.
Inference rules approach.
Inference rule approach and Normal forms
Problems with inference rule approach:
-Too many different rules one can apply
-Many new sentence are just equivalent sentences
Question:
-Can we simplify inferences using one of the normal forms?

Normal forms:
1) Conjunctive normal form (CNF)
Conjunction of clauses (clauses include disjunctions of literals)
2) Disjunctive normal form (DNF)
Disjunction of terms (terms include conjunction of literals)
Normal forms
• A formula is in conjunctive normal form (CNF, clause normal form), if it is a conjunction of
disjunctions of literals (or in other words, a conjunction of clauses).

• A formula is in disjunctive normal form (DNF), if it is a disjunction of conjunctions of literals.


• Checking the validity of CNF formulas or the unsatisfiability of DNF formulas is easy:
• A formula in CNF is valid, if and only if each of its disjunctions contains a pair of complementary
literals P and ¬P .
• Conversely, a formula in DNF is unsatisfiable, if and only if each of its conjunctions contains a pair
of complementary literals P and ¬P .
Conversion to a CNF
Resolution algorithm
• Convert KB to the CNF form
• Now KB is in CNF
– KB = AND of all the sentences in KB
– KB sentence = clause = OR of literals
– Literal = propositional symbol or its negation
• Find two clauses in KB, one of which contains a literal and the other
its negation
• Cancel the literal and its negation
• Bundle everything else into a new clause
• Add the new clause to KB
Inference problem and satisfiability
Inference problem and satisfiability
Resolution Rule
Resolution Rule
A KB is a set of sentences all of which are true, i.e., a conjunction
of sentences
• To use resolution, put KB into conjunctive normal form (CNF)
– Each sentence is a disjunction of one or more literals
(positive or negative atoms)
• Every KB can be put into CNF, it's just a matter of rewriting its
sentences using standard tautologies, e.g.:
P Q ≡ ~P ∨ Q
Resolution refutation
1. Add negation of goal to the KB
2. Convert all sentences in KB to CNF
3. Find all pairs of sentences in KB with complementary literals that
have not yet been resolved
4. If there are no pairs stop else resolve each pair, by adding the result
to the KB and go to 2
5. If we derived an empty clause (i.e., a contradiction) then the
conclusion follows from the KB
6. If we did not, the conclusion cannot be proved from the KB
Example: Resolution
α=
Summary
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
Propositional logic limitations

(1) Statements that hold for many objects must be enumerated


Solution: make statements with variables
(2) Statements that define the property of the group of objects
Solution: make statements with quantifiers
(i) Universal quantifier –the property is satisfied by all members of the group
(ii) Existential quantifier – at least one member of the group satisfy the property

(3) Not expressive enough for most problems


First Order Logic (FOL)
• FOPL is also called predicate calculus , or Predicate logic
• Predicates are used to describe certain properties or
relationships between individuals or objects.
• Quantifiers indicate how frequently a certain statement is true.
Specifically, the universal quantifier is used to indicate that a
statement is always true, whereas the existential quantifier
indicates that a statement is sometimes true.
• Predicate Logic represented using constants, variables and
predicates
First Order Logic (FOL)
• Constant –models a specific object
Examples: “John”, “France”, “7”
• Variable – represents object of specific type (defined by the
universe of discourse)
Examples: x, y (universe of discourse can be people, students, numbers)

• Predicate - over one, two or many variables or constants.


– Represents properties or relations among objects
Examples: Red(car23), student(x), married(John, Ann)
Predicate Calculus: Syntax
The Domain (universe of discourse): The universe of discourse or
domain is the collection of all persons, ideas, symbols, data structures,
and so on, that affect the logical argument under consideration. The
elements of the domain are called individuals or objects.
Predicates: Properties or relations among individuals or objects
referred as predicates.
Variables: are frequently chosen from the end of the alphabet;
that is x, y and z
First Order Logic (FOL):Quantifiers
First Order Logic (FOL):Quantifiers
Universal quantifier: The universal quantifier allows us to build formulae
that are true for all objects.
Existential quantifier: The existential quantifier allows us to build
formulae that are true for at least one object.

When ∀x P(x) and ∃x P(x) are true and false?


Translation with quantifiers

Sentence: All KIIT students are smart.


Assume: the domain of discourse of x are KIIT students
Translation: ∀x Smart(x)
Assume: the universe of discourse are students (all students):
∀x at(x,KIIT) Smart(x)
Assume: the universe of discourse are people:
∀x student(x) ∧ at(x, KIIT) Smart(x)
Translation with quantifiers

Sentence: Someone at KIIT is smart.


Assume: the domain of discourse are all KIIT affiliates
Translation: ∃x Smart(x)
Assume: the universe of discourse are people:
∃x at(x , KIIT) ∧ Smart(x)
Translation with quantifiers
Assume two predicates S(x) and P(x)
Universal statements typically tie with implications
• All S(x) is P(x)
∀x ( S(x) P(x) )
• No S(x) is P(x)
∀x( S(x) ¬P(x) )
Existential statements typically tie with conjunctions
• Some S(x) is P(x)
∃x (S(x) ∧ P(x) )
• Some S(x) is not P(x)
∃x (S(x) ∧ ¬P(x) )
Free variable and bound variable
A variable is bound if it is under a quantifier with the same name (the
occurrence of the variable close to the quantifier is called binding variable).
If this is not the case, the variable is free.
Example, in the expression ∀x(P (x) → Q(x)), the variable x appears three times and
each time x is a bound variable.

Example, ∀z(P (z) ∧ Q(x)) ∨ ∃yQ(y). Here all occurrences of z and y are bound,
Only one variable x is free.
Order of quantifiers
The order of nested quantifiers matters if quantifiers are of
different type
• ∃x∀x P(x,y) is not the same as ∀x ∃x P(x,y).

Example:
• Assume P(x,y) denotes “x loves y”
• Then: ∀x ∃x L(x,y)
• Translates to: Everybody loves somebody.
• And: ∃x∀x L(x,y)
• Translates to: There is someone who is loved by everyone.

***The meaning of the two is different.


* *The order of nested quantifiers does NOT MATTER if quantifiers are of the SAME type
**The order of nested quantifiers MATTER if quantifiers are of the NOT same type
Inference in FOL : Example
Inference in FOL:Example
Inference in FOL: Example
Inference in FOL: Example
First order Predicate Logic
• Mary loves everyone. ∀x love (Mary, x), ∀x (love (Mary, x)), (∀x love
(Mary, x)), (∀x (love (Mary, x))) (All are correct)
• Mary loves everyone: ∀x (person(x) → love (Mary, x))
• Everyone loves himself. ∀x love (x, x)
• Everyone loves everyone. ∀x∀y love (x, y)
• Everyone loves Mary. ∀x love (x, Mary)
• Every student smiles. ∀x (student(x) → smile( x))
• Every student except George smiles. ∀x ((student(x) & x ≠ George) →
smile( x))
• Everyone walks or talks.∀x (walk (x) ∨ talk (x))
• Every student who walks talks. ∀x (student(x) → (walk (x) ∨ talk (x)))
• Everyone loves someone. ∀x∃y love (x, y) (or) ∃y∀x love (x, y)
• Someone loves everyone.∃x∀y love (x, y) (or) ∀y∃x love (x, y)
• Someone walks and talks. ∃x(walk (x) ∧ talk (x))
First order Predicate Logic
• Every person plays some game. .∀x ∃y Person(x) ⇒ ( Game(y) ∧ Plays(x, y) )
• All games are fun. ∀x Game(x) ⇒ Fun(x)
• For every game, there is a person that plays that game. ∀x ∃y [ Game(x) ∧
Person(y) ] ⇒ Plays(y, x)
• Every person plays every game. ∀x ∃y Game(x) ⇒ [ Person(y) ∧ Plays(y, x) ]
• Some person plays every game. ∃x ∀y Person(x) ∧ [ Game(y) ⇒ Plays(x, y) ]
• Some person plays some game. ∃x ∃y Person(x) ∧ Game(y) ∧ Plays(x, y)
• There is some person in Delhi who is smart. ∃x Person(x) ∧ In(x, Irvine) ∧
Smart(x)
• Every person in Delhi is smart. ∀x [ Person(x) ∧ In(x, Irvine) ] ⇒ Smart(x)
First order logic
First order logic
1) All apples are red 6) Every DOG is a animal
∀x (Apple(x) ⇒Red(x)) ∀x Dog(x) animal(x)
2) Every person has some person he loves 7) Some dog is pet
∀x ∃y Loves(x, y) ∃x Dog(x) pet(x)
3) There is a single person whom everybody loves. 8) Everyone loves somebody
∃y ∀x Loves(x, y) ∀x. ∃y. Loves(x,y)
4) Every dog is owned by someone. ∃y. ∀x. Loves(x,y)
∀ x(Dog(x)) ⇒ ∃ y[Person(y) ∧ Owns(y,x)] 9) Brothers are siblings
5) John has a dog ∀x,y Brother(x,y) sibling(x,y)
∃x. Dog(x) ∧ Owns (John, x) ∀x,y Brother(x,y) <--> sibling(y,x)

19) Ones mother is ones female parent


∀x,y Mother(x,y) (female(x) ∧ parent(x,y))
∀x,y Mother(x,y) <--> (female(x) ∧ parent(x,y))
Types of Mathematical Logic
1) Propositional logic
Propositions are interpreted as true or false
Infer truth of new propositions
2) First order logic
Contains predicates, quantifiers and variables
• E.g. Philosopher(a) Scholar(a)
• ∀x, King(x) ∧ Greedy (x) Evil (x)
Variables range over individuals (domain of discourse)
3) Second order logic
Quantify over predicates and over sets of variables
4) Temporal logic
Truths and relationships change and depend on time
5) Fuzzy logic
Uncertainty, contradictions

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy