intro to ai knowledge representation & reasoning ruth bergman fall 2002

43
Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

Post on 21-Dec-2015

223 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

Intro to AIKnowledge Representation &

Reasoning

Ruth Bergman

Fall 2002

Page 2: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

Logic & AI

• One of the original problem areas in AI was mathematical theorem proving: logic theorist, GPS– first complete inference procedure was computational

• Early on many researchers realized that it was essential to have a “formal” language for talking about knowledge– logic seems like the obvious language

• These two facts have led logic and logical inference to be generally viewed as essential to symbolic AI– explicit language for expressing “knowledge”– formal inference procedures– nothing “hidden” in the code --- a fully declarative approach

Page 3: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

Knowledge-Based Agent

Agent

Environm

entSensors

Effectors

Inference

Knowledge

Page 4: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

Knowledge-Based Agent

1. Knowledge or epistemological level

“What the agent can know about”

The Golden Gate Bridge links San Francisco and Marin County

2. Logical level

representation of facts as sentences in a formal language

Links(GGBridge, SF, Marin)

3. Implementation level

how inference is implemented on the agent architecture

Page 5: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

Building KB Agent

• Initially input designer’s knowledge in the form of sentences - declarative approach

• Design learning mechanism - autonomous agent

Page 6: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

Representation & Reasoning

• Knowledge representation : express knowledge in computer-tractable form– Syntax : the written form of sentences– Semantics : facts in the world to which the

sentences refer

• Reasoning : a process of constructing new physical configurations from old ones

Page 7: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

Representation

• Programming language– good for describing algorithms and concrete data

structures– hard to represent “there is a blue flower”

• Natural language– expressive– ambiguous, depend on context “small dog and cat”

• Good KB representation language– expressive, concise, unambiguous, effective– first-order predicate calculus (first order logic)

Page 8: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

Syntax of First Order Logic

• Term: – Constant

p, q, AI

– Variable x

– Predicate of n arguments (Pn : Un {True,False})brother, LeftLegOf

– Function of n arguments (fn : Un U)Before, HasColor, Raining

• connective: ^ | v | | | • quantifier: |

Page 9: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

Well-Formed Formulae

• AtomicSentence: pred (term1, term2, .. termn)Brother(Joseph, Reuven)

• Sentence: – AtomicSentence Sentence

Brother(Joseph,Jacob)

– Sentence connective SentenceBrother(Joseph, Reuven) ^ Brother(Joseph, Judea)

– quantifier Sentencex Brother(Joseph,x) -> Son(x, Jacob)

– (Sentence)

Page 10: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

Semantics

• Semantics is the link between what we write (syntax) and what it means (semantics)

• We must define an interpretation for the sentences we write. The interpretation gives the sentence meaning in the world.

• We will assume all of our languages of compositional: we can recursively define the meaning of sentences in terms of their components

Page 11: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

Models• A model of a sentence is any world in which a sentence is true

under a particular interpretation

Example: any world where {p=False, q = False} is a model for

p -> q• The more claims, the fewer the models • Models of complex sentences are described by the models of

their component, and can be viewed as sets

Example: Let the set P be the set of all the models of p and Q the set of all models of q. Then the set Q v P is the set of all models of p -> q

U is the set of all modelsP Q

U

Page 12: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

Models for FOL

• Universe U of objects• A interpretation function I that

– maps constants to elements of U

– maps function symbols f of n arguments to elements of U

– maps predicates P of n arguments to relations, i.e. a subset PU of Un

• Example: a model of integral arithmetic– Integers U = {1,2,3,…}

– Functions symbols, f1= successor ={(0,1), (1,2), (2,3),…}

f2= + ={(0,1,1), (0,2,2), (1,2,3), (0,3,3),…}

– Predicate symbols, p=lessThan={(0,1), (0,2), (1,2), (0,3)…}

Page 13: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

Interpretation in FOL • meaning of constants

1, 2, jacob, …• meaning of functions

I(f(t1, t2, ... tn)) = u U if f(I(t1),…I(tn))= u• meaning of predicates

I(P(t1, t2, ... tn)) = true if <I(t1),…I(tn)> PU

false otherwise• meaning of connectives ^ | v | | |

Connectives operate on truth values {True, False}Truth table gives true values for every possible

input valuesimply connective: any implication is true whenever

its antecedent is false• The meaning of a complex sentence is derived

from its parts

p q P->q

T T T

T F F

F T T

F F T

Page 14: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

Variable Substitution

• Consider a substitution s to be a list of pairs x/u where x is a variable in the language and u is an element of U

• a [s] is the sentence a with all of the variable assignments given in s

• Example: a = x,y childof(y,x) parentof(x,y)a [x/jacob, y/issac] = childof(issac,jacob) parentof(jacob,issac)

Page 15: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

Interpretation of Quantifiers

• meaning of variablesx[x/u] = u

• meaning of quantifiersx P(x) the predicate P holds for all objects x Ux P(x) the predicate P holds for some object x U

• Order of quantification is very important

• The term Well-Formed Formula (wff) is often used for sentences that have all their variables quantified

• A term with no variables is called a ground term

x y Loves(x,y)Everybody loves somebody

y x Loves(x,y)There is someone who is loved by everyone

Page 16: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

An Example x male(x) v female(x) ^ x (male(x) ^ female(x)) x y z parentof(x,y) ^ ancesterof(y,z) ancesterof(x,z) x y parentof(x,y) ancesterof(x,y) x parentof(fatherof(x),x) ^ parentof(motherof(x),x) ^

male(fatherof(x)) ^ female(motherof(x)) x y1, y2 parentof(y1,x) ^ parentof(y2,x) ^ (y1 = y2) x,y childof(y,x) parentof(x,y)• male(jacob), female(rebecca), parentof(rebecca,jacob) .....

• E.g. show x y ancesterof(y,x)

Page 17: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

Logical Reasoning

• We need a proof theory for our representation• Two notions of determining what follows from

what we know– KB |= KB entails a; if KB is true, then so is

Sentence is entailed by KB if all models of KB are models of

– KB |-i inference procedure i derives from the sentences in KB

Page 18: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

Representation & the “Real World”

sentences sentences

facts facts

Se

ma

ntics

Se

ma

ntics

entailment

follows

world

representation

Page 19: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

Inference

• Sound reasoning = logical inference = deduction

Valid A sentence s is valid if it is true in all interpretationsin all possible worldsnecessarily true, tautologies, analytic sentence

SatisfiableA sentence s is satisfiable if it is true for some interpretation in some world

UnsatisfiableA sentence s is unsatisfiable if there is no interpretation in all possible world for which it it true

Page 20: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

Inference Procedure

• We can make up any way of creating new sentences from old– i is sound if KB |-i implies that KB |=

• we only derive statements that are true given what we know

• the record of the derivation is called a proof

– i is complete if KB |= implies that KB |-i • if a fact is true, we can derive it

• Soundness is essential (and usually easy)• Completeness is hard (and sometimes

impossible!)

Page 21: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

Inference for Propositional Logic

• [Reminder] Propositional Logic– Atomic sentence: True, False, p, jacob– connective: ^ | v | | |

• We could do inference for propositional logic just by checking models– 2n potential true values for a sentence with n

atoms– Impractical even for propositional logic– Cannot extend this inference procedure for FOL

with infinitely large universe U

Page 22: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

Rules of Inference for Propositional Logic

Modus Ponens

And-Elimination

And-Introduction

Or-Introduction

Double-Negation Elimination

Unit Resolution

Resolution

,

n

i

...21

i

n

...21

n

n

...

,...,,

21

21

,

,

Page 23: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

Rules of Inference Involving Quantifiers

• The connection between the universal and existential quantifiers P(x) == x P(x) x P(x) == x P(x)

Universal Elimination

Existential Elimination

Existential Introduction

]/[ g

]/[ k

][g/

Sentence , variable , ground term g

Sentence , variable , constant k no in KB

Sentence , variable not in , ground term g in

Page 24: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

Example

• From our previous axiomitization1. x male(x) v female(x) ^ (male(x) ^ female(x))2. x y z parentof(x,y) ^ ancesterof(y,z) ancesterof(x,z)3. x y parentof(x,y) ancesterof(x,y)4. x parentof(fatherof(x),x) ^ parentof(motherof(x),x) ^

male(fatherof(x)) ^ female(motherof(x))5. x y1, y2 parentof(y1,x) ^ parentof(y2,x) ^ (y1 = y2)6. x,y childof(y,x) parentof(x,y)7. male(jacob), female(rebecca), parentof(rebecca,jacob) ...

• show x y ancesterof(y,x) ^ female(y)– childof(jacob, rebecca) childof(rebecca,jacob)

Page 25: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

Notes on Proofs by Inference

• A proof may require many steps• The proof process requires matching, substitution

and application of the inference rules

Page 26: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

An Inference Procedure for FOL?

• This inference procedure will find a proof for any true sentence

• For false sentences this procedure may not halt. This procedure is semi-decidable.

An inference procedure1. If is in KB return yes2. Apply inferences rules on KB3. Add new sentences to KB4. Go to 2

Page 27: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

Building a Knowledge Base

• The process of building a knowledge base is called knowledge engineering

• The knowledge engineer must encode domain knowledge in logic sentences

• Typically, the knowledge engineer is a logician, not a domain expert.

• Thus, the knowledge engineer interviews domain expert(s) to learn about the domain. This process is called knowledge acquisition.– A realistic domain typically requires thousands of rules– The knowledge is not available in rule form– The domain expert’s time is precious ($$$)– This process may take years – the knowledge engineering

bottleneck

Page 28: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

Knowledge Engineering

• 5-step methodology– Decide what to talk about– Decide on a vocabulary of predicates, functions,

and constants : ontology of the domain– Encode general knowledge about domain : writing

logical sentences or axioms– Encode descriptions of the specific problem

instances : writing simple atomic sentences– Pose queries to the inference procedure and get

answers

Page 29: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

Electronic Circuits Domain

• What to talk about: circuits, terminals, signals, gates, gate types

X1

O1

A2

A1

X2

C1

3

21

1

2

Page 30: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

Electronic Circuits Ontology

– Representation of constants• Gates X1, X2,…• Gate types XOR, OR, AND and NOT• Signal value constants : On, Off

– Representation of objects• Output terminals Out(1, X1) , In(2, X1)

– Representation of predicates on objects• Type (X1) = XOR v.s. Type(X1, XOR) v.s. XOR(X1) • Signal(X1) = On

– Representation of relations between objects• Connected(Out(1, X1) , In(1, X2) )

Page 31: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

Electronic Circuits Representation

• Encode general rules– If two terminals are connected, then they have the same signal i1, i2

Connected (i1, i2) Signal(i1) = Signal(i1)– An XOR gate’s output is on iff its inputs are different

g Type(g)=XOR Signal(Out(1,g)) = on Signal(In(1,g)) != Signal(In(2,g))

– … Five more rules for this domain• Encode specific instances

– Type(X1) = XOR, …– Connected(Out(1, X1) , In(1, X2)) …

• Pose queries to the inference procedure– What are the inputs for Sum bit = Off and Carry bit = On ?

i1, i2, i3 Signal(In(1, C1)) = i1 Signal(In(2, C1)) = i2 Signal(In(3, C1)) = i3 Signal(Out(1, C1)) = Off Signal(Out(2, C1)) = On

Page 32: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

General Relations and Predicates

• Representation of general predicates– If x is a parent of y then it is an ancestor of y

x y parentof(x,y) ancesterof(x,y)

x y z parentof(x,y) ^ ancesterof(y,z) ancesterof(x,z)

• Representation of general relations on predicates– Ancestor is transitive

x y z ancestorof(x,y) ^ ancesterof(y,z) ancesterof(x,z)– Ancestor is asymmetric

x y z ancestorof(x,y) ancesterof(y,x)

Page 33: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

Higher Order Logics

• General relations on predicates– Predicate p is transitive

p Transitive(p) x y p(x,y) ^ p(y,z) ancesterof(x,z)

– Predicate p is asymmetric p Transitive(p) x y p(x,y) p(y,x)

• Higher-order logic have strictly greater expressive power than first-order logic.

• Logicians have little understanding of how to reason effectively with sentences in higher-order logic.

Page 34: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

Representation limits of FOL

• Inheritance x bird(x) flies(x) x penguin(x) bird(x)

• Inheritance with exceptions x penguin(x) flies(x)penguin(opus)

Can deduce both flies(opus) and flies(opus)A contradiction.

• The property of monotonicityFOL is a monotonic logic. If P follows from KB, then it still

follows when KB is augmented with a new sentence s.There are nonmonotonic logics that explicitly deal with default

values

Page 35: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

General Ontologies• Special-purpose ontologies

– Are the most efficient representation to solve problems for the given domain

– Lack re-usability. Portions of knowledge have to be duplicated from one ontology to another.

• General purpose ontologies– more demanding to construct– once done, many advantages

• General purpose ontologies should be applicable in any special-purpose domain– Add domain specific rules

• General purpose ontologies enable reasoning in several areas simultaneously.– In sufficiently demanding domains, different areas of knowledge

must be unified

Page 36: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

General Ontologies

• Categories – define a taxonomic hierarchy where properties are inherited from more general categories

Birds Pigeons, x Bird(x) fly(x)• Measures – a representation for mass, age, price, length, etc.• Composite objects – objects belong to categories based on their

composition from subparts. E.g a chair has four legs and a flat seat

• Time, Space and Change– represent a universe of continuous temporal and spatial dimensions. Times places and objects are part of this universe.

• Events and processes – events are things that occur with space and time extent; processes are continuous events.

Page 37: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

General Ontologies

• Physical objects – allow objects to have different properties at different times.

E.g. PrimeMinister(Israel)• Substances – describe properties that are intrinsic to the

substances, rather than properties of the object as a whole.

E.g., x,y x Butter ^ part of(y,x) y Butter• Mental objects and Beliefs – in multi-agent domains, it is

important for an agent to reason about the mental processes of the other agents.

Page 38: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

General purpose ontology

• Categories : objects having certain common properties

• Measures : quantities of particular type, age, mass...

• Composite objects : car with wheels, engines, ...

• Time, Space, and Change • Events and Processes : individual event and continuous

events

• Physical Objects• Substances : Tomato juice is category? Physical object?

• Mental Objects and Beliefs : reason about belief of its own or others

Page 39: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

West Wessex Marathon Race

(by Martin Hollis) • With a field of five for the west wessex marathon race, there

was little to interest the bettors. So, Peter Piper opened one of his ingenious books where he accepts multiple bets at high odds. To place a multiple bet, you must bet on two propositions, and you will win only if you are wholly successful. Peter Piper is now on an extended vacation because of the bettors who lost these bets:

1. A will not win the gold, nor B the silver.2. C will win a medal, and D will not.3. D and E will both win medals.4. D will not win the silver, nor E the bronze.5. A will win a medal, and C will not.

Who won which of the medals?

Page 40: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

West Wessex Marathon Race

I. A racer medals iff he receives a gold, silver or bronze medalx medal(x) (gold(x) v silver(x) v bronze(x))

II. A racer can only receive one medal

. x gold(x) medal(x) ^ (silver(x) v bronze(x))

. x silver(x) medal(x) ^ (gold(x) v bronze(x))

c. x bronze(x) medal(x) ^ (silver(x) v gold(x))III. Only one race can receive a gold (silver, bronze) medal

. x,y gold(x) ^ x != y gold(y)

. x,y silver(x) ^ x != y silver(y)

c. x,y bronze(x) ^ x != y bronze(y)IV. Some participant must win a gold (silver, bronze) medal

. x gold(x). x silver(x)c. x bronze(x)

Page 41: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

West Wessex Marathon Race

1. A will not win the gold, nor B the silver is falsegold(A) v silver(B)

2. C will win a medal, and D will not is false

medal(C) v medal(D)3. D and E will both win medals is false

medal(D) v medal(E)4. D will not win the silver, nor E the bronze is false

silver(D) v bronze(E)5. A will win a medal, and C will not is false

medal(A) v medal(C)• Who won which of the medals? Proof in class.

Page 42: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

Knights & Knaves

• A very special island is inhabited only by knights and knaves. Knights always tell the truth, and knaves always lie.You meet two inhabitants Zoey and Mel. Zoey tells you Mel and I are both knaves. 1. Is Zoey a knight or knave?2. Is Mel a knight or knave?

Page 43: Intro to AI Knowledge Representation & Reasoning Ruth Bergman Fall 2002

Knights & Knaves• A very special island is inhabited only by knights and

knaves.

knight(x) knave(x)• Knights always tell the truth

x,s knight(x) ^ tell(x,s) TV(s)• knaves always lie

x,s knave(x) ^ tell(x,s) TV(s)• The meaning of the truth value predicate (TV)

s TV(s) s, s TV(s) s• Zoey tells you Mel and I are both knaves.

tell(Zoey, knave(Zoey)^knave(Mel))

1. Is Zoey a knight or knave?

2. Is Mel a knight or knave?