Beruflich Dokumente
Kultur Dokumente
• Knowledge Manipulation:
– Forward & Backward Chaining
– Deduction & Reaction Systems
• Variables: ?x,?y,?z
– Same name => same value
Knowledge Manipulation
• Forward chaining:
– Reason from “if” antecedents to “then” consequents
• Backward chaining:
– Confirm hypothesis matching “then” patterns by
verifying “if” patterns
Rule-based Systems
• Separate knowledge from control
– Contrast from typical programming: Integrated
Add
consequent
Rule
Assertions Interpreter Rules
Select rule
Match antecedent
Forward Chaining
• Identify triggered rules
– Antecedents match assertions
– Match variables -> rule instances
• Select a triggered rule to fire
– Conflict resolution strategy: first, random, LRU,
combination
• Fire a rule
– Add consequents to list of assertions (deduction)
– Perform action(s) in consequent (reaction)
Forward Chaining Example
R1: if (signs (nasal congestion)) R4: if (temp >100)
(signs (viremia)) then (signs (fever))
then (diagnosis influenza) R5: if (headache)
R2: if (runny nose) then (signs (achiness))
then (signs (nasal congestion)) R6: if (signs (fever))
R3: if (body-aches) (signs (achiness))
then (signs (achiness)) (cough)
Assertions: then (signs (viremia))
F1: runny nose Execution:
F2: temp = 101.5
F3: headache R2 Fires: Asserts (signs (nasal congestion))
R4 Fires: Asserts (signs (fever))
R5 Fires: Asserts (signs (achiness))
R6 Fires: Asserts (signs (viremia))
R1 Fires: Asserts (diagnosis influenza)
Forward Chaining with variables
IF (parent ?x ?y) (parent A B)
(parent ?y ?z) (parent A C)
THEN (grand-parent ?x ?z) (parent B D)
(parent C E)
(parent ?x ?y) (parent ?y ?z) (grand-parent ?x ?z)
Diagnosis Influenza
AND
(Signs (nasal congestion)) (Signs (viremia)
AND
(Runny nose) (Signs (fever)) (Signs (achiness))(cough)
Ask
OR Ask
Yes
(Temp > 100) Yes
Ask
Yes (Body-ache) (Headache)
Ask Ask
No Yes
Reaction Systems
• Deduction systems
– Produce new assertions
– Keep firing all triggered rules
• Order less important
• Reaction systems
– Produce arbitrary actions: assertions, printing,
moving, bagging
– Side effects -> Order important
Reaction System: Example
• For example,
IF (at ?x ?y)
(move ?x to ?z)
ADD (at ?x ?z)
DELETE (move ?x to ?z)
(at ?x ?y)
• Assume an initial database:
– (at A room1) (move A room2)
• Then the rule would add: (at A room2)
• And, delete:
– (at A room1) (move A room2)
Conflict Resolution
• When >1 rule is triggered, which fires??
• First: Rules are ordered. Fire first triggered.
• Random: Randomly select a rule to fire
• Most specific: Fire rule with most antecedents
• Least recently fired: Avoids rule starvation.
– Combination
• Design rule set wrt conflict resolution strategy
Conflict Resolution: Deduction
• Generally, less important,but
• Possible to create infinitely recursive rule
– if ?x, (not (not ?x))….
• Need conflict resolution
– Allow other rules to fire
• E.g. stop rule