cpsc 322 lecture 12 - cs.ubc.capoole/cs322/2018/slides/lect12s.pdf · elect_cbd.ail load into ailog...

37
Announcements Assignment 5 due today Assignment 6 (smaller than others) available sometime today Midterm: 27 February. I You can bring in a letter sized sheet of paper with anything written in it. I Exam will cover material up to Wednesday of this week I It assumes what is covered in class as well as the content of the assignments. I Practice midterm available this week We have been promised more reliable lecture recording. c D. Poole and A. Mackworth 2017 CPSC 322 — Lecture 12 1 / 37

Upload: truonghanh

Post on 29-May-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

Announcements

Assignment 5 due today

Assignment 6 (smaller than others) available sometimetoday

Midterm: 27 February.I You can bring in a letter sized sheet of paper with

anything written in it.I Exam will cover material up to Wednesday of this weekI It assumes what is covered in class as well as the content

of the assignments.I Practice midterm available this week

We have been promised more reliable lecture recording.

c©D. Poole and A. Mackworth 2017 CPSC 322 — Lecture 12 1 / 37

Review: Propositions and Inference

KB |= g (g is a logical consequence of KB) if and only ifg is true in every model of KB .

The bottom-up proof procedure computs all consequencesof a knowledge base.

Top-down proof procedure searches from the goal to finda proof for a query.

Assumables are used in a proof by contradiction.

A conflict is a set of assumables that, together with theknowledge base, implies false.

c©D. Poole and A. Mackworth 2017 CPSC 322 — Lecture 12 2 / 37

Search Space for SLD Resolution

The search space for a query ?q given KB is defined by:

nodes: answer clauses yes ← body

neighbors of a node:I select an atom in bodyI there is a neighbor for every clause with that atom in the

headI neighbors are defined by SLD resolution

start node: yes ← q.

goal node: yes ←.

c©D. Poole and A. Mackworth 2017 CPSC 322 — Lecture 12 3 / 37

Clicker Question

Suppose the knowledge base includes:

w ← y ∧ zp ← s ∧ tp ← w

answer clause: yes ← w ∧ ratom w is selectedwhich of the following is a possible next answer clause

A yes ← w ∧ r

B yes ← y ∧ z ∧ r

C yes ← y ∧ z ∧ p

D yes ← w ∧ r ∧ y ∧ z

E none of the above

c©D. Poole and A. Mackworth 2017 CPSC 322 — Lecture 12 4 / 37

Clicker Question

Suppose the knowledge base includes:

w ← y ∧ zp ← s ∧ tp ← w

answer clause: yes ← p ∧ ratom p is selectedwhich of the following is the next answer clause

A either yes ← w ∧ r or yes ← s ∧ t ∧ r

B yes ← s ∧ t ∧ w ∧ r

C either yes ← y ∧ z ∧ r or yes ← s ∧ t ∧ r

D yes ← y ∧ z ∧ s ∧ t

E none of the above

c©D. Poole and A. Mackworth 2017 CPSC 322 — Lecture 12 5 / 37

Learning Objectives

assumption-based reasoning (continued)

knowledge-based debugging

representing actions

c©D. Poole and A. Mackworth 2017 CPSC 322 — Lecture 12 6 / 37

Questions and Answers in Horn KBs

An assumable is an atom whose negation you areprepared to accept as part of a (disjunctive) answer.

A conflict of KB is a set of assumables that, given KBimply false.

A minimal conflict is a conflict such that no strict subsetis also a conflict.

c©D. Poole and A. Mackworth 2017 CPSC 322 — Lecture 12 7 / 37

Clicker Question

{c , d , e, f , g , h} are the assumables

KB =

false ← a ∧ b.a← c .a← e.b ← d .b ← e.

A {e} is a minimal conflict

B {e} is a conflict but not a minimal conflict

C {e} is a set of assumables that is not a conflict

D {e} is not a set of assumables

c©D. Poole and A. Mackworth 2017 CPSC 322 — Lecture 12 8 / 37

Clicker Question

{c , d , e, f , g , h} are the assumables

KB =

false ← a ∧ b.a← c .a← e.b ← d .b ← e.

A {c , d , e} is a minimal conflict

B {c , d , e} is a conflict but not a minimal conflict

C {c , d , e} is a set of assumables that is not a conflict

D {c , d , e} is not a set of assumables

c©D. Poole and A. Mackworth 2017 CPSC 322 — Lecture 12 9 / 37

Clicker Question

{c , d , e, f , g , h} are the assumables

KB =

false ← a ∧ b.a← c .a← e.b ← d .b ← e.

A {c , d} is a minimal conflict

B {c , d} is a conflict but not a minimal conflict

C {c , d} is a set of assumables that is not a conflict

D {c , d} is not a set of assumables

c©D. Poole and A. Mackworth 2017 CPSC 322 — Lecture 12 10 / 37

Clicker Question

{c , d , e, f , g , h} are the assumables

KB =

false ← a ∧ b.a← c .a← e.b ← d .b ← e.

A {c , d , e, h} is a minimal conflict

B {c , d , e, h} is a conflict but not a minimal conflict

C {c , d , e, h} is a set of assumables that is not a conflict

D {c , d , e, h} is not a set of assumables

c©D. Poole and A. Mackworth 2017 CPSC 322 — Lecture 12 11 / 37

Clicker Question

{c , d , e, f , g , h} are the assumables

KB =

false ← a ∧ b.a← c .a← e.b ← d .b ← e.

A {a, d} is a minimal conflict

B {a, d} is a conflict but not a minimal conflict

C {a, d} is a set of assumables that is not a conflict

D {a, d} is not a set of assumables

c©D. Poole and A. Mackworth 2017 CPSC 322 — Lecture 12 12 / 37

Clicker Question

{c , d , e, f , g , h} are the assumables

KB =

false ← a ∧ b.a← c .a← e.b ← d .b ← e.

The set of all minimal conflicts is

A {{e}}B {{e}, {c , d}}C {{e}, {c , d}, {e, d}, {c , e}}D {}E None of the above

c©D. Poole and A. Mackworth 2017 CPSC 322 — Lecture 12 13 / 37

Using Conflicts for Diagnosis

Assume that the user is able to observe whether a light islit or dark and whether a power outlet is dead or live.

A light can’t be both lit and dark. An outlet can’t beboth live and dead:

false ← dark l1 ∧ lit l1.

false ← dark l2 ∧ lit l2.

false ← dead p1 ∧ live p2.

Assume the individual components are working correctly:

assumable ok l1.

assumable ok s2.

. . .

Suppose switches s1, s2, and s3 are all up:up s1. up s2. up s3.

c©D. Poole and A. Mackworth 2017 CPSC 322 — Lecture 12 14 / 37

Electrical Environment

light

two-wayswitch

switch

off

on

poweroutlet

circuit�breaker

outside power

l1

l2

w1

w0

w2

w4

w3

w6

w5

p2

p1

cb2

cb1s1

s2s3

c©D. Poole and A. Mackworth 2017 CPSC 322 — Lecture 12 15 / 37

Representing the Electrical Environment

light l1.

light l2.

up s1.

up s2.

up s3.

live outside.

lit l1 ← live w0 ∧ ok l1.

live w0 ← live w1 ∧ up s2 ∧ ok s2.

live w0 ← live w2 ∧ down s2 ∧ ok s2.

live w1 ← live w3 ∧ up s1 ∧ ok s1.

live w2 ← live w3 ∧ down s1 ∧ ok s1.

lit l2 ← live w4 ∧ ok l2.

live w4 ← live w3 ∧ up s3 ∧ ok s3.

live p1 ← live w3.

live w3 ← live w5 ∧ ok cb1.

live p2 ← live w6.

live w6 ← live w5 ∧ ok cb2.

live w5 ← live outside.

c©D. Poole and A. Mackworth 2017 CPSC 322 — Lecture 12 16 / 37

If the user has observed l1 and l2 are both dark:

dark l1. dark l2.

There are two minimal conflicts:

{ok cb1, ok s1, ok s2, ok l1} and

{ok cb1, ok s3, ok l2}.You can derive:

(¬ok cb1 ∨ ¬ok s1 ∨ ¬ok s2 ∨ ¬ok l1)∧(¬ok cb1 ∨ ¬ok s3 ∨ ¬ok l2).

Either cb1 is broken or there is one of six double faults.

c©D. Poole and A. Mackworth 2017 CPSC 322 — Lecture 12 17 / 37

Conflicts in AILog

http://artint.info/code/ailog/ailog_code/ch05/

elect_cbd.ail

Load into AILog and ask queries commented out at bottom.

c©D. Poole and A. Mackworth 2017 CPSC 322 — Lecture 12 18 / 37

Diagnoses

A consistency-based diagnosis is a set of assumables thathas one element in each conflict.

A minimal diagnosis is a diagnosis such that no subset isalso a diagnosis.

Intuitively, one of the minimal diagnoses must hold. Adiagnosis holds if all of its elements are false.

Example: For the proceeding example the conflicts imply

(¬ok cb1 ∨ ¬ok s1 ∨ ¬ok s2 ∨ ¬ok l1)∧(¬ok cb1 ∨ ¬ok s3 ∨ ¬ok l2).

This can be distributed into:

¬ok cb1 ∨ (¬ok s1 ∧ ¬ok s3) ∨ (¬ok s1 ∧ ¬ok l2)

∨ (¬ok s2 ∧ ¬ok s3) ∨ (¬ok s2 ∧ ¬ok l2)

∨ (¬ok l1 ∧ ¬ok s3) ∨ (¬ok l1 ∧ ¬ok l2)

c©D. Poole and A. Mackworth 2017 CPSC 322 — Lecture 12 19 / 37

Recall: top-down consequence finding

To solve the query ?q1 ∧ . . . ∧ qk :

ac := “yes ← q1 ∧ . . . ∧ qk”repeat

select atom a1 from the body of acchoose clause C from KB with a1 as headreplace a1 in the body of ac by the body of C

until ac is an answer.

c©D. Poole and A. Mackworth 2017 CPSC 322 — Lecture 12 20 / 37

Implementing conflict finding: top down

Query is false.

Don’t select an atom that is assumable.

Stop when all of the atoms in the body of the generalisedquery are assumable:

I This set of assumables is a conflict

You may need to search to find minimal conflicts

c©D. Poole and A. Mackworth 2017 CPSC 322 — Lecture 12 21 / 37

Example

false ← a.

a← b ∧ c .

b ← d .

b ← e.

c ← f .

c ← g .

e ← h ∧ w .

e ← g .

w ← f .

assumable d , f , g , h.

c©D. Poole and A. Mackworth 2017 CPSC 322 — Lecture 12 22 / 37

Knowledge-Level Debugging

There are four types of non-syntactic errors that can arise inrule-based systems:

An incorrect answer is produced: an atom that is false inthe intended interpretation was derived.

Some answer wasn’t produced: the proof failed when itshould have succeeded. Some particular true atom wasn’tderived.

The program gets into an infinite loop.

The system asks irrelevant questions.

c©D. Poole and A. Mackworth 2017 CPSC 322 — Lecture 12 23 / 37

Debugging incorrect answers

Suppose atom g was proved but is false in the intendedinterpretation.

There must be a clause g ← a1 ∧ . . . ∧ ak in theknowledge base that was used to prove g .

Either:I one of the ai is false in the intended interpretation orI all of the ai are true in the intended interpretation.

Incorrect answers can be debugged by only answeringyes/no questions.

c©D. Poole and A. Mackworth 2017 CPSC 322 — Lecture 12 24 / 37

Electrical Environment

light

two-wayswitch

switchoff

on

poweroutlet

circuit breaker

outside powercb1

s1

w1s2 w2

w0

l1

w3s3

w4

l2p1

w5

cb2

w6

p2

http://artint.info/code/ailog/ailog_code/ch05/

elect_bug.ail (no assumables or askables)c©D. Poole and A. Mackworth 2017 CPSC 322 — Lecture 12 25 / 37

Missing Answers

If atom g is true in the intended interpretation, but could notbe proved, either:

There is no appropriate clause for g .

There is a rule g ← a1 ∧ . . . ∧ ak that should havesucceeded.

I One of the ai is true in the interpretation and could notbe proved.

c©D. Poole and A. Mackworth 2017 CPSC 322 — Lecture 12 26 / 37

State-space Search

deterministic or stochastic dynamics

fully observable or partially observable

explicit states or features or individuals and relations

static or finite stage or indefinite stage or infinite stage

goals or complex preferences

perfect rationality or bounded rationality

flat or modular or hierarchical

single agent or multiple agents

knowledge is given or knowledge is learned

reason offline or reason while interacting with environment

c©D. Poole and A. Mackworth 2017 CPSC 322 — Lecture 12 27 / 37

Classical Planning

deterministic or stochastic dynamics

fully observable or partially observable

explicit states or features or individuals and relations

static or finite stage or indefinite stage or infinite stage

goals or complex preferences

perfect rationality or bounded rationality

flat or modular or hierarchical

single agent or multiple agents

knowledge is given or knowledge is learned

reason offline or reason while interacting with environment

c©D. Poole and A. Mackworth 2017 CPSC 322 — Lecture 12 28 / 37

Planning

Planning is deciding what to do based on an agent’sability, its goals. and the state of the world.

Planning is finding a sequence of actions to solve a goal.

Initial assumptions:I The world is deterministic.I There are no exogenous events outside of the control of

the robot that change the state of the world.I The agent knows what state it is in.I Time progresses discretely from one state to the next.I Goals are predicates of states that need to be achieved.

c©D. Poole and A. Mackworth 2017 CPSC 322 — Lecture 12 29 / 37

Actions

A deterministic action is a partial function from states tostates.

The preconditions of an action specify when the actioncan be carried out.

The effect of an action specifies the resulting state.

c©D. Poole and A. Mackworth 2017 CPSC 322 — Lecture 12 30 / 37

Delivery Robot Example

Coffee Shop(cs)

Mail Room(mr )

Lab(lab)

Sam'sOffice(off )

Features:RLoc – Rob’s locationRHC – Rob has coffeeSWC – Sam wants coffeeMW – Mail is waitingRHM – Rob has mail

Actions:mc – move clockwisemcc – move counterclockwisepuc – pickup coffeedc – deliver coffeepum – pickup maildm – deliver mail

c©D. Poole and A. Mackworth 2017 CPSC 322 — Lecture 12 31 / 37

Explicit State-space Representation

State Action Resulting State〈lab,¬rhc , swc ,¬mw , rhm〉 mc 〈mr ,¬rhc , swc ,¬mw , rhm〉〈lab,¬rhc , swc ,¬mw , rhm〉 mcc 〈off ,¬rhc , swc ,¬mw , rhm〉〈off ,¬rhc , swc ,¬mw , rhm〉 dm 〈off ,¬rhc , swc ,¬mw ,¬rhm〉〈off ,¬rhc , swc ,¬mw , rhm〉 mcc 〈cs,¬rhc , swc ,¬mw , rhm〉〈off ,¬rhc , swc ,¬mw , rhm〉 mc 〈lab,¬rhc , swc ,¬mw , rhm〉. . . . . . . . .

What happens when we also want to model its battery charge?

c©D. Poole and A. Mackworth 2017 CPSC 322 — Lecture 12 32 / 37

STRIPS Representation

For each action specify:

precondition: when the action can be carried out.

effect: a set of assignments of values to features that aremade true by this action.

STRIPS assumption: every feature not mentioned in theeffects is unaffected by the action.

c©D. Poole and A. Mackworth 2017 CPSC 322 — Lecture 12 33 / 37

Example STRIPS representation

Pick-up coffee (puc):

precondition: [cs,¬rhc]

effect: [rhc]

Deliver coffee (dc):

precondition: [off , rhc]

effect: [¬rhc ,¬swc]

c©D. Poole and A. Mackworth 2017 CPSC 322 — Lecture 12 34 / 37

Planning

Given:

A description of the effects and preconditions of theactions

A description of the initial state

A goal to achieve

find a sequence of actions that is possible and will result in astate satisfying the goal.

c©D. Poole and A. Mackworth 2017 CPSC 322 — Lecture 12 35 / 37

Forward Planning

Idea: search in the state-space graph.

The nodes represent the states

The arcs correspond to the actions: The arcs from a states represent all of the actions that are legal in state s.

A plan is a path from the state representing the initialstate to a state that satisfies the goal.

c©D. Poole and A. Mackworth 2017 CPSC 322 — Lecture 12 36 / 37

Example state-space graph

mac

Actionsmc: move clockwisemac: move anticlockwisenm: no movepuc: pick up coffeedc: deliver coffeepum: pick up maildm: deliver mail

mc

mac

mac

mac

mac

mc

mcmc

puc

〈cs,rhc,swc,mw,rhm〉

〈cs,rhc,swc,mw,rhm〉 〈off,rhc,swc,mw,rhm〉 〈mr,rhc,swc,mw,rhm〉

〈off,rhc,swc,mw,rhm〉

〈mr,rhc,swc,mw,rhm〉

〈lab,rhc,swc,mw,rhm〉〈cs,rhc,swc,mw,rhm〉

dc

〈off,rhc,swc,mw,rhm〉

〈lab,rhc,swc,mw,rhm〉

〈mr,rhc,swc,mw,rhm〉

Locations:cs: coffee shopoff: officelab: laboratorymr: mail room

Feature valuesrhc: robot has coffeeswc: Sam wants coffeemw: mail waitingrhm: robot has mail

c©D. Poole and A. Mackworth 2017 CPSC 322 — Lecture 12 37 / 37