🧠 AI Foundations · Lecture 19 of 24

Fuzzy Logic: Reasoning with Degrees of Truth

Is 29°C "hot"? Fuzzy logic replaces true/false with degrees of membership. We build a Mamdani fuzzy controller step by step: fuzzification, rule evaluation, aggregation and defuzzification.

Classical logic insists that every statement is true or false. But human concepts are vague: "tall", "hot", "fast", "high risk". Is a 29°C day hot? Somewhat. Fuzzy logic, introduced by Lotfi Zadeh in 1965, formalises such graded concepts. It became famous through control systems — from washing machines and rice cookers to the Sendai subway in Japan, whose fuzzy controller gave a smoother ride.

Fuzzy sets#

A classical (crisp) set $A$ has a characteristic function $\chi_A(x) \in \{0, 1\}$. A fuzzy set has a membership function

$$ \mu_A : X \rightarrow [0, 1] $$

where $\mu_A(x)$ is the degree to which $x$ belongs to $A$. Common shapes are triangular, trapezoidal and Gaussian:

$$ \mu_{\text{tri}}(x; a, b, c) = \max\left(0,\; \min\left(\frac{x - a}{b - a},\; \frac{c - x}{c - b}\right)\right) $$

Fuzzy operators#

Zadeh's standard operators generalise logic:

OperationDefinition
AND (intersection)$\mu_{A \cap B}(x) = \min(\mu_A(x), \mu_B(x))$
OR (union)$\mu_{A \cup B}(x) = \max(\mu_A(x), \mu_B(x))$
NOT (complement)$\mu_{\neg A}(x) = 1 - \mu_A(x)$

More generally, AND can be any t-norm (e.g. product $ab$) and OR any t-conorm (e.g. probabilistic sum $a + b - ab$). Note that fuzzy logic violates the law of excluded middle: $\max(\mu, 1 - \mu)$ can be less than 1.

A fuzzy controller, step by step#

Let us design a fan-speed controller. Input: temperature (°C). Output: fan speed (%).

Linguistic variables:

  • Temperature: Cold, Warm, Hot.
  • Fan speed: Slow, Medium, Fast.

Rules:

  1. IF temperature is Cold THEN speed is Slow.
  2. IF temperature is Warm THEN speed is Medium.
  3. IF temperature is Hot THEN speed is Fast.

The Mamdani inference process has four stages:

  1. Fuzzification — compute membership degrees of the crisp input.
  2. Rule evaluation — compute each rule's firing strength and clip its output set.
  3. Aggregation — combine clipped output sets with max.
  4. Defuzzification — convert the aggregated fuzzy set into a crisp number, usually with the centroid:
$$ y^* = \frac{\int y\, \mu(y)\, dy}{\int \mu(y)\, dy} $$
python
import numpy as np

def tri(x, a, b, c):
    return np.maximum(0, np.minimum((x - a) / (b - a + 1e-9), (c - x) / (c - b + 1e-9)))

temp_sets = {"cold": (0, 10, 22), "warm": (18, 25, 32), "hot": (28, 38, 50)}
speed = np.linspace(0, 100, 501)
speed_sets = {"slow": tri(speed, 0, 15, 45), "medium": tri(speed, 30, 50, 70), "fast": tri(speed, 55, 85, 100)}
rules = [("cold", "slow"), ("warm", "medium"), ("hot", "fast")]

def fan_speed(t):
    agg = np.zeros_like(speed)
    for tin, sout in rules:
        strength = tri(np.array(t, float), *temp_sets[tin])       # fuzzification
        agg = np.maximum(agg, np.minimum(strength, speed_sets[sout]))  # clip + aggregate
    return float((speed * agg).sum() / (agg.sum() + 1e-9))      # centroid

for t in [8, 20, 26, 30, 40]:
    print(t, "°C ->", round(fan_speed(t), 1), "%")

Notice how the output changes smoothly with temperature — there is no abrupt jump at a threshold. That smoothness is exactly why fuzzy controllers feel natural.

Sugeno models#

The Takagi–Sugeno–Kang (TSK) model uses crisp functions as rule outputs, e.g. "IF temperature is Hot THEN speed $= 2t + 10$". The final output is the weighted average of rule outputs by firing strength. TSK models are computationally cheaper and easier to optimise.

Neuro-fuzzy systems#

ANFIS (Adaptive Neuro-Fuzzy Inference System, 1993) represents a Sugeno fuzzy system as a network and learns membership-function parameters by gradient descent. This combines the interpretability of linguistic rules with the adaptivity of learning — an early instance of the neuro-symbolic idea.

Where fuzzy logic stands today#

Fuzzy control remains common in consumer appliances, automotive subsystems, industrial process control and decision-support tools where experts can describe behaviour in words. In mainstream machine learning, probabilistic and neural methods dominate, but fuzzy ideas persist in soft membership (e.g. fuzzy c-means clustering) and in interpretable rule-based models.

JA
Written by

Janin A Apurba

B.Sc. in CSE, AUST · Advanced ICT Officer, CNRS-UNHCR. Teaching AI, ML and Deep Learning to the next generation of engineers and researchers.

Keep learning

Related lectures

🧠 AI Foundations

Genetic Algorithms and Evolutionary Computation

Nature optimises through selection, crossover and mutation. We implement a genetic algorithm from scratch, discuss the schema theorem and survey evolution strategies and neuroevolution.

Beginner⏱ 5 min#018
🧠 AI Foundations

Monte Carlo Tree Search: The Algorithm Behind Superhuman Go

When the game tree is too vast and positions too hard to evaluate, MCTS builds an asymmetric tree guided by random simulations and the UCB1 bandit formula. We implement it and connect it to AlphaZero.

Intermediate⏱ 5 min#020
🧠 AI Foundations

Local Search: Hill Climbing, Simulated Annealing and Beam Search

When only the final configuration matters, we can abandon paths and move through the space of complete solutions. Local search is simple, memory-light and the conceptual ancestor of gradient descent.

Beginner⏱ 5 min#017