Artificial IntelligenceUnit 87 min read
Expert Systems & Fuzzy Logic: Rules, Uncertainty & Real-World AI
Unit 8 of Artificial Intelligence covers expert systems (architecture, rule-based reasoning, inference engines) and fuzzy logic (membership functions, fuzzy rules, defuzzification) with Nepalese and global applications like loan approvals, traffic control, and medical diagnosis.
Core Concepts
Expert Systems: The Digital Consultant
Definition: An expert system is a rule-based AI program that mimics human expertise in a narrow domain (e.g., medicine, finance) by combining:
- A knowledge base (facts + rules)
- An inference engine (reasoning logic)
- A user interface (question/answer)
classDiagram
class ExpertSystem {
+KnowledgeBase
+InferenceEngine
+UserInterface
}
class KnowledgeBase {
+Facts
+Rules
}
class InferenceEngine {
+ForwardChaining
+BackwardChaining
}
ExpertSystem --> KnowledgeBase : contains
ExpertSystem --> InferenceEngine : uses
ExpertSystem --> UserInterface : interactsHow It Works:
- Knowledge Acquisition: Experts encode their expertise as rules (IF-THEN statements).
- Inference: The engine applies rules to facts to deduce new conclusions.
- Explanation: Justifies its reasoning (critical for trust).
Example: Loan Approval System (like Nepal’s NMB Bank)
- Rule:
IF (income > 50k AND credit_score > 700) THEN approve_loan(YES) - Facts:
income = 60k, credit_score = 750 - Inference: Engine fires the rule →
approve_loan(YES)
Fuzzy Logic: Handling the Gray Areas
Definition: A mathematical framework to represent uncertainty where truth values range between 0 (false) and 1 (true), unlike binary logic (0/1). Used when data is imprecise (e.g., "tall," "hot").
Membership Functions: The Heart of Fuzzy Logic
For a fuzzy set Height = {short, medium, tall} over domain X = {150, 160, 170, 180, 190}:
- Short: Membership increases linearly from 150 (0) to 170 (1).
- Medium: Overlaps with "short" and "tall" (e.g., 170 = 0.5 for medium).
- Tall: Membership increases from 170 (0) to 190 (1).
Worked Example: Air Conditioner Temperature Control
- Fuzzy Sets:
Cold = {20-24°C},Comfortable = {22-26°C},Hot = {24-30°C} - Rule:
IF temperature IS Hot THEN set_fan_speed(High) - Input: 28°C → Membership in
Hot= 0.8,Comfortable= 0.2 - Defuzzification: Combine outputs (e.g., weighted average) →
fan_speed = 75%
In the Real World
eSewa (Nepal):
- Expert System: Uses rule-based logic to validate bill payments (e.g.,
IF (meter_number IN database AND amount > 0) THEN process_payment). - Fuzzy Logic: Adjusts "congestion fees" for delayed payments based on vague rules like "slightly late" (1–3 days) vs. "very late" (>7 days).
- Expert System: Uses rule-based logic to validate bill payments (e.g.,
Pathao (Ride-Hailing):
- Dynamic Rule Base: Adjusts surge pricing using fuzzy logic for demand (e.g.,
IF (wait_time > 10 mins AND drivers < 5) THEN surge_multiplier = 1.5).
- Dynamic Rule Base: Adjusts surge pricing using fuzzy logic for demand (e.g.,
NTC Traffic Management:
- Fuzzy Controller: Regulates traffic lights at busy intersections using rules like:
IF (car_queue > 20 AND pedestrian_queue = 0) THEN green_light_duration = 45s.
- Fuzzy Controller: Regulates traffic lights at busy intersections using rules like:
Development Phases of an Expert System
flowchart LR
A["Identify Domain"] --> B["Knowledge Acquisition"]
B --> C["Knowledge Representation"]
C --> D["Design Inference Engine"]
D --> E["Build User Interface"]
E --> F["Testing & Validation"]
F --> G["Deployment & Maintenance"]Key Steps:
- Domain Identification: Narrow the scope (e.g., "diabetes diagnosis" vs. "general medicine").
- Knowledge Acquisition: Interview experts or extract rules from data.
- Knowledge Representation: Use production rules (IF-THEN), semantic networks, or frames.
- Inference Engine: Choose forward (data-driven) or backward (goal-driven) chaining.
- Validation: Test with real-world cases (e.g., 100 patient records for a medical system).
Comparison: Rule-Based vs. Machine Learning
| Feature | Rule-Based Systems | Machine Learning |
|---|---|---|
| Data Requirement | Needs explicit rules | Needs labeled data |
| Explainability | High (rules are transparent) | Low (black-box models) |
| Adaptability | Static (rules must be updated) | Dynamic (learns from new data) |
| Example | Loan approval, medical diagnosis | Fraud detection, image recognition |
When to Use Rule-Based:
- Static Environments: Tax calculation, grammar checkers.
- High Stakes: Medical diagnosis (explainability matters).
- Limited Data: Few examples but clear rules.
When to Use ML:
- Dynamic Environments: Stock trading, social media trends.
- Unstructured Data: Images, text (NLP).
Fuzzy Logic Operators
Fuzzy logic extends Boolean operators (AND, OR, NOT) to handle partial truths:
- AND:
min(a, b) - OR:
max(a, b) - NOT:
1 - a
Example: Washing Machine Logic
- Rule:
IF (dirt_level = High AND water_hardness = Medium) THEN detergent_amount = 70% - Calculation:
dirt_level = 0.9,water_hardness = 0.6ANDresult =min(0.9, 0.6) = 0.6detergent_amount = 0.6 * 100% = 60%(rounded to 70% per rule).
Worked Example: Covid-19 Vaccine Recommender (PEAS Framework)
Performance: Recommend vaccines based on age, health conditions, and side effects. Environment: Dynamic (new variants, drug interactions). Actuators: Database queries, user alerts. Sensors: Patient records, CDC guidelines.
flowchart TD
A["Patient Data"] --> B["Rule Base"]
B --> C["Inference Engine"]
C --> D["Recommendation"]
D --> E["User Alert"]
B -->|"Example Rule"| F["IF (age > 65 AND has_heart_condition) THEN recommend_Pfizer"]Fuzzy Rule Example:
- Rule:
IF (risk_level = High AND mobility = Low) THEN priority = Urgent - Membership:
risk_level = 0.8(from symptoms + age)mobility = 0.3(uses wheelchair)ANDresult =min(0.8, 0.3) = 0.3- Defuzzification: Combine with other rules →
priority = "High".
Exam Tip
Define Clearly:
- Expert system = "AI system that encodes human expertise as rules."
- Fuzzy logic = "Logic that handles partial truth values (0–1)."
Draw Diagrams:
- Always sketch a rule-based system flowchart (knowledge base → inference engine → output).
- For fuzzy logic, plot membership functions (triangular/trapezoidal).
Link to Nepal:
- eSewa: Rule-based for bill validation.
- NTC Traffic: Fuzzy logic for signal timing.
- Banks: Loan approval rules (e.g.,
IF (income < 30k AND loan > 2M) THEN reject).
Common Pitfalls:
- Forgetting to defuzzify (convert fuzzy outputs to crisp actions).
- Confusing forward chaining (data → conclusion) with backward chaining (goal → data).
Past Exam Patterns:
- 20%: Define + example (e.g., "Expert system for Covid prediction").
- 30%: Design a rule base or fuzzy set (use realistic domains like traffic or loans).
- 25%: PEAS framework (describe performance, environment, actuators, sensors).
- 25%: Convert sentences to FOPL (First-Order Predicate Logic) or explain inference.
Based on the TU BSc CSIT syllabus for Artificial Intelligence (CSC266), unit 8.
Discussion
Loading…