Top Banner
From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004
48

From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

Dec 16, 2015

Download

Documents

Helen Frear
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

From Propositional Logic to PROLOG

From Propositional Logic to PROLOG

CSE P573

Applications of Artificial IntelligenceHenry Kautz

Fall 2004

Page 2: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

TonightTonight

• Discussion of assignment 1

• Games of chance

1. Basic elements of logic

2. Resolution

• Ground [Application: diagnosis]

• With variables

• With function symbols

3. Prolog

Page 3: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

Nondeterministic Games

Involve chance: dice, shuffling, etc.

Chance nodes: calculate the expected value

E.g.: weighted average over all possible dice rolls

Page 4: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

In Practice...

Chance adds dramatically to size of search space

Backgammon: number of distinct possible rolls of dice is 21Branching factor b is usually around 20, but can be as high as 4000 (dice rolls that are doubles)Alpha-beta pruning is

generally less effectiveBest Backgammon programs

use other methods

Page 5: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

Imperfect Information

E.g. card games, where opponents’ initial cards are unknownIdea: For all deals

consistent with what you can see

compute the minimax value of available actions for each of possible dealscompute the expected value over all deals

Page 6: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

Probabilistic STRIPS Planning

domain: Hungry Monkey

shake: if (ontable)

Prob(2/3) -> +1 banana

Prob(1/3) -> no change

else

Prob(1/6) -> +1 banana

Prob(5/6) -> no change

jump: if (~ontable)

Prob(2/3) -> ontable

Prob(1/3) -> ~ontable

else

ontable

Page 7: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

What is the expected reward?

[1] shake

[2] jump; shake

[3] jump; shake; shake;

[4] jump; if (~ontable){ jump; shake}

else { shake; shake }

Page 8: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

ExpectiMax

node chance a isn if )(ExpectiMax)(

nodemax isn if )}(children|)(ExpectiMaxmax{

node terminala isn if )(

)(ExpectiMax

)(

nchildrens

ssP

nss

nU

n

Page 9: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

Hungry Monkey: 2-Ply Game Tree

0 0 1 0 0 0 1 0 1 1 2 1 0 0 1 0

jump

jump jumpjump

jump

shake

shake shake shakeshake

2/3

2/3 2/3 2/3 2/3 2/3

1/3

1/3 1/3 1/3 1/3 1/3

1/6 5/6

1/6 1/61/6 5/6 5/6 5/6

Page 10: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

ExpectiMax 1 – Chance Nodes

0 2/3

0 0 1 0

0 1/6

0 0 1 0

1 7/6

1 1 2 1

0 1/6

0 0 1 0

jump

jump jumpjump

jump

shake

shake shake shakeshake

2/3

2/3 2/32/3 2/3 2/3

1/3

1/3 1/3 1/3 1/3 1/3

1/6 5/6

1/6 1/61/6 5/6 5/6 5/6

Page 11: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

ExpectiMax 2 – Max Nodes

2/3

0 2/3

0 0 1 0

1/6

0 1/6

0 0 1 0

7/6

1 7/6

1 1 2 1

1/6

0 1/6

0 0 1 0

jump

jump jumpjump

jump

shake

shake shake shakeshake

2/3

2/3 2/32/3 2/3 2/3

1/3

1/3 1/3 1/3 1/3 1/3

1/6 5/6

1/6 1/61/6 5/6 5/6 5/6

Page 12: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

ExpectiMax 3 – Chance Nodes

1/2 1/3

2/3

0 2/3

0 0 1 0

1/6

0 1/6

0 0 1 0

7/6

1 7/6

1 1 2 1

1/6

0 1/6

0 0 1 0

jump

jump jumpjump

jump

shake

shake shake shakeshake

2/3

2/3 2/32/3 2/3 2/3

1/3

1/3 1/3 1/3 1/3 1/3

1/6 5/6

1/6 1/61/6 5/6 5/6 5/6

Page 13: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

ExpectiMax 4 – Max Node

1/2

1/2 1/3

2/3

0 2/3

0 0 1 0

1/6

0 1/6

0 0 1 0

7/6

1 7/6

1 1 2 1

1/6

0 1/6

0 0 1 0

jump

jump jumpjump

jump

shake

shake shake shakeshake

2/3

2/3 2/32/3 2/3 2/3

1/3

1/3 1/3 1/3 1/3 1/3

1/6 5/6

1/6 1/61/6 5/6 5/6 5/6

Page 14: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

Policies

The result of the ExpectiMax analysis is a conditional plan (also called a policy):

Optimal plan for 2 steps: jump; shake

Optimal plan for 3 steps:jump; if (ontable) {shake; shake}

else {jump; shake}

Probabilistic planning can be generalized in many ways, including action costs and hidden state

The general problem is that of solving a Markov Decision Process (MDP)

Page 15: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

Summary

Deterministic gamesMinimax searchAlpha-Beta pruningStatic evaluation functions

Games of chanceExpected valueProbabilistic planning

Strategic games with large branching factors (Go)

Relatively little progress

Page 16: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

Desiderata for Knowledge Representation

Desiderata for Knowledge Representation

1. Declarative

• Separate knowledge from specific use

2. Expressive

• General rules as well as facts

• Incomplete information

3. Concise

• Can draw many new conclusions

4. Effectively computable

• Unambiguous How does STRIPS measure up?

Page 17: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

Basic Idea of LogicBasic Idea of Logic

By starting with true assumptions, you can deduce true conclusions.

Francis Bacon (1561-1626) No pleasure is comparable to the standing upon the vantage-ground of truth.

Thomas Henry Huxley (1825-1895) Irrationally held truths may be more harmful than reasoned errors.

John Keats (1795-1821) Beauty is truth, truth beauty; that is allYe know on earth, and all ye need to know.

Blaise Pascal (1623-1662) We know the truth, not only by the reason, but also by the heart.

François Rabelais (c. 1490-1553) Speak the truth and shame the Devil.

Daniel Webster (1782-1852) There is nothing so powerful as truth, and often nothing so strange.

Page 18: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

The Big ThreeThe Big Three

Page 19: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

EntailmentEntailment

m – something that determines whether a sentence S is true or false – a “possible world”

m S• S is true in m• m is a model of S

S T• S entails T• Every model of S is a model of T• When S is true, then T must be true

Page 20: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

ImplicationImplication

0 0 1

0 1 1

1 0 0

1 1 1

xy0 0 1

0 1 1

1 0 0

1 1 1

xy

Page 21: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

ConsequenceConsequence

A logic includes a set of mechanical rules for determining which sentences can be derived from other sentences

S TT is a consequence of S

Sound:

if S T then S T

Complete:

if S T then S T

Page 22: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

ResolutionResolution

P v Q, ~P

Q

P v Q, ~P v R

Q v R

P v Q v S , ~Q v S

P v S

Bush or Kerry will get a popular majority. Bush won’t get a popular majority.

Bush or Kerry will get a popular major. If Bush gets a popular majority, the country will unite.

If neither Bush or Kerry get a popular majority, the Supreme Court will pick the president.If Kerry gets a popular majority, the Supreme Court will pick the president.

Page 23: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

Conjunctive Normal FormConjunctive Normal Form

• Any sentence is equivalent to one where:

• Top level is a conjunction of clauses

• Each clause is a disjunction of literals

• Each literal is a proposition or its negation

In the worst-case, how muchlarger is the CNF form of a

sentence? What canwe do about it?

Page 24: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

New Variable TrickNew Variable Trick

Putting a formula in clausal form may increase its size exponentially

But can avoid this by introducing dummy variables(abc)(def) {(ad),(ae),(af),

(bd),(be),(bf), (cd),(ce),(cf) }

(abc)(def) {(gh),(abcg),(ga),(gb),(gc), (defh),(hd),(he),(hf)}

Dummy variables don’t change satisfiability!

Page 25: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

Proof by RefutationProof by Refutation

S T

iff (S T) false

Model theory:

S T

iff S T has no models (is unsatisfiable)

Page 26: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

Resolution ProofResolution Proof

DAG, where leaves are input clauses

• Internal nodes are resolvants

• Root is false (empty clause)

( A H)

(M A)

( H) (I H)

( M)

( M I)(I)(A)

(M)

()

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

Prove: the unicorn is horned.

Page 27: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

Expert System for Automobile Diagnosis

Expert System for Automobile Diagnosis

Knowledge Base:

GasInTank FuelLineOK GasInEngine

GasInEngine GoodSpark EngineRuns

PowerToPlugs PlugsClean GoodSpark

BatteryCharged CablesOK PowerToPlugs

Observed:

EngineRuns,GasInTank, PlugsClean, BatteryCharged

Prove:

FuelLineOK CablesOK

Page 28: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

Solution by ResolutionSolution by Resolution

Knowledge Base and Observations:( GasInTank FuelLineOK GasInEngine)( GasInEngine GoodSpark EngineRuns)( PowerToPlugs PlugsClean GoodSpark)( BatteryCharged CablesOK PowerToPlugs)(EngineRuns)(GasInTank)(PlugsClean)(BatteryCharged)

Negation of Conclusion:(FuelLineOK)(CablesOK)

Unit propagation = Resolution where

one clause must be a single literal

Page 29: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

How Do You Know What to Prove?

How Do You Know What to Prove?

In this example were given the diagnosis we wanted to prove:

FuelLineOK CablesOK

But, in general, how do you know what to prove?

A powerful and widely-used technique for finding an hypothesis that explains an observed system fault ( EngineRuns) is Consistency Based Diagnosis.

Page 30: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

Consistency-Based DiagnosisConsistency-Based Diagnosis

1. Make some Observations O.

2. Initialize the Assumption Set A to assert that all components are working properly.

3. Check if the KB, A, O together are inconsistent (can deduce false).

4. If so, delete propositions from A until consistency is restored (cannot deduce false). The deleted propositions are a diagnosis.

There may be many possible diagnoses

Page 31: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

ExampleExample

Is KB Observations Assumptions consistent?

KB { EngineRuns, GasInTank, PlugsClean, BatteryCharged} { FuelLineOK, CablesOK } false

• Must restore consistency!

KB { EngineRuns,GasInTank, PlugsClean, BatteryCharged} {CablesOK } false

• So FuelLineOK is a possible diagnosis!

KB { EngineRuns,GasInTank, PlugsClean, BatteryCharged} {FuelLineOK} false

• So CablesOK is a possible diagnosis!

Page 32: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

Complexity of DiagnosisComplexity of Diagnosis

If KB is Horn, then each consistency test takes linear time.

Complexity = ways to delete propositions from Assumption Set that are considered.

• Single fault diagnosis – O(n2)

• Double fault diagnosis – O(n3)

• Triple fault diagnosis – O(n4)

Page 33: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

Deep Space OneDeep Space One

• Autonomous diagnosis & repair “Remote Agent”

• Compiled systems schematic to 7,000 var SAT problem

Started: January 1996Launch: October 15th, 1998Experiment: May 17-21

Page 34: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

TonightTonight

• Discussion of assignment 1

• Games of chance

1. Basic elements of logic

2. Resolution

• Ground [Application: diagnosis]

• With variables

• With function symbols

3. Prolog

Page 35: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

First-Order LogicFirst-Order Logic

All men are mortal.

x . (man(x) mortal(x))

No man is not mortal.

x . (man(x) mortal(x) )

Everybody has somebody they lean on.

x . (person(x) y . (person(y) leans_on(x,y))

A number is less than it’s successor.

n . (number(x) less_than(x, successor(x)) )

Nothing is less than zero.

x . less_than(x, ZERO)

Quantifiers Variables

Constants Function Symbols

Page 36: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

First-Order Clausal FormFirst-Order Clausal Form

• Begin with universal quantifiers (implicit)

• Rest is a clause

• No , but may use function symbols instead

• Variables in each clause are unique

man(x) mortal(x)

person(x) person(friend(x))

person(y) leans_on(friend(y))

number(x) less_than(x, successor(x))

Page 37: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

UnificationUnification

Can resolve clauses if can unify one pair of literals

• Same predicate, one positive, one negative

• Match variable(s) to other variables, constants, or complex terms (function symbols)

• Carry bindings on variables through to all the other literals in the result!

(Mortal(HENRY)) (Mortal(y)Fallible(y))

(Fallible(HENRY))

Page 38: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

Unification with Multiple Variables

Unification with Multiple Variables

You always hurt the ones you love.

Politicians love themselves.

Therefore, politicians hurt themselves.

love(x,y)hurt(x,y) politician(z)love(z,z)

politician(w)hurt(w,w)

Page 39: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

Unification with Function Symbols

Unification with Function Symbols

(Less(a,suc(a))) (Less(b,c) Less(c,d) Less(b,d))

(Less(b,a) Less(b,suc(a)))

rename variables:

(Less(e,f) Less(e,suc(f)))

Less(a,suc(suc(a)))

A number is less than its successor

“Less than” is transitive

A number is less than the successor of its successor

{c/a, d/suc(a)}

{e/a,f/suc(a)}

Page 40: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

TonightTonight

• Discussion of assignment 1

• Games of chance

1. Basic elements of logic

2. Resolution

• Ground [Application: diagnosis]

• With variables

• With function symbols

3. Prolog

Page 41: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

Making FOL PracticalMaking FOL Practical

Barriers to using FOL:

• Choice of clauses to resolve

• Huge amount of memory to store DAG

• Getting useful answers to queries (not just “yes” or “no”)

PROLOG’s answers:

• Simple backward-chaining resolution strategy – left/right, first to last clause

• Tree-shaped proofs – no need to store entire proof in memory at one time

• Extract answers to queries by returning variable bindings

Page 42: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

Prolog InterpreterProlog Interpreter

binding_list disprove(literal neglit){

choose (clause c) such that (binding = unify(head(c),neglit))

if (no choice possible){

backtrack to last choice;}

for (each lit in body(c)){

binding = binding U disprove(substitute(lit,binding));

}

return binding;

}

Page 43: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

ExampleExample

• Rich people are happy.

• People who love happy people are happy.

• Your spouse loves you.

• Your mother loves you.

• Bill is rich.

• Melinda is Bill’s spouse.

• Elaine is Melinda’s mother.

• Mary is Bill’s mother.

• Paul is rich.

• Barbara is Henry’s mother.

run prolog, consult(happy)

Page 44: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

happy.plhappy.pl

happy(X) :- rich(X).

happy(X) :- loves(X,Y),happy(Y).

loves(X,Y) :- spouse(X,Y).

loves(X,Y) :- mother(X,Y).

rich(bill).

spouse(melinda,bill).

mother(elaine,melinda).

mother(mary,bill).

rich(paul).

mother(barbara,henry).

Page 45: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

Prolog LimitationsProlog Limitations

• Only handles definite clauses (exactly one positive literal per clause)

• No true disjuction: cannot express e.g.happy(bill) v happy(henry)

• Tree-shaped proofs means some sub-steps may be repeatedly derived

• DATALOG: does forward-chaining inference and caches derived unit clauses

• Interpreter can get into an infinite loop if care is not taken in form & order of clauses

Page 46: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

toohappy.pltoohappy.pl

happy(X) :- rich(X).happy(X) :- loves(X,Y),happy(Y).loves(X,Y) :- spouse(X,Y).loves(X,Y) :- mother(X,Y).

rich(bill).spouse(melinda,bill).mother(elaine,melinda).mother(mary,bill).rich(paul).mother(barbara,henry).

loves(bill,melinda).loves(henry,barbara).

Page 47: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

ExerciseExercise

You have just been hired by snacks.com, an Internet startup that provides snacking recommendations. Your first assignment is to create an expert system that will recommend snacks according to the following rules:

• Every snack should contain one beverage and one munchie.

• Sweet beverages are good with salty munchies.

• Bitter beverages are good with sweet munchies or salty munchies.

Define a predicate snack(X,Y) that makes such recommendations.

Get started with: prolog/snack.pl

Page 48: From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004.

Next WeekNext Week

Data structures in Prolog

Natural language processing