Artificial Intelligence Theory - Final Exam Preparation Notes
Note: This document compiles all concepts, notes, formulas, and examples extracted precisely from the provided material, specifically targeting AI domains.
1. Logical Agents & Wumpus World Problem
Logical Agents
Definition: Logical agents are more intelligent than previous agents. Previous agents only worked on existing knowledge, but logical agents can perform Logical Reasoning on existing knowledge and can also infer new knowledge.
Knowledge Base (KB): Acts as a database or data store based on a proportion/form of sentences. Later on, the agent extracts data, draws conclusions, and creates results.
Agent Architecture & Interaction with KB
The system interacts using specific commands: TELL and ASK.
- Sensors: Update the Knowledge Base with environment percepts.
- Reasoning Module (Inference Engine): Takes the updated knowledge, reasons, and maps it to Actions.
- Actuators: Execute the actions in the environment.
Commands to Interact with KB
- TELL: Provide input / add something to the KB (e.g., "KB me koi cheez add krni hai").
- ASK: Query the KB.
Execution Sequence of Logical Agent:
- Percept: Read the current environment percept.
- Ask: Ask the KB what action to take now against the sequence.
- Reasoning: Reason on the provided list of actions.
- Tell: Tell the KB that a certain action is to be performed.
The Wumpus World Problem
The Wumpus World is an environment (story description) with rules, primarily formatted as a 4x4 matrix of rooms.
- Characteristics: Fully observable, deterministic, static.
- Agent Capability: The agent carries a single arrow.
- Elements / Entities:
- Wumpus: A monster. Emits a Stench in surrounding rooms.
- Pit: Emits a Breeze in surrounding rooms.
- Gold: The goal object. Emits a Glitter.
Wumpus World 4x4 Grid Representation
Breeze
(Pit nearby)
Breeze
Breeze
Pit
Breeze
Pit
Breeze
Breeze
Stench, Breeze
Gold (Glitter),
Stench, Breeze
Stench
Agent Start
(1,1)
Stench
Wumpus
Monster
Propositional Logic Checks for Wumpus World:
Rules defined for mapping relations between adjacent blocks based on percepts (e.g., B = Breeze, P = Pit):
R1 : ¬P11 (No pit in starting room 1,1)
R2 : B11 ⇔ (P12 ∨ P21) (Breeze in 1,1 means Pit in 1,2 or 2,1)
R3 : B21 ⇔ (P11 ∨ P22 ∨ P31) (Breeze in 2,1 implies pits in adjacent squares)
R4 : ¬B11 (Example observation)
R5 : B21 (Example observation)
2. Propositional Logic
Limitations of Propositional Logic: It lacks quantification and relationship indication between two objects, which leads to the necessity of Predicate/First-Order Logic.
Core Definitions
- Syntax: Way of writing; ensures the sentence is valid according to the language.
- Semantics: Meaningful sentence; evaluates to True (T) or False (F).
- Model: Possible values per sentence to evaluate. Leads to Satisfaction.
Entailment
Represented as: α ⊨ β
Meaning: α, β are sentences. If α is true, then β is true. "Aspects of the real world follows aspect of the real world." Sentences entail sentences.
Sentences & Operator Precedence
A statement is either true or false (uses different symbols). A sentence can be Simple or Complex (uses two or more logical connectives).
Precedence Order: ¬ (Not) , ∧ (Conjunction/AND) , ∨ (Disjunction/OR) , ⇒ (Implication) , ⇔ (Biconditional)
3. Predicate Logic / First Order Logic (FOL)
First-Order logic implements logical agents with broader definitions compared to Propositional logic.
Components of FOL
- Objects: Predicate is itself an object through which we can pass a parameter.
- Relations: Any type of relation between objects or predicates.
- Predicate: e.g.,
Human(X). Does not return an object(value). It maps on a noun/object and returns a truth value (True or False).
- Function: e.g.,
Age(Ali). It returns a value/object, not True or False.
- Constant: Name, numeric value (e.g., Ahmed, 12). Values passed directly.
- Variable: Parameters passed (e.g., X, Y) to supply values directly to the predicate.
- Connectors: Logical Operators (NOT, OR, AND, etc.).
- Equality (=): Compares if 2 predicates return the same result.
Quantifiers
Quantifiers define how many values hold the result True/False.
| Symbol |
Name |
Meaning |
| ∀ |
Universal Quantifier |
For all / Everyone |
| ∃ |
Existential Quantifier |
Some / Exists / Someone |
Rules of Quantifiers
∀x ∀y = ∀y ∀x
∃x ∃y = ∃y ∃x
∃x ∀y ≠ ∀x ∃y
Predicate Logic Examples
Here are several statements translated into First-Order Logic based on the course notes:
| English Sentence |
First-Order Logic (FOL) Representation |
| Ali is a teacher. |
Teacher(Ali) |
| All teachers are human. |
∀x (Teacher(x) ⇒ Human(x)) |
| Everyone is a friend of someone. |
∀x ∃y isFriend(x, y) |
| Brothers are siblings. |
∀x ∀y (Brother(x, y) ⇒ Siblings(x, y)) |
| One's mother is one female parent. |
∀x ∀y (Mother(x, y) ⇒ (Parent(x, y) ∧ Female(x))) |
| Everyone at UET is hardworking. |
∀x (UET(x) ⇒ Hardworking(x)) |
| Someone at UET is hardworking. |
∃x (UET(x) ⇒ Hardworking(x)) |
| Everyone likes ice cream. |
∀x Likes(x, icecream) |
| There is someone who doesn't like ice cream. |
∃x ¬Likes(x, icecream) |
| Deans are professors. |
∀x (Dean(x) ⇒ Professor(x)) |
4. Fuzzy Logic
Definition: Fuzzy logic is a form of logic based on probabilistic talk rather than true/false absolutes. While Binary Logic has strict outcomes of either 0 or 1, Fuzzy Logic outcomes lie in a continuous range: [0 - 1].
The Problem with Binary Logic (True Predicate):
- If speed limit is defined as:
Fast > 30 and Slow <= 30
- In Binary:
isFast(60) -> 1 (True)
- In Binary:
isFast(59.9) -> 0 (False - which creates a logical fallacy for continuous real-world data).
- This is a "false logic" control. Fuzzy logic improves this transition by providing a degree of membership.
Fuzzy Logic Degree Examples
Example 1: Height (Tall)
1 ← if Height ≥ 6.0 feet
0 ← if Height ≤ 5.8 feet
- Degree Formula for transitions:
degree ← (6.0 - X) / 0.4
- Calculation Example for Height = 5.10:
(6.0 - 5.10) / 0.4 = 0.5 (50% chance/degree)
Example 2: Transition Improvement (Speed)
degree = (60 - X) / 10
- If X = 55:
(60 - 55) / 10 = 5 / 10 = 0.5
Fuzzy Logic Operations
Fuzzy operations map to specific mathematical functions based on their input matrices:
- Negation (NOT A):
¬A = (1 - A)
- Intersection (A AND B):
min(A, B) (Selects the minimum value / Bottom shaded region in graph)
- Union (A OR B):
max(A, B) (Selects the maximum value / Top peaks shaded in graph)
Fuzzy Operations Truth / Value Table
| A |
B |
NOT A (1 - A) |
A AND B min(A,B) |
A OR B max(A,B) |
| 0 |
- |
1 |
- |
- |
| 0.1 |
0.3 |
0.9 |
0.1 |
0.3 |
| 0.5 |
0.2 |
0.5 |
0.2 |
0.5 |
| 0.4 |
0.8 |
0.6 |
0.4 |
0.8 |
| 0.7 |
0.3 |
0.3 |
0.3 |
0.7 |
Fuzzy Logic Membership Functions (Temperature Example)
Membership functions determine the degree (μ) to which an input belongs to a category (e.g., Cold, Warm, Hot).
- Cold: Peaks at lower temperatures. As temp rises, membership drops to 0.0.
- Warm (μ=1.0): Peaks perfectly at moderate temperatures (e.g., 25°C). Overlaps with Cold and Hot.
- Hot (μ=0.0): Starts at 0.0 during warm temperatures and peaks at higher values (e.g., 40°C+).
5. Decision Tree (ID3 Algorithm)
Purpose: Used for Classification purposes. It builds a model to predict the class of an object based on learned decision rules.
Structure:
- Root Node: The most important feature/attribute containing the highest Information Gain.
- Internal Nodes: Conditions or attributes being tested.
- Leaf Nodes: The final Decision (e.g., YES or NO).
"Play Tennis" Classic Example Structure
[ROOT NODE: ATTRIBUTE: OUTLOOK]
↙ ↓ ↘
SUNNY OVERCAST RAIN
(If Sunny) → [ATTRIBUTE: HUMIDITY] → High (NO) / Normal (YES)
(If Overcast) → [DECISION: YES]
(If Rain) → [ATTRIBUTE: WIND] → Strong (NO) / Weak (YES)
ID3 Step-by-Step Mathematical Process
Step 1: Find the most important feature. Compute the Information Gain (IG) of each feature. The feature with the highest Information Gain is selected as the Root Node.
1. Entropy of Dataset (DS):
Entropy(DS) = - P(yes) * log2(P(yes)) - P(no) * log2(P(no))
2. Information Gain (IG):
IG(Attribute) = Entropy(DS) - Σ [ (Count of Value / Total Count) * Entropy(Value) ]
Sample Dataset Calculation
| Temp |
Humidity |
Wind |
Output (Play?) |
| H | N | Y | Y |
| H | N | Y | Y |
| M | H | N | Y |
| H | N | Y | N |
| C | H | N | N |
| C | N | Y | Y |
| H | H | N | N |
| C | H | N | N |
| M | N | N | Y |
| C | H | Y | N |
Calculating Base Entropy (DS):
Total Samples = 10. Yes (Y) = 6, No (N) = 4 → [6, 4]
Entropy(DS) = -(6/10) * log2(6/10) - (4/10) * log2(4/10) ≈ 0.97
Calculating Entropy for a Specific Column (e.g., Temp):
Calculate instances of Hot, Mild, and Cold in relation to the target output.
- Temp = Hot [2, 2]: 2 Yes, 2 No.
Ent(Temp, Hot) = -(2/4)log2(2/4) - (2/4)log2(2/4) = 1
- Temp = Mild [2, 0]: 2 Yes, 0 No.
Ent(Temp, Mild) = 0 (Pure node)
Calculating Information Gain for Temp:
IG(Temp) = Entropy(DS) - [ (4/10)*Ent(Hot) + (4/10)*Ent(Cold) + (2/10)*Ent(Mild) ]
ID3 Tree Building Rules:
- If a node's output is pure (straight NO or YES, completely homogeneous), it becomes a leaf node (Decision).
- If a column has a mixed outcome, move to the next preference/feature to split the node further.
- Higher preference (higher Info Gain) is always calculated and placed first.
6. Machine Learning Fundamentals
Definition: It is a domain of AI. We use it to try to train a model to perform tasks based on data. Applications are vast, spanning across sectors like Health, Finance, and Education.
Three Main Types of Machine Learning:
- Supervised Learning
- Unsupervised Learning
- Reinforcement Learning
7. Supervised Learning
Core Concept: Learning with Labels. Depends on past data. We train the model on data with known outcomes (labeled data) and it maps to the category it belongs to.
Input Data
(Labeled: e.g. Cat, Dog)
→
Model
(Training)
→
Predictions
(Actual vs Predicted)
Two Main Tasks in Supervised Learning:
- Classification: Predicts discrete categories.
- Binary Classification (e.g., Yes/No, Spam/Not Spam)
- Multi-classification (e.g., Cat/Dog/Car)
- Regression: Predicts continuous values.
- Examples: Bitcoin price predictor, Predicting house prices based on features (size, beds).
8. Unsupervised Learning
Core Concept: Finding Structure. Input data is unlabeled (don't provide labels). The model groups data based on inherent patterns, likeliness, or shared interests.
Two Main Techniques:
- Clustering: Used for grouping data.
- If "likeliness exists" → add them into their own clusters.
- Example: Grouping students based on their interests.
- Dimensionality Reduction:
- Data consists of many attributes, but some attributes don't play a significant role.
- Rule: List them → Remove them.
- Result: Data is reduced → Performance is improved.
K-Means Clustering (Algorithm & Math)
K = Number of clusters. We compute differences (distances) to group points into centroids.
Distance Formulas:
1 Parameter (1D): d = | x1 - x2 |
2 Parameters (2D Euclidean Distance): d = √[ (x2 - x1)2 + (y2 - y1)2 ]
Mathematical Example (1 Parameter - Marks):
Suppose K=2. We initially specify two random centroids from the data, e.g., C1 = 80, C2 = 60.
| Student |
Marks |
Distance to C1 (μ=80) |
Distance to C2 (μ=60) |
Assigned Cluster |
| S1 | 80 | |80-80| = 0 | |80-60| = 20 | C1 |
| S2 | 60 | |60-80| = 20 | |60-60| = 0 | C2 |
| S3 | 72 | |72-80| = 8 | |72-60| = 12 | C1 (Min distance is 8) |
Centroid (Mean Value) Change:
Because S3 was added to C1, we must compute the new mean for C1.
New μ1 = (80 + 72) / 2 = 76
Now, test the next student (e.g., S4 = 65) against the new centroid μ1=76 and μ2=60:
Distance to C1: |65 - 76| = 11
Distance to C2: |65 - 60| = 5 → Assign to C2 (Min distance).
New C2 Mean: (60 + 65) / 2 = 62.5
Within Cluster Sum of Square (WCSS) & Elbow Method
To find the optimal number of clusters (K), we use the Elbow Method based on WCSS.
- WCSS: The sum of the squared distances of each point from its assigned cluster centroid.
- Formula:
WCSS = Σ (xi - μc)2
- Elbow Shape Graph: Plot K (1, 2, 3...10) on the X-axis and WCSS on the Y-axis. The line curves downwards. The point at which the edge becomes "sharp" (like an elbow) is the optimal K value.
9. Reinforcement Learning
Core Concept: Continuous Learning via Reward and Penalty. The agent learns optimal actions to maximize total rewards through an Agent-Environment Loop.
The Agent-Environment Loop:
[ ENVIRONMENT (State) ] → provides current state to → [ ROBOT AGENT ]
[ ROBOT AGENT ] → performs an → [ ACTION (e.g., Move Right) ]
[ ACTION ] → affects the → [ ENVIRONMENT ]
[ ENVIRONMENT ] → returns a → [ REWARD (+10, 0, -1) ] back to the agent.
Training & Deployment Behavior:
- We train the model with sample data.
- When deployed, if the answer the model provides is correct/what we need → Reward the model (Means model behaves correctly in the future).
- If the model does not behave correctly or does not produce the expected result → Give it a Penalty so the model learns not to do it again.
End of Artificial Intelligence Theory Preparation Notes. Good luck on your final exam!