Is 30 °C hot?
Hands up: is 30 °C hot? Is 29.9 °C?
A crisp rule "hot if T ≥ 30" says 29.9 is not hot and 30.0 is. Nobody in Dhaka thinks that. People say "a bit hot", "quite hot", "very hot".
Fuzzy sets: membership is a degree
- A crisp set: x is in or out, μ(x) ∈ {0, 1}. A fuzzy set A: a membership function μA: X → [0, 1].
- A linguistic variable (temperature) has fuzzy values (cool, warm, hot) that overlap: 30 °C is 0.57 warm and 0.29 hot.
- Shapes are a design choice; triangles and trapezoids are standard because they are cheap and easy to tune.
Fuzzy ≠ probability
"0.7 chance that the glass is poisoned" and "the glass is 0.7 full of poison" are different statements. Probability is about uncertainty whether something is true; fuzziness is about the degree to which it is true, with nothing left to find out.
Lotfi Zadeh, an electrical engineer at Berkeley, introduced fuzzy sets in 1965. Japanese engineers made them famous in the 1980s.
Fuzzy AND, OR, NOT, and hedges
| Operation | Zadeh | μA = 0.7, μB = 0.4 |
|---|---|---|
| A AND B | min(μA, μB) | 0.4 |
| A OR B | max(μA, μB) | 0.7 |
| NOT A | 1 − μA | 0.3 |
| very A | μA² | 0.49 |
| somewhat A | √μA | 0.84 |
A AND NOT A = min(0.7, 0.3) = 0.3, not 0. A OR NOT A = 0.7, not 1. The laws of contradiction and excluded middle do not hold.
With μ only 0 or 1, min/max/1 − μ reduce to ordinary Boolean AND/OR/NOT: fuzzy logic contains crisp logic.
Worked example: a fuzzy fan controller, by hand
Given
Room at 30 °C, 70 % humidity. Temperature: cool (15, 15, 20, 26), warm (20, 27, 34), hot (28, 35, 40, 40). Humidity: dry (30, 30, 45, 65), humid (50, 75, 100, 100). Fan: low (0, 0, 15, 45), medium (25, 50, 75), high (55, 85, 100, 100). Rules: R1 cool → low; R2 warm ∧ dry → low; R3 warm ∧ humid → medium; R4 hot → high.
Find
The fan speed by Mamdani inference with centroid defuzzification (sample every 10 %).
Method: Mamdani inference: fuzzify, AND = min, clip, OR = max, centroid
Solution
Predict the answer first. Then reveal one step at a time.
Live lab: the fan controller
| Rule | IF | THEN fan | strength |
|---|---|---|---|
| R1 | temp is cool | low | 0.00 |
| R2 | temp is warm AND humidity is dry | low | 0.00 |
| R3 | temp is warm AND humidity is humid | medium | 0.57 |
| R4 | temp is hot | high | 0.29 |
Your turn · 1: a Sugeno shortcut
Same sets and rules as the worked example, but each rule now outputs a single number (a Sugeno system): low = 20 %, medium = 50 %, high = 90 %.
Find the fan speed at 33 °C and 55 % humidity. Check with the lab's Sugeno readout.
Work it out first.
Press Solve when the class has an answer.
Critical thinking · why not just use an equation?
A fan speed of 61.8 % could also come from a formula, e.g. speed = 6(T − 20). What does fuzzy logic give you that the formula does not?
Argue it in pairs for two minutes. There may be more than one defensible answer.
Genetic algorithms: search by breeding
- Encode a candidate solution as a string (a chromosome): bits, digits, a permutation.
- Start with a random population of N individuals. Score each with a fitness function.
- Select parents in proportion to fitness (roulette wheel) or by tournament.
- Crossover: cut two parents at a random point and swap tails.
- Mutate: change each gene with a small probability.
- The children form the next generation (optionally keep the best: elitism). Repeat until good enough or out of time.
A GA is a local search (Week 3) that keeps k states, like beam search, but makes new ones by combining two good states instead of only nudging one.
Roulette selection: fitness must be positive; bigger slice, more children.
Worked example: one generation by hand
Given
Maximise f(x) = x², x an integer 0–31 encoded in 5 bits. Population: 01101, 11000, 01000, 10011 (Goldberg's classic).
Find
Selection probabilities, expected copies, the children of crossover, and the new total fitness.
Method: simple GA (Goldberg, 1989)
Solution
Predict the answer first. Then reveal one step at a time.
Live lab: evolve an 8-queens solution
263168572623571855236155683823657857462235382822216858712321Your turn · 2: Russell & Norvig's 8-queens population
Four 8-queens individuals with fitness (non-attacking pairs): 24748552 (24), 32752411 (23), 24415124 (20), 32543213 (11).
(a) Selection probability of each? (b) Cross 32752411 with 24748552 after the 3rd digit: write both children.
Work it out first.
Press Solve when the class has an answer.
Critical thinking · when does crossover help?
Crossover helped in x² and 8-queens. Can you design an encoding where it is useless, or harmful?
Argue it in pairs for two minutes. There may be more than one defensible answer.
Real world: rice cookers and space antennas
Fuzzy-logic rice cookers, washing machines (load and dirt sensors → water and spin time) and inverter air conditioners sold in Dhaka markets all run small fuzzy controllers. The Sendai subway in Japan (1987) used fuzzy control for smoother, more energy-efficient braking.
Fuzzy controllers are studied for anaesthesia depth and insulin dosing, where expert rules ("glucose high and rising → increase a little") are natural, and smooth action is safer than thresholds.
NASA's ST5 satellites (2006) flew an X-band antenna whose odd, bent-wire shape was designed by an evolutionary algorithm; it met the specification better than the hand design.
Your university class routine: rooms, teachers, sections, no clashes. Why is a GA a reasonable tool?
Argue it in pairs for two minutes. There may be more than one defensible answer.
Pop quiz
Question 1 / 5
μtall(Rafi) = 0.7. Then μnot tall(Rafi) and μtall AND not tall(Rafi) are…
Three things to remember
Fuzzy sets: μ ∈ [0, 1], overlapping linguistic values. AND = min, OR = max, NOT = 1 − μ; very = μ².
Mamdani: fuzzify → rule strength (min) → clip → aggregate (max) → centroid Σμz/Σμ. Sugeno: Σwz/Σw.
GA: population, fitness, roulette selection f/Σf, crossover, mutation, elitism. A k-state local search that recombines.
Midterm: what to expect
| Week | Be able to… |
|---|---|
| 1 | define AI (four approaches), write PEAS, classify environments |
| 2 | formulate a problem (states, actions, goal, cost); propositional logic, forward/backward chaining, expert-system architecture |
| 3 | trace BFS, DFS, UCS, DLS, IDS; compare them; hill climbing, annealing acceptance eΔE/T, beam search |
| 4 | greedy and A* traces; admissible vs consistent; dominance, b*, relaxed problems; minimax |
| 5 | alpha–beta cuts, move ordering, expectiminimax; fuzzy inference by hand; one GA generation |
Creative questions (CQ) only, no MCQ. 30 % of the course. Each CQ has a short scenario and 3–4 parts that go from recall to analysis.
A practice CQ
A ward robot moves on: S–A (2), S–B (5), A–B (2), A–G (6), B–G (2). Heuristic: h(S) = 5, h(A) = 4, h(B) = 2, h(G) = 0.
(a) Is h admissible? (b) Consistent? (c) Trace A*: expansion order, path, cost. (d) What would greedy best-first return?
Work it out first.
Press Solve when the class has an answer.