CS 380: ARTIFICIAL INTELLIGENCE LOGICAL AGENTSsanti/teaching/2013/CS... · Declarative Programming...

31
CS 380: ARTIFICIAL INTELLIGENCE LOGICAL AGENTS 11/6/2013 Santiago Ontañón [email protected] https://www.cs.drexel.edu/~santi/teaching/2013/CS380/intro.html

Transcript of CS 380: ARTIFICIAL INTELLIGENCE LOGICAL AGENTSsanti/teaching/2013/CS... · Declarative Programming...

Page 1: CS 380: ARTIFICIAL INTELLIGENCE LOGICAL AGENTSsanti/teaching/2013/CS... · Declarative Programming • Tell an agent WHAT to do, but not HOW. • Encode all the necessary knowledge,

CS 380: ARTIFICIAL INTELLIGENCE LOGICAL AGENTS

11/6/2013 Santiago Ontañón [email protected] https://www.cs.drexel.edu/~santi/teaching/2013/CS380/intro.html

Page 2: CS 380: ARTIFICIAL INTELLIGENCE LOGICAL AGENTSsanti/teaching/2013/CS... · Declarative Programming • Tell an agent WHAT to do, but not HOW. • Encode all the necessary knowledge,

Summary so far: • What is AI?

•  Rational Agents

• Problem solving: •  Systematic search

•  Uninformed search: DFS, BFS, ID •  Informed search: heuristics, Best-FS, A*

•  Local Search: Hill Climbing, Simulated Annealing •  Adversarial Search: Minimax, alpha-beta, Monte Carlo Tree Search

• Next: knowledge representation + reasoning

Page 3: CS 380: ARTIFICIAL INTELLIGENCE LOGICAL AGENTSsanti/teaching/2013/CS... · Declarative Programming • Tell an agent WHAT to do, but not HOW. • Encode all the necessary knowledge,

Knowledge • Knowledge base:

Page 4: CS 380: ARTIFICIAL INTELLIGENCE LOGICAL AGENTSsanti/teaching/2013/CS... · Declarative Programming • Tell an agent WHAT to do, but not HOW. • Encode all the necessary knowledge,

Knowledge • Knowledge base:

•  A set of sentences in a formal language

• Knowledge-based agent:

• Declarative programming

Inference engine

Knowledge base

Domain independent

Domain specific

Page 5: CS 380: ARTIFICIAL INTELLIGENCE LOGICAL AGENTSsanti/teaching/2013/CS... · Declarative Programming • Tell an agent WHAT to do, but not HOW. • Encode all the necessary knowledge,

Declarative Programming •  Tell an agent WHAT to do, but not HOW.

• Encode all the necessary knowledge, and let the agent infer how to achieve the goals.

•  For example, instead of programming quick sort, we would tell an agent: •  Here’s a set of numbers. •  Now I want them sorted, which means that for every adjacent

numbers, a, b, they must satisfy a <= b. •  You (the agent) figure out how !

Page 6: CS 380: ARTIFICIAL INTELLIGENCE LOGICAL AGENTSsanti/teaching/2013/CS... · Declarative Programming • Tell an agent WHAT to do, but not HOW. • Encode all the necessary knowledge,

Wumpus World PEAS description

Performance measuregold +1000, death -1000-1 per step, -10 for using the arrow

EnvironmentSquares adjacent to wumpus are smellySquares adjacent to pit are breezyGlitter iff gold is in the same squareShooting kills wumpus if you are facing itShooting uses up the only arrowGrabbing picks up gold if in same squareReleasing drops the gold in same square

Breeze Breeze

Breeze

BreezeBreeze

Stench

Stench

BreezePIT

PIT

PIT

1 2 3 4

1

2

3

4

START

Gold

Stench

Actuators Left turn, Right turn,Forward, Grab, Release, Shoot

Sensors Breeze, Glitter, Smell

Chapter 7 5

Page 7: CS 380: ARTIFICIAL INTELLIGENCE LOGICAL AGENTSsanti/teaching/2013/CS... · Declarative Programming • Tell an agent WHAT to do, but not HOW. • Encode all the necessary knowledge,

Wumpus world characterization

Observable??

Chapter 7 6

Page 8: CS 380: ARTIFICIAL INTELLIGENCE LOGICAL AGENTSsanti/teaching/2013/CS... · Declarative Programming • Tell an agent WHAT to do, but not HOW. • Encode all the necessary knowledge,

Wumpus world characterization

Observable?? No—only local perception

Deterministic??

Chapter 7 7

Page 9: CS 380: ARTIFICIAL INTELLIGENCE LOGICAL AGENTSsanti/teaching/2013/CS... · Declarative Programming • Tell an agent WHAT to do, but not HOW. • Encode all the necessary knowledge,

Wumpus world characterization

Observable?? No—only local perception

Deterministic?? Yes—outcomes exactly specified

Episodic??

Chapter 7 8

Page 10: CS 380: ARTIFICIAL INTELLIGENCE LOGICAL AGENTSsanti/teaching/2013/CS... · Declarative Programming • Tell an agent WHAT to do, but not HOW. • Encode all the necessary knowledge,

Wumpus world characterization

Observable?? No—only local perception

Deterministic?? Yes—outcomes exactly specified

Episodic?? No—sequential at the level of actions

Static??

Chapter 7 9

Page 11: CS 380: ARTIFICIAL INTELLIGENCE LOGICAL AGENTSsanti/teaching/2013/CS... · Declarative Programming • Tell an agent WHAT to do, but not HOW. • Encode all the necessary knowledge,

Wumpus world characterization

Observable?? No—only local perception

Deterministic?? Yes—outcomes exactly specified

Episodic?? No—sequential at the level of actions

Static?? Yes—Wumpus and Pits do not move

Discrete??

Chapter 7 10

Page 12: CS 380: ARTIFICIAL INTELLIGENCE LOGICAL AGENTSsanti/teaching/2013/CS... · Declarative Programming • Tell an agent WHAT to do, but not HOW. • Encode all the necessary knowledge,

Wumpus world characterization

Observable?? No—only local perception

Deterministic?? Yes—outcomes exactly specified

Episodic?? No—sequential at the level of actions

Static?? Yes—Wumpus and Pits do not move

Discrete?? Yes

Single-agent??

Chapter 7 11

Page 13: CS 380: ARTIFICIAL INTELLIGENCE LOGICAL AGENTSsanti/teaching/2013/CS... · Declarative Programming • Tell an agent WHAT to do, but not HOW. • Encode all the necessary knowledge,

Wumpus world characterization

Observable?? No—only local perception

Deterministic?? Yes—outcomes exactly specified

Episodic?? No—sequential at the level of actions

Static?? Yes—Wumpus and Pits do not move

Discrete?? Yes

Single-agent?? Yes—Wumpus is essentially a natural feature

Chapter 7 12

Page 14: CS 380: ARTIFICIAL INTELLIGENCE LOGICAL AGENTSsanti/teaching/2013/CS... · Declarative Programming • Tell an agent WHAT to do, but not HOW. • Encode all the necessary knowledge,

Exploring a wumpus world

A

OK

OKOK

Chapter 7 13

Page 15: CS 380: ARTIFICIAL INTELLIGENCE LOGICAL AGENTSsanti/teaching/2013/CS... · Declarative Programming • Tell an agent WHAT to do, but not HOW. • Encode all the necessary knowledge,

Exploring a wumpus world

OK

OK OK

A

A

B

Chapter 7 14

Page 16: CS 380: ARTIFICIAL INTELLIGENCE LOGICAL AGENTSsanti/teaching/2013/CS... · Declarative Programming • Tell an agent WHAT to do, but not HOW. • Encode all the necessary knowledge,

Exploring a wumpus world

OK

OK OK

A

A

B

P?

P?

Chapter 7 15

Page 17: CS 380: ARTIFICIAL INTELLIGENCE LOGICAL AGENTSsanti/teaching/2013/CS... · Declarative Programming • Tell an agent WHAT to do, but not HOW. • Encode all the necessary knowledge,

Exploring a wumpus world

OK

OK OK

A

A

B

P?

P?

A

S

Chapter 7 16

Page 18: CS 380: ARTIFICIAL INTELLIGENCE LOGICAL AGENTSsanti/teaching/2013/CS... · Declarative Programming • Tell an agent WHAT to do, but not HOW. • Encode all the necessary knowledge,

Exploring a wumpus world

OK

OK OK

A

A

B

P?

P?

A

S

OK

P

WChapter 7 17

Page 19: CS 380: ARTIFICIAL INTELLIGENCE LOGICAL AGENTSsanti/teaching/2013/CS... · Declarative Programming • Tell an agent WHAT to do, but not HOW. • Encode all the necessary knowledge,

Exploring a wumpus world

OK

OK OK

A

A

B

P?

P?

A

S

OK

P

W

A

Chapter 7 18

Page 20: CS 380: ARTIFICIAL INTELLIGENCE LOGICAL AGENTSsanti/teaching/2013/CS... · Declarative Programming • Tell an agent WHAT to do, but not HOW. • Encode all the necessary knowledge,

Exploring a wumpus world

OK

OK OK

A

A

B

P?

P?

A

S

OK

P

W

A

OK

OK

Chapter 7 19

Page 21: CS 380: ARTIFICIAL INTELLIGENCE LOGICAL AGENTSsanti/teaching/2013/CS... · Declarative Programming • Tell an agent WHAT to do, but not HOW. • Encode all the necessary knowledge,

Exploring a wumpus world

OK

OK OK

A

A

B

P?

P?

A

S

OK

P

W

A

OK

OK

A

BGS

Chapter 7 20

Page 22: CS 380: ARTIFICIAL INTELLIGENCE LOGICAL AGENTSsanti/teaching/2013/CS... · Declarative Programming • Tell an agent WHAT to do, but not HOW. • Encode all the necessary knowledge,

Other tight spots

A

B OK

OK OK

A

B

A

P?

P?P?

P?

Breeze in (1,2) and (2,1)⇒ no safe actions

Assuming pits uniformly distributed,(2,2) has pit w/ prob 0.86, vs. 0.31

A

S

Smell in (1,1)⇒ cannot move

Can use a strategy of coercion:shoot straight aheadwumpus was there ⇒ dead ⇒ safewumpus wasn’t there ⇒ safe

Chapter 7 21

Page 23: CS 380: ARTIFICIAL INTELLIGENCE LOGICAL AGENTSsanti/teaching/2013/CS... · Declarative Programming • Tell an agent WHAT to do, but not HOW. • Encode all the necessary knowledge,

Logic in general

Logics are formal languages for representing informationsuch 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

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 = 1x + 2 ≥ y is false in a world where x = 0, y = 6

Chapter 7 22

Page 24: CS 380: ARTIFICIAL INTELLIGENCE LOGICAL AGENTSsanti/teaching/2013/CS... · Declarative Programming • Tell an agent WHAT to do, but not HOW. • Encode all the necessary knowledge,

Entailment

Entailment means that one thing follows from another:

KB |= α

Knowledge base KB entails sentence αif and only if

α is true in all worlds where KB is true

E.g., the KB containing “the Giants won” and “the Reds won”entails “Either the Giants won or the Reds won”

E.g., x + y = 4 entails 4 = x + y

Entailment is a relationship between sentences (i.e., syntax)that is based on semantics

Note: brains process syntax (of some sort)

Chapter 7 23

Page 25: CS 380: ARTIFICIAL INTELLIGENCE LOGICAL AGENTSsanti/teaching/2013/CS... · Declarative Programming • Tell an agent WHAT to do, but not HOW. • Encode all the necessary knowledge,

Models

Logicians typically think in terms of models, which are formallystructured worlds with respect to which truth can be evaluated

We say m is a model of a sentence α if α is true in m

M(α) is the set of all models of α

Then KB |= α if and only if M(KB) ⊆ M(α)

E.g. KB = Giants won and Reds wonα = Giants won M( )

M(KB)

x

x

x

x

x

x

x x

x

x

xx

xxx

xxx

xxx

xx

x xxx

xx x

x

xx

x x xx

xx

x

x

x

x

x

x

x

x

Chapter 7 24

Page 26: CS 380: ARTIFICIAL INTELLIGENCE LOGICAL AGENTSsanti/teaching/2013/CS... · Declarative Programming • Tell an agent WHAT to do, but not HOW. • Encode all the necessary knowledge,

Entailment in the wumpus world

Situation after detecting nothing in [1,1],moving right, breeze in [2,1]

Consider possible models for ?sassuming only pits

AA

B

??

?

3 Boolean choices ⇒ 8 possible models

Chapter 7 25

Page 27: CS 380: ARTIFICIAL INTELLIGENCE LOGICAL AGENTSsanti/teaching/2013/CS... · Declarative Programming • Tell an agent WHAT to do, but not HOW. • Encode all the necessary knowledge,

Wumpus models

1 2 3

1

2

Breeze

PIT

1 2 3

1

2

Breeze

PIT

1 2 3

1

2

Breeze

PIT PIT

PIT

1 2 3

1

2

Breeze

PIT

PIT

1 2 3

1

2

BreezePIT

1 2 3

1

2

Breeze

PIT

PIT

1 2 3

1

2

Breeze

PIT PIT

1 2 3

1

2

Breeze

Chapter 7 26

Page 28: CS 380: ARTIFICIAL INTELLIGENCE LOGICAL AGENTSsanti/teaching/2013/CS... · Declarative Programming • Tell an agent WHAT to do, but not HOW. • Encode all the necessary knowledge,

Wumpus models

1 2 3

1

2

Breeze

PIT

1 2 3

1

2

Breeze

PIT

1 2 3

1

2

Breeze

PIT PIT

PIT

1 2 3

1

2

Breeze

PIT

PIT

1 2 3

1

2

BreezePIT

1 2 3

1

2

Breeze

PIT

PIT

1 2 3

1

2

Breeze

PIT PIT

1 2 3

1

2

Breeze

KB

KB = wumpus-world rules + observations

Chapter 7 27

Page 29: CS 380: ARTIFICIAL INTELLIGENCE LOGICAL AGENTSsanti/teaching/2013/CS... · Declarative Programming • Tell an agent WHAT to do, but not HOW. • Encode all the necessary knowledge,

Wumpus models

1 2 3

1

2

Breeze

PIT

1 2 3

1

2

Breeze

PIT

1 2 3

1

2

Breeze

PIT PIT

PIT

1 2 3

1

2

Breeze

PIT

PIT

1 2 3

1

2

BreezePIT

1 2 3

1

2

Breeze

PIT

PIT

1 2 3

1

2

Breeze

PIT PIT

1 2 3

1

2

Breeze

KB1

KB = wumpus-world rules + observations

α1 = “[1,2] is safe”, KB |= α1, proved by model checking

Chapter 7 28

Page 30: CS 380: ARTIFICIAL INTELLIGENCE LOGICAL AGENTSsanti/teaching/2013/CS... · Declarative Programming • Tell an agent WHAT to do, but not HOW. • Encode all the necessary knowledge,

Wumpus models

1 2 3

1

2

Breeze

PIT

1 2 3

1

2

Breeze

PIT

1 2 3

1

2

Breeze

PIT PIT

PIT

1 2 3

1

2

Breeze

PIT

PIT

1 2 3

1

2

BreezePIT

1 2 3

1

2

Breeze

PIT

PIT

1 2 3

1

2

Breeze

PIT PIT

1 2 3

1

2

Breeze

KB

KB = wumpus-world rules + observations

Chapter 7 29

Page 31: CS 380: ARTIFICIAL INTELLIGENCE LOGICAL AGENTSsanti/teaching/2013/CS... · Declarative Programming • Tell an agent WHAT to do, but not HOW. • Encode all the necessary knowledge,

Wumpus models

1 2 3

1

2

Breeze

PIT

1 2 3

1

2

Breeze

PIT

1 2 3

1

2

Breeze

PIT PIT

PIT

1 2 3

1

2

Breeze

PIT

PIT

1 2 3

1

2

BreezePIT

1 2 3

1

2

Breeze

PIT

PIT

1 2 3

1

2

Breeze

PIT PIT

1 2 3

1

2

Breeze

KB2

KB = wumpus-world rules + observations

α2 = “[2,2] is safe”, KB ̸|= α2

Chapter 7 30