31
CS 4100 Artificial Intelligence Prof. C. Hafner Class Notes Jan 24, 2012

CS 4100 Artificial Intelligence

  • Upload
    urbano

  • View
    31

  • Download
    1

Embed Size (px)

DESCRIPTION

CS 4100 Artificial Intelligence. Prof. C. Hafner Class Notes Jan 24, 2012. Topics for today. Finish discussion of propositional logic Forms of clauses Refutation resolution Forward chaining in PL (review) Backward chaining in PL Discussion of Homework 2 - PowerPoint PPT Presentation

Citation preview

Page 1: CS 4100 Artificial Intelligence

CS 4100 Artificial Intelligence

Prof. C. HafnerClass Notes Jan 24, 2012

Page 2: CS 4100 Artificial Intelligence

Topics for today• Finish discussion of propositional logic

– Forms of clauses – Refutation resolution– Forward chaining in PL (review)– Backward chaining in PL

• Discussion of Homework 2• Review wumpus world model using PL• First order logic• Wumpus world model using FOL

Page 3: CS 4100 Artificial Intelligence

Disjunctive and Implicative form of clauses• ~P1 v ~P2 v . . . v ~Pn v Q V R – disjunctive form• Same as: P1 ^ P2 ^ . . . ^ Pn Q V R -- implicative

form

• What about: ~P1 v ~P2 v . . . v ~Pn Implicative form is:

P1 ^ P2 ^ . . . ^ Pn {} {} == False

• What about Q (single positive literal).Implicative form is: True Q (or just Q)

Any logical sentence can be converted to (one or more) clauses!!

Page 4: CS 4100 Artificial Intelligence

Horn clauses and Definite clauses

All Clauses

Horn clauses: 0 or 1 positive literals

Definite clauses: 1 positive literal

Page 5: CS 4100 Artificial Intelligence

Review: The Resolution Rule for Propositional Logic

[P1 v P2 v . . . Pk ] [ P1 v Q2 v . . . Qn ]---------------------------------------------------

P2 v . . . Pk v Q2 v . . . Qn

A generalization of modus ponens:

P1 [ P1 v Q] Note: [ P1 v Q] equivalent to ------------------------ P1 Q

Q

Page 6: CS 4100 Artificial Intelligence

Refutation Resolution

• Assert the negation of what you want to prove and resolve with current database to obtain {}. Very useful when we move to FOL

• A simple example: E A~E BProve: A v B using refutation resolution

Page 7: CS 4100 Artificial Intelligence

Any KB (i.e., any sentence) can be transformed into an equivalent CNF representation

1. Replace P => Q with P v Q2. Replace P with P3. Replace (P v Q) with P ^ Q4. Replace (P ^ Q) with P v Q5. Apply distributive rule replacing:

(P ^ Q) v R with (P v R) ^ (Q v R)

Page 8: CS 4100 Artificial Intelligence

Class ExerciseConvert the following to CNF (a list of clauses)

Convert the CNF clauses to implicative form

a) A v B v C b) A ^ B ^ Cc) ~A v ~Bd) ~A ^ ~Be) ~A v ~B v C v D v Ef) (A ^ B) v Cg) ~(A ^ ~B) v C

Page 9: CS 4100 Artificial Intelligence

Class Exercise (from text)

• Given the following, can you prove that the unicorn is mythical? Magical? Horned?

If the unicorn is mythical, then it is immortal, but if it is not mythical, then it is a mortal mammal. If the unicorn is either immortal or a mammal, then it is horned. The unicorn is magical if it is horned.

Page 10: CS 4100 Artificial Intelligence

Convert to Clause formIf the unicorn is mythical, then it is immortal, C1 mythical ~mortalC1a ~mythical v ~mortalIf not mythical, then it is a mortal mammal C2. ~mythical mortal ^ mammalC2a mythical v mortalC2b mythical v mammalIf the unicorn is either immortal or a mammal, then it is horned. C3 (~mortal v mammal) horned == (mortal ^ ~mammal) v

hornedC3a mortal v hornedC3b ~mammal v hornedThe unicorn is magical if it is horned. C4 horned magicalC4a ~horned v magicalProve “magical” by refutation

Page 11: CS 4100 Artificial Intelligence

A common error

• Derive: ~mortal v mortal v horned

• Does this imply horned ?? NO• Why? Because it is true whether horned is T or F

Page 12: CS 4100 Artificial Intelligence

Review: Forward chaining: takes a KB of Horn clauses

• Basis of forward chainingP Q is an assertion in the KBP is a new percept----------Conclude Q

• Two views of KB– All implications are made explicit vs.– Reasoning on demand

• “Pure” forward chaining suggests the former

Page 13: CS 4100 Artificial Intelligence

Forward chaining algorithm (KB of Definite Clauses)

Notes: 1. An efficient implementation requires an index of the rules by LHS symbols

2. How are infinite loops prevented by this algorithm ?

ALGORITHM (recursive):PLForwardChain() uses KBase -- a knowledge base of Horn clauses for each new percept p

PLForwardChain1(p) #use a recursive "helper function" PLForwardChain1(percept) if percept is already in KBase, return else add percept to KBase for r in rules where conclusion of r is not already in KBase

if percept is a premise of r and all the other premises of r are known

PLForwardChain1(conclusion of r)

Page 14: CS 4100 Artificial Intelligence

Review forward chaining algorithm

How are infinite loops prevented by this algorithm ?

ALGORITHM (recursive):PLForwardChain() uses KBase -- a knowledge base of Horn clauses for each new percept p

PLForwardChain1(p) #use a recursive "helper function" PLForwardChain1(percept) if percept is already in KBase, return else add percept to KBase for r in rules where conclusion of r is not already in KBase

if percept is a premise of r and all the other premises of r are known

PLForwardChain1(conclusion of r)

Page 15: CS 4100 Artificial Intelligence

HW2: Input format for this knowledge base vegetable edible vegetable ^ green healthy edible ^ healthy recommended apple fruitedible

edible IF vegetablehealthy IF vegetable greenrecommended IF edible healthyfruit IF appleedible

Python: tokenlist = line.split() #string list of strings

Page 16: CS 4100 Artificial Intelligence

Backward chaining: goal driven reasoning triggered by a new percept (fact)

• Basis of backward chainingP ^ R Q is an assertion in the KBQ is a query we want to prove (or disprove)----------Set up P and R as sub-queries, if they are true

then Q is proved• What if we cannot find Q or a rule that succeeds in proving Q.

Then we answer False. This is called negation by failure. (It is not the same as a real logical proof of ~Q).

• Note: P ~Q is not a Horn Clause. It normalizes to P V Q, which has two positive literals

Page 17: CS 4100 Artificial Intelligence

Backward chaining: goal-driven reasoning – triggered by a question being asked

KB:fruit ediblevegetable edibleedible ^ green healthyapple fruitbanana fruitspinach vegetablespinach greenedible ^ healthy recommendedapple

Consider some queries: ? apple ? fruit ? banana ? edible ? healthy

Page 18: CS 4100 Artificial Intelligence

Sketch of Backward Chaining algorithmbackwardChain(KB, query) returns Boolean

if query is in KB, return Truefor each rule r in KB such that RHS(r) == query

testing = Truefor each element e of the LHS(r) if backwardChain(KB, e) = False

testing = Falsebreak

if testing = True return True return FalseNOTE that backward chaining does not update the KB

Page 19: CS 4100 Artificial Intelligence

The Wumpus World in PL

What we need to represent:I. Static knowledgeThe relevant ontology of possible world configurations:

locations on a 4 by 4 grid and their propertiesex: Pxy means a pit at location x,y

Player’s current state (Lxy, has-arrow)The axioms of the world’s configurations

L21 ^ Breeze P22 v P31Player’s current percepts: Breeze, Stench, etc.

Page 20: CS 4100 Artificial Intelligence

The Wumpus World in PL

Additional static world axioms:There is exactly one wumpus:W21 v W31 v . . . W44 == there is at least one

There is at most one:~(W21 ^ W22) -- one axiom like this for each pair

Page 21: CS 4100 Artificial Intelligence

The Wumpus World in PL (cont)What we need to represent:II. Dynamic knowledgeThe agent’s possible actions: up, down, left right, grab, shootThe result of the agent’s actions:

requires temporal indexing: L110 ^ up0 L211 -- one for each location X action X timestep L110 ^ has-arrow0 ^ shoot0 L111 ^ ~has-arrow1The frame problem requires more: L110 ^ up0 L211 ^ ~L111But it is even worse: L110 ^ has-arrow0 ^ up0 L211 ^ ~L111 ^ has-arrow1 L110 ^ ~has-arrow0 ^ up0 L211 ^ ~L111 ^ ~has-arrow1The frame problem arises when we use temporal indexing!!!It causes axioms to multiply almost without limit.

Page 22: CS 4100 Artificial Intelligence

First Order Logic (FOL)

• Why FOL?• Syntax and semantics of FOL• Using FOL• Wumpus world in FOL• Knowledge engineering in FOL

Page 23: CS 4100 Artificial Intelligence

Pros and cons of propositional logic Propositional logic is declarative Propositional logic allows partial/disjunctive/negated

information– (unlike most data structures and databases)– (Horn clauses an intermediate form)

Propositional logic is compositional:– meaning of B1,1 P1,2 is derived from meaning of B1,1 and of

P1,2 Meaning in propositional logic is context-independent

– (unlike natural language, where meaning depends on context)

Propositional logic has very limited expressive power– (unlike natural language)– E.g., cannot say "pits cause breezes in adjacent squares“

• except by writing one sentence for each square

Page 24: CS 4100 Artificial Intelligence

First-order logic• Whereas propositional logic limits world models to

atomic facts such as P12 B22

• first-order logic (like natural language) can manipulate world models that include:– Objects: people, houses, numbers, colors, baseball games,

wars, …– Relations: red, round, prime, brother of, bigger than, part of,

comes between, …– Functions: father, nationality, one more than, plus, …

Adjacent([x,y], [z,w]) ^ Pit([x,y]) Breeze([z,w])– and structured facts such as:

Page 25: CS 4100 Artificial Intelligence

Syntax of FOL: Basic elements• Constant symbols KingJohn, 2, NU,... • Predicate symbols IsHappy, Likes, >,...• Function symbols Sqrt, Nationality,...• Variables x, y, a, b,...• Connectives , , , , • Equality = • Quantifiers ,

• The constant, predicate and function symbols are called a “logical language”. Given a LL we can then define all the logical sentences that can be expressed.

Page 26: CS 4100 Artificial Intelligence

Atomic sentences

Atomic sentence = predicate (term1,...,termn) |term1 = term2

Term = constant |variable |function (term1,...,termn)

• E.g., Brother(KingJohn,RichardTheLionheart)• Greater (AgeOf(Richard), AgeOf(John))• Brother (AgeOf(Richard), AgeOf(John))

Page 27: CS 4100 Artificial Intelligence

Complex sentences

• Complex sentences are made from atomic sentences using connectives (with the same semantics as propositional logic)

S, S1 S2, S1 S2, S1 S2, S1 S2,

E.g. Sibling(John,Richard) < Sibling(Richard,John) >(1,2) ≤ (1,2) >(1,2) >(1,2)

Page 28: CS 4100 Artificial Intelligence

Complex sentences (cont.)

• Additional complex sentences may include quantifiers: and

var [S] var [S]

Abbreviate: x y z [S] as x, y, z [S]Abbreviate: x y z [S] as x, y, z [S]

Page 29: CS 4100 Artificial Intelligence

Meaning and truth in first-order logic• Sentences of FOL are true with respect to a model and an

interpretation

• A model for a FOL language is a “world” of objects (domain elements) and relations among them (compare with propositional logic model)

• Interpretation I specifies referents forconstant symbols → objectspredicate symbols → relationsfunction symbols → functions

• An atomic sentence P(term1,...,termn) is trueiff the objects referred to by term1,...,termnare in the relation I(P)

Page 30: CS 4100 Artificial Intelligence

Meaning and truth in first-order logic (cont.)

• Complex sentences: truth is defined using the same truth tables: S1 S2 is true iff S1 is true and S2 is true.

• x [S] is true iff, for any object C in the model S[x/C] is true

• x [S] is true iff, for at least one object C in the model S[x/C] is true

Page 31: CS 4100 Artificial Intelligence

Models for FOL: Example

symbols: constant relation function