Recap of Lecture 18 and Homework Check
LAST LECTURE · 5 MIN
Today: how do we put a wheat specialist's knowledge into a computer so a farmer in Burewala can ask it for advice?
Today's Plan (50 minutes)
ROADMAP
0-5
Recap of Lecture 18 and homework check
S02
5-8
Plan and learning outcomes
S03-S04
8-16
Module 1: What an expert system is and how it is built
S05-S08
16-28
Module 2: Forward and backward chaining on Gandum Doctor
S09-S13
28-35
Module 3: Conflict resolution, certainty factors, strengths and limits
S14-S17
35-43
Class activity: run the expert system by hand
S18
43-48
Common mistakes and recap quiz
S19-S20
48-50
Homework and next lecture
S21
Learning Outcomes (SLOs)
BY THE END OF THIS LECTURE YOU WILL BE ABLE TO
SLO 19.1
Explain what an expert system is and the role of each component (knowledge base, inference engine, working memory, explanation)
→ CLO2 · C2 Understand
SLO 19.2
Apply forward and backward chaining to a rule base and trace the reasoning
→ CLO2 · C3 Apply
SLO 19.3
Apply conflict resolution and certainty factors, and explain the limits of rule-based systems
→ CLO2 · C3 Apply
- Course Learning Outcome(s) served
- CLO2: Demonstrate first-order predicate calculus, logical reasoning and problem-solving using Prolog language.
Slide 5
MODULE 1
Expert Systems
A specialist's knowledge in a program
What Is an Expert System?
MODULE 1 · DEFINITION
DENDRAL (1965)
MYCIN (1970s)
XCON (1980)
Chemistry: worked out the structure of molecules from lab data.
Medicine: about 600 rules to choose antibiotics; gave reasons and certainty.
Business: configured computer orders for DEC; saved millions a year.
Definition: a program that gives expert-level advice in ONE narrow area, using knowledge stored as IF-THEN rules.
Today: loan approval, insurance claims, tax software, crop-advice apps - rule engines are everywhere.
Inside an Expert System
MODULE 1 · ARCHITECTURE
- Working memory
- (facts of this case)
Inference engine
- User
- (farmer)
User interface
- Knowledge base
- (IF-THEN rules)
- Explanation
- (WHY / HOW)
- Knowledge engineer
- + domain expert
Key idea: knowledge (rules) is kept separate from the reasoning program - add rules without rewriting code. Engine + interface with no rules = a SHELL (CLIPS, Drools).
Who Builds It? Knowledge Acquisition
MODULE 1 · PEOPLE AND PROCESS
Domain expert
Knowledge engineer
User
Knows the subject: e.g. a plant pathologist (disease specialist) at UAF.
Interviews the expert, studies cases, writes and tests the rules.
Farmer or field assistant who answers questions and gets advice.
Bottleneck: experts often cannot explain how they know - getting rules out of their heads is the slowest step.
Slide 9
MODULE 2
Reasoning with Rules
Forward and backward chaining
The Gandum Doctor Rule Base
MODULE 2 · KNOWLEDGE BASE
Simplified rules for teaching - not agronomic advice.
Forward Chaining: From Facts to Advice
MODULE 2 · DATA-DRIVEN
REAL OUTPUT: L19/FORWARD.PY
- Farmer reports: yellow_stripes_on_leaves, powder_on_stripes
- cool_humid_weather, before_flowering
- Cycle 1: conflict set {R1} -> fire R1: stripe_rust_suspected
- Cycle 2: conflict set {R3} -> fire R3: stripe_rust
- Cycle 3: conflict set {R6} -> fire R6: rust_disease
- Cycle 4: conflict set {R8} -> fire R8: advise_fungicide_spray
- Advice: ['advise_fungicide_spray']
EXPLANATION FACILITY: HOW DID YOU REACH THIS ADVICE?
- HOW? (explanation)
- advise_fungicide_spray <- R8 because rust_disease AND before_flowering
- rust_disease <- R6 because stripe_rust
- stripe_rust <- R3 because stripe_rust_suspected AND cool_humid_weather
- stripe_rust_suspected <- R1 because yellow_stripes_on_leaves AND powder_on_stripes
- yellow_stripes_on_leaves (told by the farmer)
- powder_on_stripes (told by the farmer)
- cool_humid_weather (told by the farmer)
- before_flowering (told by the farmer)
Backward Chaining: From a Goal to Questions
MODULE 2 · GOAL-DRIVEN
REAL OUTPUT: L19/BACKWARD.PY (FARMER 2: LEAF RUST)
- Goal advise_fungicide_spray: try R8
- Goal rust_disease: try R6
- Goal stripe_rust: try R3
- Goal stripe_rust_suspected: try R1
- ASK: yellow stripes on leaves? no
- stripe_rust_suspected cannot be proved
- stripe_rust cannot be proved
- Goal rust_disease: try R7
- Goal leaf_rust: try R4
- Goal leaf_rust_suspected: try R2
- ASK: orange brown spots? yes
- ASK: spots scattered? yes
- R2 proves leaf_rust_suspected
- ASK: warm humid weather? yes
- R4 proves leaf_rust
- R7 proves rust_disease
- ASK: before flowering? yes
- R8 proves advise_fungicide_spray
- Goal advise_fungicide_spray: PROVED
- Questions asked: 5 of 8 askable facts
Start from the goal
Find rules that conclude it; prove their conditions as sub-goals.
Ask only what is needed
5 of 8 possible questions; never asks about black powder.
Backtrack
Stripe-rust chain fails - try the leaf-rust chain. Same as Prolog (L09).
Forward or Backward?
MODULE 2 · COMPARISON
Remember: forward = 'what follows from what I know?' · backward = 'is this goal true? what do I need to ask?'
Slide 14
MODULE 3
Making Rules Practical
Conflicts, uncertainty and limits
Conflict Resolution: Which Rule Fires First?
MODULE 3 · CONFLICT SET
REAL OUTPUT: L19/CONFLICT.PY
THREE RULES ALL MATCH (P = PRIORITY)
- Facts, oldest first:
- yellow_leaves, stripes, powder, cool_humid_weather
- order first: fire G1: nitrogen_deficiency
- specificity first: fire S1: stripe_rust
- priority first: fire S1: stripe_rust
- recency first: fire W1: rust_risk_high
- G1: IF yellow_leaves
- THEN nitrogen_deficiency [p 1]
- S1: IF yellow_leaves AND stripes AND powder
- THEN stripe_rust [p 3]
- W1: IF cool_humid_weather
- THEN rust_risk_high [p 2]
Certainty Factors: Rules That Are Not 100% Sure
MODULE 3 · UNCERTAINTY
REAL OUTPUT: L19/CF.PY
- R1 (CF 0.7): yellow stripes 0.9 AND powder 0.8 -> stripe rust CF = 0.7 x min(0.9, 0.8) = 0.56
- R2 (CF 0.6): lab spore test positive 1.0 -> stripe rust CF = 0.60
- Combined: 0.56 + 0.60 x (1 - 0.56) = 0.824
- Order does not matter: 0.824
Scale: CF from -1 (certainly false) through 0 (unknown) to +1 (certainly true). Next lecture: probability does this exactly.
Strengths and Limits of Expert Systems
MODULE 3 · EVALUATION
Strengths
Limits
Available any time and anywhere · consistent · explains WHY and HOW · rules easy to read and update · keeps knowledge when experts retire
Knowledge acquisition bottleneck · brittle outside its narrow area · no common sense · does not learn by itself · big rule bases are hard to maintain
Brittle: ask Gandum Doctor about a new disease it has no rules for, and it can only say 'no advice' - or worse, give wrong advice.
Coming up: decision trees (L25) LEARN IF-THEN rules from data instead of interviewing an expert.
Activity: Run Gandum Doctor by Hand
CLASS ACTIVITY · PAIRS · 8 MIN
Pairs, 6 min + 2 min check. Use the rule base on S10.
Forward-chain from: black powder in ears. Cycles and advice?
Backward-chain the goal 'advise treated seed'. How many questions are asked?
Forward-chain from: orange-brown spots, spots scattered, warm humid weather. Advice?
Forward or backward? (a) factory alarms from sensors (b) 'does this patient have dengue?'
Rule CF 0.8; premises 0.7 AND 0.9. CF? Then combine with another rule's 0.5.
Which component: (a) stores this farmer's facts (b) answers 'why do you ask?'
Common Mistakes
WATCH OUT
WRONG IDEA
CORRECT IDEA
✗ The inference engine contains the rules.
✓ Rules are in the knowledge base; the engine only applies them.
✗ Forward chaining starts from the goal.
✓ Forward starts from facts; backward starts from the goal.
✗ Backward chaining asks every question.
✓ It asks only what the goal needs (5 of 8 questions).
✗ Combine CFs by adding: 0.56 + 0.6 = 1.16.
✓ a + b(1 - a) = 0.824 - never above 1.
✗ An expert system learns from its mistakes.
✓ It does not learn by itself; people add and fix rules.
Recap Quiz
CHECK YOUR UNDERSTANDING · 3 MIN
- Q1. The part that stores the facts of the current case is the:
- (a) Knowledge base (b) Working memory (c) Inference engine (d) User interface
- Q2. Diagnosis ('is it leaf rust?') usually uses:
- (a) Forward chaining (b) Backward chaining (c) Alpha-beta (d) Hill climbing
- Q3. Rule CF 0.7, premises 0.9 and 0.8. Conclusion CF:
- (a) 0.56 (b) 0.63 (c) 0.70 (d) 2.40
- Q4. Picking the matching rule with the most conditions is:
- (a) Recency (b) Specificity (c) Refractoriness (d) Order
Homework and Next Lecture
BEFORE THE NEXT CLASS
- Task 1: Add two rules for aphids (chepa): R10 IF small green insects on ears AND sticky leaves THEN aphid attack; R11 IF aphid attack AND many insects per tiller THEN advise insecticide. Forward-chain from all three facts.
- Task 2: Backward-chain 'advise fungicide spray' for a farmer who says: yellow stripes yes, powder yes, cool humid weather no, orange-brown spots no. List the questions in order. Proved?
- Task 3: Three rules support the same disease with CF 0.4, 0.5 and 0.3. Combine them.
NEXT LECTURE
- Lecture 20:
- Probabilistic Reasoning and Bayes' Rule