AI CH 4
AI CH 4
AI CH 4
Figure 4.1
Both operations may involve inference—that is, deriving new sentences from old. Inference must obey the requirement
that when one ASKs a question of the knowledge base, the answer should follow from what has been told (or TELLed)
to the knowledge base previously.
Figure 4.2 A generic knowledge-based agent. Given a percept, the agent adds the percept to its knowledge base, asks
the knowledge base for the best action, and tells the knowledge base that it has in fact taken that action.
Like all our agents, it takes a percept as input and returns an action. The agent maintains a knowledge
base, KB, which may initially contain some background knowledge. Each time the agent program is called, it does
three things.
Second, it ASKs the knowledge base what action it should perform. In the process of answering this query, extensive
reasoning may be done about the current state of the world, about the outcomes of possible action sequences, and so
on.
Third, the agent program TELLs the knowledge base which action was chosen, and the agent executes the action.
MAKE-PERCEPT-SENTENCE:
It constructs a sentence asserting that the agent perceived the given percept at the given time.
MAKE-ACTION-QUERY:
It constructs a sentence that asks what action should be done at the current time.
MAKE-ACTION-SENTENCE:
It constructs a sentence asserting that the chosen action was executed.
28
We can also provide a knowledge-based agent with mechanisms that allow it to learn for itself. These mechanisms
create general knowledge about the environment from a series of percepts. A learning agent can be fully autonomous.
• Environment:
A 4×4 grid of square rooms
The agent always starts in the square labeled [1,1], facing to the right.
Squares adjacent to wumpus are smelly (stench)
Squares adjacent to pit are breezy
Glitter iff gold is in the same square
Shooting kills wumpus if agent is facing it
29
Shooting uses up the only one arrow
Grabbing picks up gold if in same square
Releasing drops the gold in same square
• Actuators:
The agent can move Forward, TurnLeft by 90◦, or TurnRight by 90◦.
The action Grab can be used to pick up the gold if it is in the same square as the agent.
The action Shoot can be used to fire an arrow in a straight line in the direction the agent is facing. The arrow continues
until it either hits (and hence kills) the wumpus or hits a wall. The agent has only one arrow, so only the
first
Shoot action has any effect.
Finally, the action Climb can be used to climb out of the cave, but only from square [1,1].
• Sensors:
The agent has five sensors, each of which gives a single bit of information:
1. In the square containing the wumpus and in the directly (not diagonally) adjacent squares,
the agent will perceive a Stench.
2. In the squares directly adjacent to a pit, the agent will perceive a Breeze.
3. In the square where the gold is, the agent will perceive a Glitter.
4. When an agent walks into a wall, it will perceive a Bump.
5. When the wumpus is killed, it emits a woeful Scream that can be perceived anywhere in the cave.
The percepts will be given to the agent program in the form of a list of five symbols;
For example, if there is a stench and a breeze, but no glitter, bump, or scream, the agent program will get the percepts
[Stench, Breeze, None, None, None].
Let us watch a knowledge-based wumpus agent exploring the environment shown in Figure 4.3(a,b,c,d,e).
[2,1] Breeze which indicates that there is a pit in [2,2] or [3,1], return to [1,1] to try next safe cell
30
(c)
[1,2] Stench in cell which means that wumpus is in [1,3] or [2,2] but not in [1,1]
YET … not in [2,2] or stench would have been detected in [2,1]
THUS … wumpus is in [1,3]
THUS [2,2] is safe because of lack of breeze in [1,2]
THUS pit in [3,1]
move to next safe cell [2,2]
(d) (e)
[2,2] Move to [2,3]
[2,3] Detect glitter, smell, breeze
Pick up gold
THUS pit in [3,3] or [2,4]
31
Symbols in propositional logic are the logical constants True and False. Sentences considered in propositional logic are
not arbitrary sentences but are the ones that are either true or false, but not both. This kind of sentences is called
propositions.
Syntax
The syntax of propositional logic defines the allowable sentences.
The atomic sentences consist of a single proposition symbol.
Each such symbol stands for a proposition that can be true or false.
We use symbols that start with an uppercase letter and may contain other letters or subscripts, for example:
P, Q, R, W1,3 and North.
The names are arbitrary but are often chosen to have some mnemonic value—we use W1,3 to stand for the
proposition that the wumpus is in [1,3]. There are two proposition symbols with fixed meanings: True is the
always-true proposition and False is the always-false proposition.
Example
Some facts in propositional logic:
It is raining. - RAINING
It is sunny - SUNNY
It is windy - WINDY
Complex sentences are constructed from simpler sentences, using parentheses and logical connectives.
Example
If it is raining, then it is not sunny - RAINING -> SUNNY
All sentences are made by putting these symbols together using the following rules:
i. The logical constants True and False are sentences themselves.
ii. A propositional symbol such as P or Q is a sentence itself.
iii. Wrapping parentheses around a sentence yields a sentence by itself, eg. (P Q)
iv. A sentence can be formed by combining simpler sentences with one of the 5 logical connectives.
The 5 logical connectives according to their hierarchy are:
NOT ; only connective that operates on a single sentence
; a sentence such as P is called as negation of P
// the following connectives combine two sentences into one sentence.
AND ; conjunction
; a sentence whose main connective is , such as P (Q R)
;its parts are called conjuncts P and Q R
OR ; disjunction
; a sentence using , such as P (Q R)
;its parts are called disjuncts P and Q R
; P ∨ Q is true iff either P or Q is true
32
IMPLIES ; conditional
; a sentence using , such a s (P Q) R is called an implication
; its premise or antecedent is (P Q), and its conclusion or consequent is R
; Implications are also known as rules or if-then- statements
; P ⇒ Q is true unless P is true and Q is false
EQUIVALENT ; biconditional
; the sentence (P Q) (Q P) is an equivalence
;IF_AND_ONLY_IF
; P ⇔ Q is true iff P and Q are both true and both false
Semantics of propositional logic is the interpretation of proposition symbols and constants, and specifying the meaning
of logical connectives.
For complex sentences, we have five rules, which hold for any sub sentences P and Q in any model m
(here “iff” means “if and only if”):
• ¬P is true iff P is false in m.
• P ∧ Q is true iff both P and Q are true in m.
• P ∨ Q is true iff either P or Q is true in m.
• P ⇒ Q is true unless P is true and Q is false in m.
• P ⇔ Q is true iff P and Q are both true and both false in m.
P Q P PQ‘If P then PQ‘IF_AND_ONLY_IF’
Q’
False False True False False True True
False True True False True True False
True False False False True False False
True True False True True True True
Truth table for the 5 logical connectives
What is inference?
33
Inference is the process deriving new sentences from old ones.
If there are several sentences in either the premise or in the conclusion, they are separated by commas.
A list of 7 commonly used inference rules for propositional logic are given below.
34
iv) Or-Introduction: From a sentence, we can infer disjunction with anything else at all.
ai
a 1 Ú a 2 Ú a 3 Ú . . .Ú a n
v) Double Negation Elimination: From a doubly negated sentence, we can infer a positive sentence.
Ø Øa
a
vi) Unit Resolution: From a disjunction, if one of the disjuncts is FALSE then we can infer the other one is TRUE.
a Ú b ,Øb
a
vii) Resolution: This is the most difficult one. Because ɣ cannot be both TRUE and FALSE, one of the other disjuncts
must be TRUE in one of the premises. Or equivalently, implication is transitive.
a Ú b,Ø bÚ ɣ Ø a Þ b , bÞ ɣ
aÚɣ or ØaÞ ɣ
Examples:
i) “one plus two equals three”
Objects: one, two, three, one plus two,
Property: --------
Relation: equals
Function: plus
ii) “Squares neighboring the wumpus are smelly”
Objects: Squares, wumpus
Property: smelly
Relation: neighboring
Function: --------
iii) “Evil king John ruled England in 1200”
Objects: John, England, 1200
Properties: Evil, king
Relation: ruled
Function: ______
The basic syntactic elements of first-order logic are the symbols that stand for objects, relations, and functions.
35
The symbols come in three kinds:
a) Constant symbols, which stand for objects;
b) Predicate symbols, which stand for relations; and
c) Function symbols, which stand for functions.
We adopt the convention that these symbols will begin with uppercase letters.
Example:
Constant symbols: A, B, Richard, and John;
Predicate symbols: Brother, OnHead, Person, King, and Crown;
Function symbols: FatherOf, LeftLegOf
Terms: Term is a logical expression that refers to an object. Constant symbols are therefore terms.
A term with no variables is called a ground term.
Quantifiers
Quantifiers are needed to express properties of entire collections of objects, instead of enumerating the objects by
name.
a) Universal quantification
“Spot is a cat” is represented by Cat (Spot) and
“Spot is a mammal” is represented by Mammal (Spot).
In English, what we want to say is that for any object x, if x is a cat then x is a mammal.
First –Order Logic let us do this as follows:
"x Cat(x) Mammal(x)
E.g.1
Rules such as "All kings are persons,'' is written in first-order logic as
"x King(x) => Person(x)
Thus, the sentence says, "For all x, if x is a king, then x is a person."
E.g.2
("x) dolphin(x) => mammal(x)
b) Existential quantification
($ x)P(x) means that P holds for some value of x in the domain associated with that variable.
E.g., ($ x) mammal(x) lays-eggs(x)
Universal quantification makes statements about every object. Similarly, we can make a statement about some object
in the Universe without naming it, by using an Existential quantifier.
For example,
”Spot has a sister who is a cat” can be written as
($ x) Sister(x, Spot) Cat(x)
36
Thus in general a sentence is represented as
($x) P(x)
where
$x is pronounced “There exists an x such that ..” or “ For some x ..”,
the symbol x is called a variable (lower case letters) and all predicate, constant & function
symbols are capitalized.
P is logical expression says that ($x) P is true if P is true for some object x in the Universe.
Hence the symbol $ is called Existential quantifier.
c) Nested quantifiers
More complex sentences can be expressed using multiple quantifiers.
The simplest case is where the quantifiers are of the same type.
For example, “For all x and y if x is the parent of y then y is the child of x”
"x"y Parent(x, y)Child(y, x)
"x"y is equivalent to "x, y.
Similarly, “Brothers are siblings” can be written as
"x, y Brother(x, y)Sibling(y, x)
The other cases are where the quantifiers are of the mixture type " and $
“Everybody loves somebody” means that for every person, there is someone that person loves:
"x $ y Loves(x, y)
On the other hand, to say “There is someone who is loved by everyone” we write
$ y "x Loves(x, y)
The order of quantification is therefore very important. It becomes clearer if we put in parenthesis.
d)Equality
FOL includes Equality symbol (¿) to represent atomic sentences, other than using a predicate and terms.
The Equality symbol (¿) can be used to represent two terms to refer to the same object. For example,
Father(John)= Henry
says that the object referred to by Father(John) and the object referred to by Henry are the same.
37
Quantifier → ∀| ∃
Constant → A | X1 | John | ・ ・ ・
Variable → a | x | s | ・・・
Predicate → True | False | After | Loves | Raining | ・・・
Function → Mother | LeftLeg | ・ ・ ・
Figure 8.3 The syntax of first-order logic with equality, specified in Backus–Naur Form
(1) Universal instantiation (UI): This rule says that we can infer any sentence obtained by substituting a ground
term (a term without variables) for the variable. Let SUBST(, θ) denotes the result of applying the substitution θ
to the sentence . Then every instantiation of a universally quantified sentence is entailed as:
38
when substituting x= Father(John)
King(Father(John)) Ù Greedy(Father(John)) Þ Evil(Father(John)).
UI can be applied several times to add new sentences; the new KB is logically equivalent to the old.
39
(1)Logical schemes: Logical schemes represent knowledge, using mathematical or orthographic symbols, inference
rules and are based on precisely defined syntax and semantics.
i. Propositional calculus
ii. Predicate(FOL) calculus
(2)Procedural schemes: In procedural schemes knowledge is represented as a set of instructions for problem-solving.
That allows to modify a knowledge base easily and to separate a knowledgebase from an inference mechanism.
IF..THEN..rules
(3)Structured schemes: Structured schemes extend networked representation by displaying each node in a graph as a
complex data structure.
i. Frames
ii. Scripts
(4)Networked schemes: Networked schemes use a graph to represent knowledge. Nodes of a graph display objects or
concepts in a domain, but arcs define relationships between objects, their attributes, and values of attributes.
i. Semantic nets
ii. Conceptual graphs
Networked schemes
(i) Semantic nets
Semantic network is a knowledge representation schema that captures knowledge as a graph. The nodes
denote objects or concepts, their properties and corresponding values. The arcs denote relationships between the
nodes. Both nodes and arcs are generally labeled (arcs have weights).
Nodes of semantic nets can represent: Concepts, Objects, Events, Features, Time etc.
Several kinds of relationships are used in semantic nets:
1.“Class -Superclass” or “Is-a” relationship
5.“Attribute-Value”or“Value” relationship
40
Inheritance is possible in semantic nets. Inheritance is a process by which the local information of a superclass node is
assumed by a class node, a subclass node, and an instance node.
Example:
All vehicles have a brand name and a model. A car is a class of a superclass Vehicle. So Car inherits all features of
Vehicle that is, Brand Name and Model.
Every conceptual relation r has a relation type t and a nonnegative integer n called its valence.
•The number of arcs that belong to r is equal to its valence n. A conceptual relation of valence n is said to be n-adic,
and its arcs are numbered from 1 to n.
•For every n-adic conceptual relation r, there is a sequence of n concept types t1,...,tn, called the signature of r. A 0-adic
conceptual relation has no arcs, and its signature is empty.
41
•All conceptual relations of the same relation type t have the same valence n and the same signature s.
•The term monadic is synonymous with 1-adic, dyadic with 2-adic, and triadic with 3-adic.
: Forms of concepts
1. A node containing only a type of a concept
“There is a dog, but it is not specified which one dog”
2. Type + individual marker. Names of persons, places, or organizations can be displayed by an individual marker.
3. Specific but unnamed individual. Identity of an object can be acquired from context performing inference
4. Several objects:
-By listing them
-Using {*}
6. Units of measurements
7.All by using “ or ∀
42
“All fish are wet”
8. A conceptual graph can include a concept which is a conceptual graph by itself.
9. Different combinations
43
Restricting operation can be applied to the graph G1 by replacing type Animal with its subtype Dog: Reksi.
A new graph G3 is acquired as a result.
Now we can join graphs G2 and G3, because they have an identical concept node Dog:Reksi.
A new graph G4 is acquired.
44
2. Conjunction is displayed by placing both conceptual graphs in the common propositional node.
Example:
A conceptual graph displaying a sentence “The study course is interesting and difficult”
The IE(inference engine) is a software program, which infers the knowledge available in the knowledge base.
As an expert’s power the expert system’s creditability also depends on the Explanation and Reasoning of the decision
made/suggested by the system. Also, human beings have an ability to learn new things and forget the unused
knowledge from their minds. Simulation of such learning is essential component of KBS. The life of KBS may vary
according to the degree of such simulation. KBS may be either manually updated (manual update) or automatically
updated by machine (machine learning). Ideally, the basic frame of a KBS rarely needs to be modified. In addition to
all these, there should be an appropriate User Interface, which may have the Natural Language Processing facility.
These components are shown in Figure 2.
45
(v) Intelligent Tutoring Systems.
46