Declarative Programming PROLOG

31
1 Declarative Programming PROLOG Second part of Cmput325 Fall 2004 R Greiner + B Price (+ Bayesian Nets)

description

Declarative Programming PROLOG. (+ Bayesian Nets). Second part of Cmput325 Fall 2004 R Greiner + B Price. Declarative Programming. Motivation Warm Fuzzies What is Logic? ... Logic Programming? Mechanics of Prolog Terms, Substitution, Unification, Horn Clauses, Proof process - PowerPoint PPT Presentation

Transcript of Declarative Programming PROLOG

Page 1: Declarative Programming PROLOG

1

Declarative Programming PROLOG

Second part of Cmput325Fall 2004

R Greiner + B Price

(+ Bayesian Nets)

Page 2: Declarative Programming PROLOG

2

Declarative Programming

Motivation Warm Fuzzies What is Logic? ... Logic Programming?

Mechanics of Prolog Terms, Substitution, Unification, Horn Clauses, Proof

process Example: List Processing Theoretical Foundations

Semantics Logic / Theorem Proving … Resolution

Other Issues Search Strategies Declarative/Procedural, ... “Impure'' Operators” --- NOT, ! Utilities

? Constraint Programming ? Bayesian Belief Nets

Page 3: Declarative Programming PROLOG

3

2004 …1990 … 1980

Page 4: Declarative Programming PROLOG

4

Story … MD sees patient … perhaps MENINGITIS!

Performs standard tests Calls Infection Disease (medical) expert

Dialogue: Expert asks for info re: patient

Fever, Organism Morphology, Gram Stain, Spinal Fluid, …

Doctor's answers: DIRECT : from direct measurement, Lab tests Qualitative: Has HIGH fever Vague: Portal of Entry was GastroIntestinal (w/certainty

0.6) Unknown: don’t know identity of organism?

Page 5: Declarative Programming PROLOG

5

Story … con’t MD can ask questions:

Why ask about portal of entry? Expert answers:

trying to show infecting organism is

ENTEROBACTERICAE this information is crucial in that decision.

If further questioned, … point to definitive study

Expert provides DIAGNOSIS organism was one of {E.coli, Enterobacteria } suggest TREATMENT: Give GENTAMICIN

Happily ever after...

Page 6: Declarative Programming PROLOG

6

The Catch …

Expert System

Page 7: Declarative Programming PROLOG

7

Expert System

An EXPERT SYSTEM is a computer program that exhibits Expert Level performance in solving complex problems.

Reasons with Facts about the World:Combines General Facts/Rules (about Diseases, ...)

with Specific Facts (about Patient)

to Produce new Conclusion (diagnosis)

Page 8: Declarative Programming PROLOG

8

Medical Expert Systems

MYCIN Blood Infections

CADUCEUS Internal Medicine

CASNET Glaucoma

Present lllness Program Kidney

Digitalis advisor Erratic Heartbeat

VM Ventilator

Management ALVEN

Ventricle Movement ONCOCIN

Cancer Treatment Protocols

Page 9: Declarative Programming PROLOG

9

Other Domains

Medicine Chemistry Instruction Job-Shop Management Financial Planning Computer Diagnosis, Configuration VLSI Design Molecular Genetics Signal Analysis Structural Mechanics Mathematics …

Page 10: Declarative Programming PROLOG

10

“Declarative Programming''

Knowledge Base--- -- --- ---- --- - -- -

--- - --- ------ -- --- --Facts about the world -- ---- --- ---- ----- -- ----- -- ----- -- --- - -

1

Is true?

ProofProcedure

2

Yes … No

Give Gentamycin?

Page 11: Declarative Programming PROLOG

11

Advantages of Framework

Simply

Information is Modular

Easy to Build Easy to Modify (Extend, Debug) Capable of Explanation

Declarative Re-use same info for different tasks

store “truths”ask for other truths

Page 12: Declarative Programming PROLOG

12

Computers Manipulate SYMBOLS

Numbers 3, 5, ... Addition, Multiplication, ...

Propositions “D1 is an inverter''

“Inverters flip bits''...

Deduction, ...

Page 13: Declarative Programming PROLOG

13

Simple Deduction

Socrates is a man. If Socrates is a man,

Then Socrates is mortal.

Socrates is mortal.

In general…

Page 14: Declarative Programming PROLOG

14

Example of Deduction

Socrates is Mortal(Goal)

RULES FACTSR1: If Socrates is a Man, Then Socrates is Mortal o

o oF1: Socrates is a Man.

o o

Socrates is a Man(New Goal)

R1

Knowledge Base

Page 15: Declarative Programming PROLOG

15

Example of Deduction, #2

Plato is Mortal

RULES FACTSR1: If Plato is a Man, Then Plato is MortalR2: If Plato is a Cat Then Plato is Mortal.R3: If Plato purrs, Then Plato is a Cat.

o oF3: Plato purrs. o o o

Plato is a Man

R1

Plato is a Cat

R2

Plato purrs

R3

Page 16: Declarative Programming PROLOG

16

Example of Deduction, #3

Aristotle is a man

RULES FACTSR2: If Plato is a Cat Then Plato is Mortal. oR9: If Aristotle is a human and Aristotle is male, Then Aristotle is a man o

o oF3: Aristotle is male. oF8: Aristotle is a human o

Aristotle is maleAristotle is a Human

R9

Page 17: Declarative Programming PROLOG

17

Oversimplified Proof Process

1. If Goal = FACT then DONE YES Else …

2. Goal = “Then Part” of Rule R then Goal “If Part” of R

i

i

i+1

else DONE NO

Page 18: Declarative Programming PROLOG

18

Just Manipulating Symbols

Consider claim This is Belgium.

based on “proof” Today is Tuesday. If Today is Tuesday

Then This is Belgium.

This is Belgium

Conclusion is wrong! Conclusion is

ONLY AS TRUE as PREMISES

If Premises true,then Conclusion is.

Not fault of PROOF process

GIGO…

Page 19: Declarative Programming PROLOG

19

Page 20: Declarative Programming PROLOG

20

RulesR1: if (1) You have a Parking Permit & (2) This space is Permit-Parkable, then You can park at this space.

R2: if (1) This space is a Parking Space & (2) Permit-Sign at this space & (3) Current date is Acceptable, then This space is Permit-Parkable.

R3: if (1) Current time is 7am-Midnight & (2) This space is Permit-Parkable, then You can park at this space.

R4: if (1) Current month is Dec-Mar, then Current date is Acceptable.

R5: if (1) Current month is in Apr-Nov & (2) Current day of month is ≤ 15 then Current date is Acceptable.

Page 21: Declarative Programming PROLOG

21

Facts

This space is a Parking Space. You live near this space. You have a Parking Permit. Current month is in Apr-Nov. Current day is Tuesday. Current day of month is ≤ 15. Permit-Sign at this space. You own a car. Your car is >5 years old. Current time is 3am. You have $18.00. ...

Page 22: Declarative Programming PROLOG

22

Inference Graph

You can park at this space

You have a Parking Permit

This space is Permit-Parkable

… Parking Space

Permit-Sign …

Current date is Acceptable

… ≤ 15…Apr-Nov

R1

R2

R5

Page 23: Declarative Programming PROLOG

23

Additional Rules

R1: if (1) You have a Parking Permit & (2) This space is Permit-Parkable, then You can park at this space.

R2: if (1) This space is a Parking Space &

(2) Permit-Sign at this space & (3) Current date is Acceptable, then This space is Permit-Parkable.

R3: if (1) Current time is 7am-Midnight &

(2) This space is Permit-Parkable, then You can park at this space.

R4: if (1) Current month is Dec-Mar, then Current date is Acceptable.

R5: if (1) Current month is in Apr-Nov & (2) Current day of month is ≤ 15 then Current date is Acceptable.

R7: if (1) You live near this space &

(2) You own a car & (3) You apply for a permit, then You have a Parking

Permit.

R8: if (1) You can park at this space

then You can take a car.

Page 24: Declarative Programming PROLOG

24

Inference Graph

You can park at this space

You have a Parking Permit

This space is Permit-Parkable

… Parking Space

Permit-Sign …

Current date is Acceptable

… ≤ 15…Apr-Nov

You can take a car

… live near …

…own a car

… apply for permit

R7

R8

R1

R2

R5

Page 25: Declarative Programming PROLOG

25

Mycin: What is the suspected portal of entry of ORGANISM-1 into this sterile site?

Doctor: WHYMycin: [ie, why is it important to determine the … site?]

[3.0] … to determine which organism(s) to cover …It has already been established that 3.1] site of culture is blood 3.2] organism stain is gram positiveTherefore, if 3.3] portal of entry is g.i. 3.4] locus of infection is Pelvis or Abdomen,Then strongly suggestive evidence (0.9) that therapy should cover enterobacteriaceae.

[Rule 095] . . .

Page 26: Declarative Programming PROLOG

26

Mycin: What is the suspected portal of entry of ORGANISM-1 into this sterile site?

Doctor: WHYMycin: [ie, why is it important to determine the … site?]

[3.0] … to determine which organism(s) to cover …If has already been established that 3.1] site of culture is blood 3.2] organism stain is gram positiveTherefore, if 3.3] portal of entry is g.i. 3.4] locus of infection is Pelvis or Abdomen,Then strongly suggestive evidence (0.9) that therapy should cover enterobacteriaceae.

[Rule 095] . . .

Page 27: Declarative Programming PROLOG

27

Advantage of Rule Transparency

Explain reasoning Support / Credability Helpful when…

building/extending system modifying system

Page 28: Declarative Programming PROLOG

28

Issues

Faster Computation User Interaction

Focus of Attention “Human Engineering”

Variables Control of Search

Which (sub)goal? Which rule?

Page 29: Declarative Programming PROLOG

29

Variables You can park at X

RA

X = SpaceA

X = SpaceB X = ParkingLot-L

RB

RL

RA: if (1) …, then Can park @ SpaceA. o o o

RB: if (1) …, then Can park @ SpaceB. o o o

RL: if (1) …, then Can park @

Lot-L. o o o

Page 30: Declarative Programming PROLOG

30

Control of Search FACTSF1: f( Abe, Bob )F2: f( Bob, Charles )F3: f( Charles, Dave )

RULESR1: a( x, y ) & a( y, z ) a( x, z )R2: f( x, y ) a ( x, y )

a(Abe, Dave)

R1

a(Abe, y2) a(y2, y1) f(Abe, y1)

R2

R1

a(Abe, y3) a(y3, y2) f(Abe, y2)

R2

R1 R2

a(Abe, y1) a( y1, Dave) f(Abe, Dave)

Page 31: Declarative Programming PROLOG

31

Research Issues

Better Decision Making Coping with Uncertainty Better Explanation

“Deeper Knowledge” First Principles “Meta”

Acquiring the Knowledge … from expert … from data