Docsity

Knowledge Representation and Reasoning: Rules and Forward Chaining, Exams of Computer Science

Toggle sidebar
bg1
Two things must be done:
Representation Reasoning Technique
Knowledge Representation and Reasoning
•
•
Rules
Semantic Networks
Frames
Knowledge Representation and Reasoning (cont.)
•Which language do we use to solve
programming problems?
•Depends on the application
•Think about the knowledge structure first
•Remember that representations are just a tool
•Any tool can be used badly
•examine each method
•talk about typical use
•talk about typical problems
Which one do we use?
What will we do?
pf3
pf4
pf5
pf8
pf9
pfa
pfd

Partial preview of the text

Download Knowledge Representation and Reasoning: Rules and Forward Chaining and more Exams Computer Science in PDF only on Docsity!

Two things must be done:

Representation Reasoning Technique

Knowledge Representation and Reasoning

Rules

Semantic Networks

Frames

Knowledge Representation and Reasoning (cont.)

• Which language do we use to solve

programming problems?

• Depends on the application

• Think about the knowledge structure first

• Remember that representations are just a tool

• Any tool can be used badly

• examine each method

• talk about typical use

• talk about typical problems

Which one do we use?

What will we do?

Formal method for representing:

Are often appropriate when:

Rules

Rules - Expressing Knowledge

• Situation/Action:

if temp>300 degrees C

then turn off the boiler

• Premise/Conclusion:

if stain is grampos

then organism is strep

• Antecedent/Consequent:

if X is a dog

then X is an animal

Expression of knowledge in an IF-THEN format:

Data Directed (Forward) Reasoning

RULES:

if A then B

if C then D

if B or E then F

if F and G then H

if F and not I then K

FACTS:

A P G Y E

D

A

C

B

F

G

K

H

E

~I

Forward Chaining

General

Domain

Knowledge

Rule Base

Specific

Domain

Knowledge

Fact Base

Inference

Mechanism

Inference Schemes:

Example

P1: if X then 1.

P2: if 1.1. then 2.

P3: if 2.1. then 3.

P4: if 2.2. then 4.

P5: if 3.1. then 4.

P6: if 3.2. then 5.

1. Find all productions whose conditions are true and mark

them applicable

2. If more than one production is applicable, then

deactivate all but the lowest numbered

3. Execute that production. If none are applicable, then

quit

4. Reset the applicability of all productions and return to 1

Rules:

Interpreter

P1: if X then 1. Database Rules

P2: if 1.1. then 2.

P3: if 2.1. then 3.

P4: if 2.2. then 4.

P5: if 3.1. then 4.

P6: if 3.2. then 5.

Execution:

2nd Example - Execution

Context List Applicable Rules

(green, weighs 15 lbs)

Inference Chains

small

container

delicacy

green

refrigerated produce 15 lbs meat

perishable watermelon

turkey

R

R

R

R

R

R

staple

inexpensive ~perishable

Problems with Forward Chaining

Forward Reasoning

forward

execute-rule

eval-rule-f

member derive-new-fact?

member display-results

Code for Forward Reasoning (cont.)

;;; DERIVE-NEW-FACT? determines if new facts are being

;;; derived for a list of facts

(defun derive-new-fact? (facts)

(let (new-fact?)

(loop

cond ((null facts) (return new-fact?))

((member (car facts) fact-list :test #'equal))

(t (display-results (car facts))

(setq fact-list (cons (car facts) fact-list))

(setq new-fact? t)) )

(setq facts (cdr facts)) )))

Code for Forward Reasoning (cont.)

;;; EVAL-RULE-F examines a single rule to see if it can

;;; successfully fire

(defun eval-rule-f (rule)

(let ((ifs (caddr rule)) (thens (caddr (cddr rule))))

(loop

(cond ((null ifs)

(return (derive-new-fact? thens)))

((member (car ifs) fact-list :test #'equal)

(setq ifs (cdr ifs)))

(t (return nil)) )) ))

Code for Forward Reasoning (cont.)

;;; DISPLAY-RESULTS displays the derived rules for a

;;; particular fact

(defun display-results (derived-fact)

(terpri)

(princ "The value of ")

(princ (cadr derived-fact))

(princ " is ")

(princ (caddr derived-fact))

(terpri) )

Fruit Knowledge Base

Shape = long = round = oblong

Diameter > 4” < 4”

Surface = smooth = rough

Color = green = yellow = tan = orange = red = purple

Seedcount > 1 = 1

Fruit = banana

Fruitclass = vine

Fruitclass = tree

Seedclass = multiple = stonefruit

Fruit = watermelon = honeydew = cantaloupe

= apple = apricot = cherry = peach = plum = orange

Sample Facts

(setq fact-list

'((is color red)

(is shape round)

(= seedcount 1)

(< diameter 4)

What is the result

from execution?

Fruit Knowledge Base

Shape = long = round = oblong

Diameter > 4” < 4”

Surface = smooth = rough

Color = green = yellow = tan = orange = red = purple

Seedcount > 1 = 1

Fruit = banana

Fruitclass = vine

Fruitclass = tree

Seedclass = multiple = stonefruit

Fruit = watermelon = honeydew = cantaloupe

= apple = apricot = cherry = peach = plum = orange