CS344: Artificial Intelligence

63
CS344: Artificial Intelligence Pushpak Bhattacharyya CSE Dept., IIT Bombay Lecture 12, 13– Predicate Calculus and Knowledge Representation

description

CS344: Artificial Intelligence. Pushpak Bhattacharyya CSE Dept., IIT Bombay Lecture 12, 13– Predicate Calculus and Knowledge Representation. Logic and inferencing. Vision. NLP. Search Reasoning Learning Knowledge. Expert Systems. Robotics. Planning. - PowerPoint PPT Presentation

Transcript of CS344: Artificial Intelligence

Page 1: CS344: Artificial Intelligence

CS344: Artificial Intelligence

Pushpak BhattacharyyaCSE Dept., IIT Bombay

Lecture 12, 13– Predicate Calculus and Knowledge Representation

Page 2: CS344: Artificial Intelligence

Logic and inferencing

Vision NLP

Expert Systems

Planning

Robotics

Search Reasoning Learning Knowledge

Obtaining implication of given facts and rules -- Hallmark of intelligence

Page 3: CS344: Artificial Intelligence

Inferencing through

− Deduction (General to specific)− Induction (Specific to General)− Abduction (Conclusion to hypothesis in absence of any other evidence

to contrary)

Deduction

Given: All men are mortal (rule)Shakespeare is a man (fact)

To prove: Shakespeare is mortal (inference)

Induction

Given: Shakespeare is mortal Newton is mortal (Observation)Dijkstra is mortal

To prove: All men are mortal (Generalization)

Page 4: CS344: Artificial Intelligence

If there is rain, then there will be no picnic

Fact1: There was rainConclude: There was no picnic

Deduction

Fact2: There was no picnicConclude: There was no rain (?)

Induction and abduction are fallible forms of reasoning. Their conclusions are susceptible to retraction

Two systems of logic

1) Propositional calculus2) Predicate calculus

Page 5: CS344: Artificial Intelligence

Propositions

− Stand for facts/assertions− Declarative statements

− As opposed to interrogative statements (questions) or imperative statements (request, order)

Operators

=> and ¬ form a minimal set (can express other operations)- Prove it.

Tautologies are formulae whose truth value is always T, whatever the assignment is

)((~),),(),( NIMPLICATIONOTORAND

Page 6: CS344: Artificial Intelligence

Model

In propositional calculus any formula with n propositions has 2n models (assignments)

- Tautologies evaluate to T in all models.

Examples: 1)

2)

-e Morgan with AND

PP

)()( QPQP

Page 7: CS344: Artificial Intelligence

Semantic Tree/Tableau method of proving tautology

Start with the negation of the formula

α-formula

β-formula

α-formula

pq

¬q¬ p

- α - formula

- β - formula

)]()([ QPQP

)( QP

)( QP

- α - formula

Page 8: CS344: Artificial Intelligence

Example 2:

B C B CContradictions in all paths

X

α-formula ¬A ¬C

¬A ¬B ¬A ¬B

AB∨C

AB∨C A

B∨CA

B∨C

(α - formulae)

(β - formulae)

(α - formula)

)]()()([ CABACBA

)( CBA

))()(( CABA

)( BA

))( CA

Page 9: CS344: Artificial Intelligence

Exercise:

Prove the backward implication in the previous example

Page 10: CS344: Artificial Intelligence

Inferencing in PC

Resolution Forward chaining

Backward chaining

Page 11: CS344: Artificial Intelligence

Knowledge

Declarative Procedural

• Declarative knowledge deals with factoid questions (what is the capital of India? Who won the Wimbledon in 2005? Etc.)

• Procedural knowledge deals with “How”

• Procedural knowledge can be embedded in declarative knowledge

Page 12: CS344: Artificial Intelligence

Example: Employee knowledge base

Employee record

Emp id : 1124

Age : 27

Salary : 10L / annum

Tax : Procedure to calculate tax from basic salary, Loans, medical factors, and # of children

Page 13: CS344: Artificial Intelligence

Text Knowledge Representation

Page 14: CS344: Artificial Intelligence

A Semantic Graph

in: modifiera: indefinite

the: definite

student

past tense

agent

bought

objecttime

computer

new

June

modifier

The student bought a new computer in June.

Page 15: CS344: Artificial Intelligence

UNL representation

Ram is reading the newspaper

Representation of Knowledge

Page 16: CS344: Artificial Intelligence

UNL: a United Nations project

Started in 1996 10 year program 15 research groups across continents First goal: generators Next goal: analysers (needs solving various

ambiguity problems) Current active language groups

UNL_French (GETA-CLIPS, IMAG) UNL_Hindi (IIT Bombay with additional work on

UNL_English) UNL_Italian (Univ. of Pisa) UNL_Portugese (Univ of Sao Paolo, Brazil) UNL_Russian (Institute of Linguistics, Moscow) UNL_Spanish (UPM, Madrid)

Dave, Parikh and Bhattacharyya, Journal of Machine Translation, 2002

Page 17: CS344: Artificial Intelligence

Knowledge Representation

Ram

read

newspaper

agt obj

UNL Graph - relations

Page 18: CS344: Artificial Intelligence

Knowledge Representation

Ram(iof>person)

read(icl>interpret)

newspaper(icl>print_media)

UNL Graph - UWs

agt obj

Page 19: CS344: Artificial Intelligence

Knowledge Representation

Ram(iof>person)

read(icl>interpret)

newspaper(icl>print_media)

@entry@present@progress

@def

Ram is reading the newspaper

UNL graph - attributes

agt obj

Page 20: CS344: Artificial Intelligence

The boy who works here went to school

plt

agt@ entry @ past

school(icl>institution)

go(icl>move)

boy(icl>person)

work(icl>do)

here

@ entry

agt plc

:01

Another Example

Page 21: CS344: Artificial Intelligence

Predicate Calculus

Page 22: CS344: Artificial Intelligence

Predicate Calculus: well known examples

Man is mortal : rule

∀x[man(x) → mortal(x)]

shakespeare is a manman(shakespeare)

To infer shakespeare is mortal mortal(shakespeare)

Page 23: CS344: Artificial Intelligence

Forward Chaining/ Inferencing

man(x) → mortal(x) Dropping the quantifier, implicitly Universal

quantification assumed man(shakespeare)

Goal mortal(shakespeare) Found in one step x = shakespeare, unification

Page 24: CS344: Artificial Intelligence

Backward Chaining/ Inferencing

man(x) → mortal(x) Goal mortal(shakespeare)

x = shakespeare Travel back over and hit the fact asserted man(shakespeare)

Page 25: CS344: Artificial Intelligence

Resolution - Refutation

man(x) → mortal(x) Convert to clausal form ~man(shakespeare) mortal(x)

Clauses in the knowledge base ~man(shakespeare) mortal(x) man(shakespeare) mortal(shakespeare)

Page 26: CS344: Artificial Intelligence

Resolution – Refutation contd Negate the goal

~man(shakespeare) Get a pair of resolvents

)(~ eshakespearmortal )()(~ eshakespearmortaleshakespearman

)(~ eshakespearman )(~ eshakespearman

Page 27: CS344: Artificial Intelligence

Resolution Tree

1Re solvent 2Re solvent

soluteRe

Page 28: CS344: Artificial Intelligence

Search in resolution

Heuristics for Resolution Search Goal Supported Strategy

Always start with the negated goal Set of support strategy

Always one of the resolvents is the most recently produced resolute

Page 29: CS344: Artificial Intelligence

Inferencing in Predicate Calculus

Forward chaining Given P, , to infer Q P, match L.H.S of Assert Q from R.H.S

Backward chaining Q, Match R.H.S of assert P Check if P exists

Resolution – Refutation Negate goal Convert all pieces of knowledge into clausal form (disjunction of

literals) See if contradiction indicated by null clause can be derived

QP

QP

Page 30: CS344: Artificial Intelligence

1. P

2. converted to

3.

Draw the resolution tree (actually an inverted tree). Every node is a clausal form and branches are intermediate inference steps.

QP QP ~

Q~

Q~

QP ~

P~ P

Page 31: CS344: Artificial Intelligence

Terminology

Pair of clauses being resolved is called the Resolvents. The resulting clause is called the Resolute.

Choosing the correct pair of resolvents is a matter of search.

Page 32: CS344: Artificial Intelligence

Predicate Calculus

Introduction through an example (Zohar Manna, 1974): Problem: A, B and C belong to the

Himalayan club. Every member in the club is either a mountain climber or a skier or both. A likes whatever B dislikes and dislikes whatever B likes. A likes rain and snow. No mountain climber likes rain. Every skier likes snow. Is there a member who is a mountain climber and not a skier?

Given knowledge has: Facts Rules

Page 33: CS344: Artificial Intelligence

Predicate Calculus: Example contd. Let mc denote mountain climber and sk denotes skier.

Knowledge representation in the given problem is as follows:

1. member(A)2. member(B)3. member(C)4. ∀x[member(x) → (mc(x) ∨ sk(x))]5. ∀x[mc(x) → ~like(x,rain)]6. ∀x[sk(x) → like(x, snow)]7. ∀x[like(B, x) → ~like(A, x)]8. ∀x[~like(B, x) → like(A, x)]9. like(A, rain)10. like(A, snow)11. Question: ∃x[member(x) ∧ mc(x) ∧ ~sk(x)]

We have to infer the 11th expression from the given 10. Done through Resolution Refutation.

Page 34: CS344: Artificial Intelligence

Club example: Inferencing1. member(A)

2. member(B)

3. member(C)

4. – Can be written as –

5. –

6. –

7. –

))]()(()([ xskxmcxmemberx

))]()(()([ xskxmcxmember )()()(~ xskxmcxmember )],()([ snowxlkxskx

),()(~ snowxlkxsk )],(~)([ rainxlkxmcx

),(~)(~ rainxlkxmc )],(~),([ xBlkxAlikex

),(~),(~ xBlkxAlike

Page 35: CS344: Artificial Intelligence

8. –

9.

10.

11. – Negate–

)],(),([~ xBlkxAlkx

),(),( xBlkxAlk

),( rainAlk

),( snowAlk

)](~)()([ xskxmcxmemberx

)]()(~)([~ xskxmcxmemberx

Page 36: CS344: Artificial Intelligence

Now standardize the variables apart which results in the following

1. member(A)

2. member(B)

3. member(C)

4.

5.

6.

7.

8.

9.

10.

11.

)()()(~ 111 xskxmcxmember

),()(~ 22 snowxlkxsk ),(~)(~ 33 rainxlkxmc

),(~),(~ 44 xBlkxAlike

),(),( 55 xBlkxAlk

),( rainAlk

),( snowAlk)]()(~)([~ 666 xskxmcxmemberx

Page 37: CS344: Artificial Intelligence

),(~),(~ 44 xBlkxAlike ),( snowAlk

),(~ snowBlk ),()(~ 22 snowxlkxsk

)()()(~ 111 xskxmcxmember )(~ Bsk

)()(~ BmcBmember )(Bmember

)(Bmc)]()(~)([~ 666 xskxmcxmemberx

)()(~ BskBmember )(~ Bsk

)(~ Bmember )(Bmember

710

12 5

13 4

14 2

1115

16 13

17 2

Page 38: CS344: Artificial Intelligence

Assignment Prove the inferencing in the Himalayan club

example with different starting points, producing different resolution trees.

Think of a Prolog implementation of the problem

Prolog Reference (Prolog by Chockshin & Melish)

Page 39: CS344: Artificial Intelligence

Problem-2

From predicate calculus

Page 40: CS344: Artificial Intelligence

A “department” environment1. Dr. X is the HoD of CSE2. Y and Z work in CSE3. Dr. P is the HoD of ME4. Q and R work in ME5. Y is married to Q6. By Institute policy staffs of the same

department cannot marry7. All married staff of CSE are insured by LIC8. HoD is the boss of all staff in the

department

Page 41: CS344: Artificial Intelligence

Diagrammatic representation

Dr. X

Y Z

Dr. P

Q R

married

CSE ME

Page 42: CS344: Artificial Intelligence

Questions on “department”

Who works in CSE? Is there a married person in ME? Is there somebody insured by LIC?

Page 43: CS344: Artificial Intelligence

Problem-3 (Zohar Manna, Mathematical Theory of Computation, 1974)

From Propositional Calculus

Page 44: CS344: Artificial Intelligence

Tourist in a country of truth-sayers and liers Facts and Rules: In a certain country,

people either always speak the truth or always lie. A tourist T comes to a junction in the country and finds an inhabitant S of the country standing there. One of the roads at the junction leads to the capital of the country and the other does not. S can be asked only yes/no questions.

Question: What single yes/no question can T ask of S, so that the direction of the capital is revealed?

Page 45: CS344: Artificial Intelligence

Diagrammatic representation

S (either always says the truthOr always lies)

T (tourist)

Capital

Page 46: CS344: Artificial Intelligence

Deciding the Propositions: a very difficult step- needs human intelligence

P: Left road leads to capital Q: S always speaks the truth

Page 47: CS344: Artificial Intelligence

Meta Question: What question should the tourist ask The form of the question Very difficult: needs human

intelligence The tourist should ask

Is R true? The answer is “yes” if and only if

the left road leads to the capital The structure of R to be found as

a function of P and Q

Page 48: CS344: Artificial Intelligence

A more mechanical part: use of truth table

P Q S’s Answer

R

T T Yes T

T F Yes F

F T No F

F F No T

Page 49: CS344: Artificial Intelligence

Get form of R: quite mechanical

From the truth table R is of the form (P x-nor Q) or (P

≡ Q)

Page 50: CS344: Artificial Intelligence

Get R in English/Hindi/Hebrew… Natural Language Generation: non-trivial The question the tourist will ask is

Is it true that the left road leads to the capital if and only if you speak the truth?

Exercise: A more well known form of this question asked by the tourist uses the X-OR operator instead of the X-Nor. What changes do you have to incorporate to the solution, to get that answer?

Page 51: CS344: Artificial Intelligence

Problem-4

From Propositional Calculus

Page 52: CS344: Artificial Intelligence

Another tourist example: this time in a restaurant setting in a different country (Manna, 1974)

Facts: A tourist is in a restaurant in a country when the waiter tells him:

“do you see the three men in the table yonder? One of them is X who always speaks the truth, another is Y who always lies and the third is Z who sometimes speaks the truth and sometimes lies, i.e., answers yes/no randomly without regard to the question.

Question: Can you (the tourist) ask three yes/no questions to these men, always indicating who should answer the question, and determine who of them is X, who y and who Z?

Page 53: CS344: Artificial Intelligence

Solution: Most of the steps are doable by humans only Number the persons: 1, 2, 3

1 can be X/Y/Z 2 can be X/Y/Z 3 can be X/Y/Z

Let the first question be to 1 One of 2 and 3 has to be NOT Z. Critical step in the solution: only

humans can do?

Page 54: CS344: Artificial Intelligence

Now cast the problem in the same setting as the tourist and the capital example

Solving by analogy Use of previously solved problems Hallmark of intelligence

Page 55: CS344: Artificial Intelligence

Analogy with the tourist and the capital problem Find the direction to the capital

Find Z; who amongst 1, 2 and 3 is Z? Ask a single yes/no question to S (the

person standing at the junction) Ask a single yes/no question to 1

Answer forced to reveal the direction of the capital Answer forced to reveal who from 1,2,3 is

Z

Page 56: CS344: Artificial Intelligence

Question to 1

Ask “Is R true” and the answer is yes if and only if 2 is not Z

Propositions P: 2 is not Z Q: 1 always speaks the truth, i.e., 1 is

X

Page 57: CS344: Artificial Intelligence

Use of truth table as before

P Q 1’s Answer

R

T T Yes T

T F Yes F

F T No F

F F No T

Page 58: CS344: Artificial Intelligence

Question to 1: the first question

Is it true that 2 is not Z if and only if you are X?

Page 59: CS344: Artificial Intelligence

Analysis of 1’s answer

Ans= yes Case 1: 1 is X/Y (always speaks the

truth or always lies) 2 is indeed not Z (we can trust 1’s

answer) Case 2: 1 is Z

2 is indeed not Z (we cannot trust 1’s answer; but that does not affect us)

Page 60: CS344: Artificial Intelligence

Analysis of 1’s answer (contd)

Ans= no Case 1: 1 is X/Y (always speaks the

truth or always lies) 2 is Z; hence 3 is not Z

Case 2: 1 is Z 3 is not Z

Note carefully: how cleverly Z is identified. Can a machine do it?

Page 61: CS344: Artificial Intelligence

Next steps: ask the 2nd question to determine X/Y

Once “Not Z” is identified- say 2, ask him a tautology Is P≡P

If yes, 2 is X If no, 2 is Y

Page 62: CS344: Artificial Intelligence

Ask the 3rd Question Ask 2 “is 1 Z” If 2 is X

Ans=yes, 1 is Z Ans=no, 1 is Y

If 2 is Y (always lies) Ans=yes, 1 is X Ans=no, 1 is Z

3 is the remaining person

Page 63: CS344: Artificial Intelligence

What do these examples show? Logic systematizes the reasoning process Helps identify what is

mechanical/routine/automatable Brings to light the steps that only human

intelligence can perform These are especially of foundational and

structural nature (e.g., deciding what propositions to start with)

Algorithmizing reasoning is not trivial