Vous êtes sur la page 1sur 76

UNIT II

Knowledge Representation

Introduction
Knowledge base = set of sentences in a formal
language.
Declarative approach to building an agent (or other
system):
Tell it what it needs to know

Then it can Ask itself what to do - answers should follow


from the KB.
Agents can be viewed at the knowledge level
i.e., what they know, regardless of how implemented.

Or at the implementation level


i.e., data structures in KB and algorithms that manipulate them

Logic
Mathematical logic formalizes certain kinds of reasoning
in terms of operations on mathematical formulas.
It is important for people working in A.I. to know logic for
several reasons:
Theory: Logic has a sound mathematical foundation; things can
be proved about it.
Applications: For certain classes of applications (e.g., proving
correctness of programs) logic is the representation of choice.
Comparison with Other Methods: Other representation
methods are often reducible to logic. Knowing logic helps in
understanding other methods and may help prevent reinvention
of old techniques.

Logic
Logics are formal languages for representing
information such that conclusions can be drawn.
Syntax defines the sentences in the language.
Semantics define the "meaning" of sentences;
i.e., define truth of a sentence in a world

Example
E.g., the language of arithmetic
x+2 y is a sentence; x2+y > {} is not a
sentence.
x+2 y is true iff the number x+2 is no less
than the number y.
x+2 y is true in a world where x = 7, y = 1
x+2 y is false in a world where x = 0, y = 6.

Terms and Symbols


A simple statement is one that does not contain any
other statement as a part. We will use the lower-case
letters, p, q, r.., as symbols for simple statements.
A compound statement is one with two or more simple
statements as parts or what we will call components. A
component of a compound is any whole statement that is
part of a larger statement; components may themselves
be compounds.
An operator (or connective) joins simple statements
into compounds, and joins compounds into larger
compounds.

Simple Statements
p

p is true

assertion

p is false

negation

Compounds and Connectives

pq

either p is true or q is true, or


both

disjunction

pq

"both p and q are true"

conjunction

p q

"if p is true, then q is true"

implication

pq

"p and q are either both true or


both false"

equivalence

Logical equivalence
Two sentences are logically equivalent} iff true in same
models: iff and

Validity and satisfiability


A sentence is valid if it is true in all models,
e.g., True,

A A, A A, (A (A B)) B

Validity is connected to inference via the Deduction Theorem:


KB if and only if (KB ) is valid

A sentence is satisfiable if it is true in some model


e.g., A B,

A sentence is unsatisfiable if it is true in no models


e.g., AA

Satisfiability is connected to inference via the following:


KB if and only if (KB ) is unsatisfiable

Translating from English to


Propositional Logic
P: A purpose of punishment is deterrence
Q: Capital punishment is an effective deterrent
R: Capital punishment should be continued
S: Capital punishment is used in the United States
T: A purpose of punishment is retribution
If a purpose of punishment is deterrence and capital punishment is an
effective deterrent, then capital punishment should be continued
P Q R
Capital punishment is not an effective deterrent although it is used in the
United States
Q S
Capital punishment should not be continued if it is not an effective
deterrent, unless deterrence is not a purpose of punishment
(Q R ) P or (P (Q R))

Inference Rules

Modus Ponens
From an implication and the premise of the implication we can infer
the conclusion.
,

And Elimination
From a conjunction we can infer any of the conjuncts.
1 2, n
i
And-Introduction
From a list of sentences we can infer their conjunction.
1, 2,, n
1 2, n

Inference Rules
Or-Introduction
From a sentence we can infer its disjunction with anything else at all.
i
12,, n
Double- Negation Elimination
From a doubly negated sentence we can infer a positive sentence.

Unit Resolution
From a disjunction, if one of the disjuncts is false, then we can infer
the other one is true.
,

Clauses
We define a clause as the disjunction of a
number of literals. A ground clause is one in
which no variables occur in the expression. A
Horn clause is a clause with at most one positive
literal.

Conversion to Clause form


Eliminate replacing with ( )
( ).
Eliminate , replacing with
.
Move inwards using de Morgans rules
and double negation.
Apply distributivity law ( over ) and
flatten.

Using Predicate Logic


Can represent objects and
quantification
Theorem proving is semi-decidable

Using Predicate Logic


1.

Marcus was a man.

2.

Marcus was a Pompeian.

3.

All Pompeians were Romans.

4.

Caesar was a ruler.

5.

All Pompeians were either loyal to Caesar or hated him.

6.

Every one is loyal to someone.

7.

People only try to assassinate rulers they are not loyal to.

8.

Marcus tried to assassinate Caesar.

Using Predicate Logic


1. Marcus was a man.
man(Marcus)

Using Predicate Logic


2. Marcus was a Pompeian.
Pompeian(Marcus)

Using Predicate Logic


3. All Pompeians were Romans.
x: Pompeian(x) Roman(x)

Using Predicate Logic


4. Caesar was a ruler.
ruler(Caesar)

Using Predicate Logic


5. All Pompeians were either loyal to Caesar or hated
him.
inclusive-or
x: Roman(x) loyalto(x, Caesar) hate(x,
Caesar)
exclusive-or
x: Roman(x) (loyalto(x, Caesar) hate(x,
Caesar))
(loyalto(x, Caesar) hate(x,
Caesar))

Using Predicate Logic


6. Every one is loyal to someone.
x: y: loyalto(x, y) y: x: loyalto(x, y)

Using Predicate Logic


7.

People only try to assassinate rulers they are not loyal to.

x: y: person(x) ruler(y) tryassassinate(x, y)


loyalto(x, y)

Using Predicate Logic


8. Marcus tried to assassinate Caesar.
tryassassinate(Marcus, Caesar)

Using Predicate Logic


Was Marcus loyal to Caesar?
man(Marcus)
ruler(Caesar)
tryassassinate(Marcus, Caesar)
x: man(x) person(x)
loyalto(Marcus, Caesar)

Using Predicate Logic


Many English sentences are ambiguous.
There is often a choice of how to represent knowledge.
Obvious information may be necessary for reasoning
We may not know in advance which statements to deduce (P or
P).

Reasoning
1. Marcus was a Pompeian.
2. All Pompeians died when the volcano
erupted in 79 A.D.
3. It is now 2008 A.D.

Is Marcus alive?

Reasoning
1.

Marcus was a Pompeian.


Pompeian(Marcus)

2.

All Pompeians died when the volcano erupted in 79 A.D.


erupted(volcano, 79) x: Pompeian(x) died(x, 79)

3.

It is now 2008 A.D.


now = 2008

Reasoning
1.

Marcus was a Pompeian.


Pompeian(Marcus)

2.

All Pompeians died when the volcano erupted in 79 A.D.


erupted(volcano, 79) x: Pompeian(x) died(x, 79)

3.

It is now 2008 A.D.


now = 2008

x: t1: t2: died(x, t1) greater-than(t2, t1)


dead(x, t2)

Resolution
The basic ideas
KB |

KB |false

Resolution
The basic ideas
KB |

KB |false

( ) ( )

( )

Resolution
The basic ideas
KB |

KB |false

( ) ( )
sound and complete

( )

Resolution in Propositional
Logic
1. Convert all the propositions of KB to clause
form (S).
2. Negate and convert it to clause form. Add it
to S.
3. Repeat until either a contradiction is found or
no progress can be made.
a. Select two clauses ( P) and ( P).
b. Add the resolvent ( ) to S.

Resolution in Propositional
Logic
Example:
KB = {P, (P Q) R, (S T) Q, T}
=R

Resolution in Predicate Logic


Example:
KB = {P(a), x: (P(x) Q(x)) R(x), y: (S(y)
T(y)) Q(y), T(a)}
= R(a)

Resolution in Predicate Logic


Unification:
UNIFY(p, q) = unifier where SUBST(, p) =
SUBST(, q)

Resolution in Predicate Logic


Unification:
x: knows(John, x) hates(John, x)
knows(John, Jane)
y: knows(y, Leonid)
y: knows(y, mother(y))
x: knows(x, Elizabeth)
UNIFY(knows(John, x), knows(John, Jane)) = {Jane/x}
UNIFY(knows(John, x), knows(y, Leonid)) = {Leonid/x, John/y}
UNIFY(knows(John, x), knows(y, mother(y))) = {John/y, mother(John)/x}
UNIFY(knows(John, x), knows(x, Elizabeth)) = FAIL

Resolution in Predicate Logic


Unification: Standardization
UNIFY(knows(John, x), knows(y, Elizabeth)) = {John/y,
Elizabeth/x}

Resolution in Predicate Logic


Unification: Most general unifier
UNIFY(knows(John, x), knows(y, z))
= {John/y,
John/x, John/z}
= {John/y, Jane/x,
Jane/z}
= {John/y, v/x, v/z}
= {John/y, z/x, Jane/v}
= {John/y, z/x}

Resolution in Predicate Logic


Unification: Occur check
UNIFY(knows(x, x), knows(y, mother(y))) = FAIL

Conversion to Clause Form


1.

Eliminate .
P Q P Q

2.

Reduce the scope of each to a single term.


(P Q) P Q
(P Q) P Q
x: P x: P
x: p x: P
P P

3.

Standardize variables so that each quantifier binds a unique


variable.
(x: P(x)) (x: Q(x)) (x: P(x)) (y: Q(y))

Conversion to Clause Form


4.

Move all quantifiers to the left without changing their relative


order.
(x: P(x)) (y: Q(y)) x: y: (P(x) (Q(y))

5.

Eliminate (Skolemization).
x: P(x) P(c) Skolem constant
x: y P(x, y) x: P(x, f(x)) Skolem function

6.

Drop .
x: P(x) P(x)

7.

Convert the formula into a conjunction of disjuncts.


(P Q) R (P R) (Q R)

8.

Create a separate clause corresponding to each conjunct.

9.

Standardize apart the variables in the set of obtained clauses.

Conversion to Clause Form


1.

Eliminate .

2.

Reduce the scope of each to a single term.

3.

Standardize variables so that each quantifier binds a unique


variable.

4.

Move all quantifiers to the left without changing their relative order.

5.

Eliminate (Skolemization).

6.

Drop .

7.

Convert the formula into a conjunction of disjuncts.

8.

Create a separate clause corresponding to each conjunct.

9.

Standardize apart the variables in the set of obtained clauses.

Unification

The basic unification algorithm is simple. However, it must be


implemented with care to ensure that the results are correct.
We begin by making sure that the two expressions have no
variables in common. If there are common variables, substitute a
new variable in one of the expressions. (Since variables are
universally quantified, another variable can be substituted without
changing the meaning.)
Imagine moving a pointer left-to-right across both expressions until
parts are encountered that are not the same in both expressions. If
one is a variable, and the other is a term not containing that
variable,
substitute the term for the variable in both expressions,
substitute the term for the variable in the existing substitution set
[This is necessary so that the substitution set will be
simultaneous.]
add the substitution to the substitution set.

Unification Algorithm

Example of Unification
Literal 1
parents(x, father(x),
mother(Bill))

parents(x, father(x),
mother(Bill))

parents(x, father(x),
mother(Jane))

Literal 2

Result of Unify

parents(Bill, father(Bill), y)

{x/Bill, y/mother(Bill)}

{x/Bill, y/Bill, z/mother(Bill)}


parents(Bill, father(y), z)

parents(Bill, father(y),
mother(y))

Failure

Semantic Nets
The major idea is that:
The meaning of a concept comes from its
relationship to other concepts, and that,
The information is stored by interconnecting
nodes with labelled arcs.

Fundamental Components

Lexical part
nodes denoting objects
links denoting relations between objects
labels denoting particular objects and relations

Structural part
the links and nodes form directed graphs
the labels are placed on the links and nodes

Semantic part
meanings are associated with the link and node labels

Procedural part

constructors allow creation of new links and nodes


destructors allow the deletion of links and nodes
writers allow the creation and alteration of labels
readers can extract answers to questions

AND/OR Trees

IS-A Hierarchy

IS-PART Hierarchy

Semantic Network for representing


events

Semantic Network- Intersection


Search

Semantic Network- Inheritances

Semantic Network- Multiple


Inheritances

Semantic Network- Tangled


Hierarchies

Advantages of Semantic Network


They allow us to structure the knowledge to reflect the
structure of that part of the world which is being
represented.
The semantics, i.e. real world meanings, are clearly
identifiable.
There are very powerful representational possibilities as
a result of is a and is a part of inheritance hierarchies.
They can accommodate a hierarchy of default values
They can be used to represent events and natural
language sentences.

Frames
A basic idea of frames is that people make use of
stereotyped information about typical features of objects,
images, and situations.
Such information is assumed to be structured in large
units representing the stereotypes, and these units are
what are referred to as ``frames''.
Frames (or something similar) are important because
they allow deep understanding of new situations about
which only minimal information is directly available.
They represent our understanding of regularities in the
universe that allow intelligent action based on minimal
clues.

Frames

A frame can represent an individual object or a class of similar


objects.
Instead of properties, a frame has slots. A slot is like a property, but
can contain more kinds of information (sometimes called facets of
the slot):
The value of the slot; default value in case no value is present.
A procedure that can be run to compute the value (an if-needed
procedure).
Procedures to be run when a value is put into the slot or removed ( ifadded and if-removed procedures).
These
can
be
used
to
implement demons.
Data type information; constraints on possible slot fillers.
Documentation.

Frames can inherit slots from parent frames. For example, FIDO (an
individual dog) might inherit properties from DOG (its parent class)
or MAMMAL (a parent class of DOG).

Basic Idea of Frames

Converting between Semantic


Networks and Frames

Advantages of Frames

A frame collects information about an object in a single place in an


organized fashion. (Cf. Logic, which represents information about an
object by many small predicates scattered throughout the
database.)
By relating slots to other kinds of frames, a frame can
represent typical structures involving an object; these can be very
important for reasoning based on limited information.
Frames provide a way of associating knowledge with objects (via
the slot procedures).
Frames may be a relatively efficient way of implementing A.I.
applications (direct procedure invocation versus search in a logic
system).
Frames allow data that are stored and computed to be treated in a
uniform manner.

Disadvantages of Frames
Frames encourage baroque representations;
little guide to good structuring of a domain.
Some things that can be represented in logic
cannot be represented well or at all in frames.
Slot fillers must be ``real'' data.
It is not possible to quantify over slots.
It is necessary to repeat the same information to
make it usable from different viewpoints, since
methods are associated with slots or particular object
types.

Conceptual Dependency
Conceptual Dependency originally developed to
represent knowledge acquired from natural
language input.
The goals of this theory are:
To help in the drawing of inference from sentences.
To be independent of the words used in the original
input.
That is to say: For any 2 (or more) sentences that are
identical in meaning there should be only one
representation of that meaning.

Conceptual Dependency cont..


CD provides:
a structure into which nodes representing information
can be placed
a specific set of primitives
at a given level of granularity.

Sentences are represented as a series of


diagrams depicting actions using both abstract
and real physical situations.
The agent and the objects are represented
The actions are built up from a set of primitive acts
which can be modified by tense.

Examples of Primitive Acts


ATRANS
-- Transfer of an abstract relationship. e.g. give.

PTRANS
-- Transfer of the physical location of an object. e.g. go.

PROPEL
-- Application of a physical force to an object. e.g. push.

MTRANS
-- Transfer of mental information. e.g. tell.

MBUILD
-- Construct new information from old. e.g. decide.

Scripts
A script is a structure that prescribes a set of
circumstances which could be expected to follow
on from one another.
It is similar to a thought sequence or a chain of
situations which could be anticipated.
It could be considered to consist of a number of
slots or frames but with more specialised roles.

Beneficiaries of Scripts
Events tend to occur in known runs or patterns.
Causal relationships between events exist.
Entry conditions exist which allow an event to
take place
Prerequisites exist upon events taking place.

Components of Script

Entry Conditions
these must be satisfied before events in the script can occur.

Results
Conditions that will be true after events in script occur.

Props
Slots representing objects involved in events.

Roles
Persons involved in the events.

Track
Variations on the script. Different tracks may share components of the
same script.

Scenes
The sequence of events that occur. Events are represented
in conceptual dependency form.

Advantages & Disadvantages of


Scripts
Advantages of Scripts:
Ability to predict events.
A single coherent interpretation may be build
up from a collection of observations.

Disadvantages:
Less general than frames.
May not be suitable to represent all kinds of
knowledge.

Rule Based Systems


Knowledge is specified as a collection of rules.
Each rule has the form
condition action

which may be read if condition then action.


The condition (antecedent) is a pattern.
The action (consequent) is an operation to be
performed if rule fires.
Knowledge is applied to facts-unconditional
statements that are assumed to be correct (at
the time they are used).

Rule Based System Architecture


A collection of rules
A collection of facts
A rule fires if a fact matches the condition
of the rule
Mechanism that fires rules is inference
engine.

Advantages & Disadvantages


Advantages
These systems are very expressive.
The rules lead to a degree of modularity.

Disadvantages
There is a lack of precise semantics for the
rules.
The systems are not always efficient.

Forward Chaining
Given some facts, work forward through
inference net.
Discovers what conclusions can be derived from
data.

Backward Chaining
To determine if a decision should be made, work
backwards looking for justifications for the
decision.
Eventually, a decision must be justified by facts.

Vous aimerez peut-être aussi