Recap of Lecture 4 and Homework Check
LAST LECTURE · 5 MIN
Agents
PEAS + environment
Agent types
Sensors → agent program → actuators. Rational = best expected performance.
Performance, Environment, Actuators, Sensors. Seven properties.
Reflex → model-based → goal → utility → learning.
Link: a model-based agent needs a model of the world. Today: how to WRITE that knowledge down.
Today's Plan (90 minutes)
ROADMAP
0-5
Recap of Lecture 4 and homework check
S02
5-8
Plan and learning outcomes
S03-S04
8-28
Module 1: Knowledge, knowledge-based agents, types of knowledge
S05-S09
28-38
Module 2: What makes a good representation?
S10-S12
38-56
Module 3: Semantic networks and inheritance (+ Python demo)
S13-S17
56-74
Module 4: Frames and production rules (+ Python demo)
S18-S22
74-84
Class activity: represent UAF Burewala knowledge
S23
84-90
Mistakes, recap quiz, homework
S24-S26
Learning Outcomes (SLOs)
BY THE END OF THIS LECTURE YOU WILL BE ABLE TO
SLO 5.1
Differentiate data, information and knowledge, and describe a knowledge-based agent (TELL / ASK)
→ CLO2 · C2 Understand
SLO 5.2
Classify knowledge as declarative, procedural, meta, heuristic or structural
→ CLO2 · C2 Understand
SLO 5.3
Judge a representation using the four properties of a good KR system
→ CLO2 · C2 Understand
SLO 5.4
Represent knowledge as a semantic network and use inheritance with exceptions
→ CLO2 · C3 Apply
SLO 5.5
Represent knowledge as frames and production rules, and trace forward chaining
→ 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
What Is Knowledge?
Data, information, knowledge - and agents that store and use it
Data, Information and Knowledge
MODULE 1 · KNOWLEDGE
↑ more useful for decisions
Knowledge
Information
Data
Intelligence Needs Knowledge
MODULE 1 · KNOWLEDGE
Voluminous
Hard to describe exactly
Always changing
Very large. All the facts about crops, diseases and medicines.
What is 'a little fever' or 'good soil'?
New crop varieties, new virus strains, new electricity tariffs.
Knowledge-Based Agents: TELL and ASK
MODULE 1 · KNOWLEDGE
Percept
TELL KB: what I see
ASK KB: what should I do?
TELL KB: I did action A
Action
- Knowledge base (KB): a set of sentences (facts and rules) written in a representation language.
- TELL: add a new sentence to the KB.
- ASK: query the KB; the answer is INFERRED (worked out) from what was told.
- Declarative approach: tell the agent what is true; let inference work out what to do.
Example: crop advisor
- TELL: leaves have yellow stripes; weather is cool.
- ASK: which disease?
- KB answers: yellow (stripe) rust of wheat.
Types of Knowledge
MODULE 1 · KNOWLEDGE
Quick rule: declarative = WHAT, procedural = HOW, meta = ABOUT knowledge, heuristic = RULE OF THUMB, structural = RELATIONS.
Slide 10
MODULE 2
What Makes a Good Representation?
Four properties to judge any knowledge representation
Four Properties of a Good KR System
MODULE 2 · GOOD REPRESENTATION
Representational adequacy
Inferential adequacy
- Can it express ALL the knowledge needed?
- Excel cannot easily say 'every crop needs water'.
- Can it derive NEW knowledge from old?
- Cotton is a crop + crops need water → cotton needs water.
Inferential efficiency
Acquisitional efficiency
- Can it derive answers QUICKLY?
- An IS-A hierarchy finds inherited facts fast.
- Can new knowledge be ADDED easily?
- Add a new crop by one IS-A link.
Truth: no single method is best at all four. That is why AI uses several representations.
Main Knowledge Representation Methods
MODULE 2 · GOOD REPRESENTATION
Logic
Semantic networks
Frames
Production rules
- Exact sentences with true/false meaning.
- 'All crops need water.' → L06-L09
- Nodes (concepts) joined by labelled links (IS-A, HAS).
- Google Knowledge Graph
- A record with slots and fillers for a typical object.
- A patient form
- IF conditions THEN action.
- Expert systems (L19)
Today: semantic networks, frames and production rules. Logic gets the next three lectures.
Slide 13
MODULE 3
Semantic Networks
Knowledge as a graph of concepts and relations
A Semantic Network
MODULE 3 · SEMANTIC NETWORKS
breathes
DOES
NEEDS
Animal
Crop
water
IS-A
feathers
IS-A
IS-A
HAS
Bird
Kharif crop
Rabi crop
can fly
CAN
IS-A
IS-A
IS-A
IS-A
Sparrow
Ostrich
Cotton
Wheat
Read it: nodes = concepts; labelled arrows = relations. IS-A always points from the specific to the general.
Inheritance and Exceptions
MODULE 3 · SEMANTIC NETWORKS
Inheritance: store a fact ONCE at the most general level; every specific node below gets it automatically.
Exception rule: the MOST SPECIFIC value wins (Ostrich's 'cannot fly' beats Bird's 'can fly').
Demo: Inheritance in Python
MODULE 3 · SEMANTIC NETWORKS
SEMANTIC NETWORK (FULL CODE: NOTES §3.3)
REAL OUTPUT
- isa = {"Sparrow": "Bird", "Ostrich": "Bird", "Bird": "Animal", ...}
- props = {"Bird": {"can_fly": True, ...},
- "Ostrich": {"can_fly": False}, ...}
- def lookup(node, prop):
- path = [node]
- while node is not None:
- if prop in props.get(node, {}):
- return props[node][prop], path
- node = isa.get(node) # climb IS-A
- if node: path.append(node)
- return None, path
- Sparrow can_fly = True [Sparrow>Bird]
- Ostrich can_fly = False [Ostrich]
- Ostrich breathes = True [Ostrich>Bird>Animal]
- Cotton sown_in = summer (Apr-Jun) [Cotton>Kharif crop]
- Cotton needs_water = True [Cotton>Kharif crop>Crop]
- Wheat product = None [Wheat>Rabi crop>Crop]
Notice: 'Wheat product = None' - a KB knows only what it has been told.
Semantic Networks: Strengths and Weaknesses
MODULE 3 · SEMANTIC NETWORKS
Next: logic gives exact meaning for NOT, OR, ALL and SOME (Lectures 6-7).
Slide 18
MODULE 4
Frames and Production Rules
Records with slots, and IF-THEN knowledge
Frames: Slots and Fillers
MODULE 4 · FRAMES
Like a form
- A hospital admission form: fixed slots, the patient's values. A default fills empty slots.
- In OOP: class = generic frame, object = instance.
Frame: a record for a typical object: slots (attributes) + fillers (values, defaults, procedures).
Frame Hierarchy, Defaults and Instances
MODULE 4 · FRAMES
Student (generic)
BSCS-5th (generic)
Hira (instance)
Inherited: Hira's university (UAF) and campus come from the frames above. Her CGPA is her own.
OOP link: generic frame ≈ class; instance frame ≈ object; inheritance works the same way.
Production Rules and Forward Chaining
MODULE 4 · PRODUCTION RULES
RULES + WORKING MEMORY (FULL CODE: NOTES §4.3)
REAL OUTPUT
- rules = [
- ({"fever","body_ache"}, "viral_infection_possible"),
- ({"viral_infection_possible","dengue_season"},
- "test_for_dengue"),
- ({"test_for_dengue","low_platelets"}, "dengue_suspected"),
- ({"dengue_suspected"}, "refer_to_hospital"),
- ]
- facts = {"fever","body_ache","dengue_season","low_platelets"}
- # repeat: fire every rule whose IF-part is in facts
- Start facts: ['body_ache', 'dengue_season', 'fever', 'low_platelets']
- Cycle 1: IF body_ache AND fever THEN viral_infection_possible
- Cycle 2: IF dengue_season AND viral_infection_possible THEN test_for_dengue
- Cycle 3: IF low_platelets AND test_for_dengue THEN dengue_suspected
- Cycle 4: IF dengue_suspected THEN refer_to_hospital
- Facts in memory now: 8
- Final conclusion: refer_to_hospital
Forward chaining: start from facts, fire rules, add conclusions until nothing new.
Comparing the Representations
MODULE 4 · SUMMARY
Choose by task: relations → semantic net; records → frames; expert IF-THEN advice → rules; exact proof → logic.
Activity: Represent UAF Burewala Knowledge
CLASS ACTIVITY · GROUPS OF 3 · 10 MIN
Groups of 3. Use these facts: 'UAF Burewala is a sub campus of UAF. BSCS is a degree offered at UAF Burewala. Ali is a BSCS student. Every UAF student needs 75% attendance. BSCS students study CS-511.'
Draw a semantic network with at least 5 nodes and IS-A / other links
Write an instance frame for Ali
Using inheritance, answer: does Ali need 75% attendance? Show the path
Write 2 production rules about attendance and exam eligibility
Write a generic frame 'BSCS-Student' with 5 slots (one default)
Classify each fact as declarative, procedural, structural, meta or heuristic
Common Mistakes
WATCH OUT
WRONG IDEA
CORRECT IDEA
✗ Data and knowledge are the same.
✓ Knowledge = information + rules/experience that can be used to decide.
✗ IS-A arrows point from general to specific.
✓ IS-A points from the specific (Sparrow) to the general (Bird).
✗ Every fact must be stored at every node.
✓ Store it once at the most general level; inheritance passes it down.
✗ A default value can never change.
✓ A default is used only until a specific value overrides it (ostrich).
✗ Forward chaining starts from the goal.
✓ Forward chaining starts from FACTS; backward chaining starts from the goal.
Recap Quiz
CHECK YOUR UNDERSTANDING · 5 MIN
- Q1. 'Patient's temperature is 38 °C' is an example of:
- (a) Data (b) Information (c) Wisdom (d) Meta-knowledge
- Q2. Knowing HOW to mix a spray is:
- (a) Declarative (b) Procedural (c) Meta (d) Structural
- Q3. 'Can the KR derive new facts from old ones?' is:
- (a) Representational adequacy (b) Inferential adequacy (c) Acquisitional efficiency (d) Heuristic
- Q4. Cotton IS-A Kharif crop IS-A Crop; Crop needs water. Cotton needs water by:
- (a) Exception (b) Inheritance (c) Default (d) Forward chaining
- Q5. In a frame, a value used when nothing else is known is a:
- (a) Slot (b) Default (c) Instance (d) Rule
- Q6. Firing rules from known facts until nothing new is added is:
- (a) Backward chaining (b) Forward chaining (c) Inheritance (d) Search
Homework and Next Lecture
BEFORE THE NEXT CLASS
- Task 1: Draw a semantic network for 'vehicles': Car, Bus, Rickshaw, Motorbike, Vehicle, Engine, Wheels - with IS-A and HAS links. Add one exception.
- Task 2: Write a generic frame 'Mobile Phone' (6 slots, 2 defaults) and an instance frame for your own phone.
- Task 3: Write 4 production rules for a simple tubewell controller (soil moisture, rain forecast, load-shedding) and trace forward chaining for one case.
- Read: Kaplan Ch 2; Luger Ch 7.
NEXT LECTURE
- Lecture 6:
- Propositional Logic