Skip to content
coden

Fuzzy control: Mamdani and Sugeno from a fan to a pole on a cart

Controllers and feedback, fuzzification, inference and defuzzification, centroid, bisector and mean of maxima, the Takagi–Sugeno controller, control surfaces and a fuzzy controller that keeps a pole upright on a cart.

14 minutes Matěj Žalmánek 2026-10-15

Series AI basics Part 35 of 52
  1. Map of artificial intelligence: what is what and how it all fits together
  2. A brief history of artificial intelligence: from Turing to language models
  3. Data, model, training, inference: the basic terms on a single example
  4. How to read mathematical notation: symbols, indices, sums and quantifiers
  5. Sets and relations: the building blocks of definitions in AI
  6. Functions and mappings: why every AI model is a function
  7. Logic and proofs: the rules AI reasons by
  8. Graphs and trees: the structure that both search and neural networks stand on
  9. Linear algebra for machine learning: vectors, matrices and why AI mostly multiplies
  10. Derivatives, the gradient and the chain rule: how a model finds out which way to learn
  11. Gradient descent: how a model learns
  12. What probability is: from rolling dice to the Kolmogorov axioms
  13. Conditional probability and Bayes’ theorem: how to update your estimate when you learn something new
  14. Random variables and the cumulative distribution function: one function that tells you everything about a distribution
  15. Probability density and probability mass functions: why a continuous variable has zero probability at a point
  16. Expected value, variance and covariance: where a distribution lies, how wide it is and what goes with what
  17. Overview of probability distributions: Bernoulli, binomial, Poisson, uniform, normal and exponential
  18. Law of large numbers and central limit theorem: why averages behave so predictably
  19. Statistics and parameter estimation: maximum likelihood, MAP and confidence intervals
  20. Information theory: entropy, cross-entropy and KL divergence — where loss functions come from
  21. State-space search: BFS, DFS, UCS and A* with animations
  22. Games and adversaries: minimax, alpha-beta pruning and Monte Carlo tree search
  23. Constraint satisfaction: backtracking, constraint propagation and AC-3 on sudoku and a map of Czech regions
  24. Logic and knowledge systems: forward and backward chaining, resolution and expert systems
  25. Planning: STRIPS, the blocks world, heuristics from relaxation and planning in AI agents
  26. Local search and simulated annealing: a travelling salesman through the Czech regional capitals
  27. Genetic algorithms: population, crossover, mutation and selection on a backpack for a hike
  28. Evolution strategies and genetic programming: from the one-fifth rule to Kepler’s law
  29. Ant colony optimization: how a pheromone trail finds a short path
  30. Particle swarm optimisation: inertia, personal experience and the swarm’s experience
  31. Neuroevolution: evolving the weights and shape of neural networks, and the NEAT algorithm
  32. Fuzzy sets and membership functions: how to write down “somewhat warm”
  33. Fuzzy logic and probability: why “somewhat warm” does not mean “probably warm”
  34. Fuzzy logic: t-norms, implications and IF–THEN rules
  35. Fuzzy control: Mamdani and Sugeno from a fan to a pole on a cart
  36. Fuzzy clustering: the fuzzy c-means algorithm and points between clusters
  37. Neuro-fuzzy systems (ANFIS): fuzzy rules that learn from data
  38. Markov chains: the transition matrix, the stationary distribution and PageRank
  39. Hidden Markov models: the Viterbi algorithm and the dishonest casino
  40. Bayesian networks: why the grass is wet and what it means for the sprinkler
  41. The Kalman filter: how to estimate where a car is and how fast it goes from imprecise measurements
  42. Types of machine learning: supervised, unsupervised, semi-supervised and more
  43. Prompts, context and RAG: how to give a model the right information
  44. Variational autoencoders (VAE): new images from a continuous latent space
  45. Generative adversarial networks (GAN): the forger versus the detective
  46. Diffusion models: how pure noise becomes an image
  47. Markov decision processes: states, actions, rewards and the Bellman equations
  48. Q-learning and DQN: learning the value of actions, from a table to a neural network
  49. Policy gradient and PPO: learning the policy directly
  50. How an AI agent works: a language model in a loop with tools
  51. Programming with AI agents: the task, tests and review
  52. Evaluating and securing AI systems: how to measure and how to keep watch

Full series syllabus 52 of 83 topics published

What you will take away
  • How a fuzzy controller turns a measurement into an action: fuzzification, inference and defuzzification.
  • How Mamdani and Sugeno controllers differ and why the centroid never reaches the ends of the range.
  • How nine rules keep a pole on a cart upright — and why keeping the cart in place also needs a linear term.

Useful to know first: Fuzzy logic: t-norms, implications and IF–THEN rules

In 1974 Ebrahim Mamdani sat in a London laboratory in front of a small steam engine that refused to be controlled by classical methods. An experienced operator, meanwhile, handled it with ease — following rules such as “if the pressure is a bit high and rising, reduce the steam a little”. Together with his student Sedrak Assilian, Mamdani wrote those rules down in fuzzy logic and let them run the engine. It worked. Within ten years fuzzy controllers were running cement kilns, and a few years later underground trains and washing machines. In the previous part we learned how to evaluate rules; now we will build a controller out of them that outputs a single number — and let it balance a pole.

This part builds on Fuzzy logic: t-norms, implications and IF–THEN rules and Neuroevolution, from which we borrow the pole on a cart.

1. Controllers and feedback

Definition — controller

Let X be the set of possible measured states of the system (typically X ⊆ ℝn, where n ≥ 1 is the number of measured quantities) and U the set of admissible control actions (typically U ⊆ ℝm, m ≥ 1). A controller (without internal memory — all controllers in this part are like that) is a mapping

R : X → U,   x ↦ u = R(x),

which assigns to every measured state x ∈ X exactly one action u ∈ U. So the controller decides only from the current measurement. In a closed loop (made precise in the next definition) the action affects the system, the system changes, it is measured again and the controller acts again — typically tens to thousands of times per second.

In plain words

A thermostat measures the temperature and turns on the heating; the temperature changes, and the thermostat measures it again. A controller is the rule “what to do when I see this”. Classical control theory designs it from the equations of the system. A fuzzy controller assembles it from rules the way an experienced person would say them.

Definition — closed loop in discrete time

Let X and U be the sets of states and actions and R : X → U a controller as in the previous definition. Further let Δt > 0 be the step length (the computer measures and acts once every Δt), F : X × U → X the mapping that determines the state at the end of a step from the state and action at its beginning (it is obtained from the equations of motion of the system), and x0 ∈ X the initial state. The closed loop in discrete time is the pair of sequences of states (xk)k ≥ 0 and actions (uk)k ≥ 0 given by the recursion

uk = R(xk),    xk+1 = F(xk, uk),    k = 0, 1, 2, …

The state xk describes the system at time k · Δt. So the controller sees neither the future nor the equations F — only the current measurement. For the pendulum at the end of this part Δt = 0.02 s, so a minute of control is 3,000 steps of the loop.

2. Three steps of a fuzzy controller

input 27 °C60 % fuzzify warm 0.83humid 0.67 infer R1: 0.2R3: 0.67 defuzzify output 65.9 %
A fuzzy fan controller step by step
  1. Fuzzification turns crisp measurements into degrees of membership: 27 °C is “pleasant” to degree 0.2 and “warm” to degree 0.83, a humidity of 60 % is “humid” to degree 0.67.
  2. Inference evaluates the rules as shown in the previous part: each rule has a firing strength and clips its conclusion; the conclusions are combined by the maximum.
  3. Defuzzification turns the resulting fuzzy set into a single number that goes to the motor.
Example — fuzzifying 27 °C and 60 %

The terms from the previous part: pleasant is the trapezoid (10, 17, 23, 28), warm the triangle (22, 28, 34), hot the trapezoid (30, 36, 40, 40); dry is the trapezoid (0, 0, 30, 50), humid (40, 70, 100, 100). On the falling edge of a trapezoid (a, b, c, d), i.e. for c ≤ x ≤ d, μ(x) = d − x/d − c; on the rising edge (a ≤ x ≤ b), μ(x) = x − a/b − a; the triangle (a, b, c) is the trapezoid (a, b, b, c).

  • pleasant(27) = 28 − 27/28 − 23 = 1/5 = 0.2,
  • warm(27) = 27 − 22/28 − 22 = 5/6 ≈ 0.83 (27 lies on the rising edge),
  • cold(27) = hot(27) = 0 — 27 is outside their supports,
  • humid(60) = 60 − 40/70 − 40 = 2/3 ≈ 0.67, dry(60) = 0 (the support ends at 50).

Mamdani inference is a single formula that assembles the output fuzzy set from the clipped conclusions:

μout(y) = maxi min( αi, μBi(y) ),    αi = T(μAi1(x1), …, μAin(xn))

μout(y)
the output fuzzy set — for every possible output value y it says how strongly the rules support it; it is a whole function, not a number, which is why defuzzification still has to follow (in the figure below it is the green area)
αi
the firing strength of the i-th rule — the t-norm T (here the minimum) joins the “and” conditions; a rule cannot hold more than its weakest condition
μBi(y)
the conclusion of the rule, say “fast” — the shape the output would have if the rule held fully
min
clipping — the conclusion may be supported only as much as the premise holds; a weak rule thus gives a low “plateau”
maxi
combining the rules — the rules are treated as alternatives (“or”), so a value y is supported as much as the strongest rule supports it
Example — the output set of the fan

Firing strengths (colours as in the formula above): R1 (cold or pleasant → slow) has α1 = max(0, 0.2) = 0.2; R2 (warm and dry → medium) α2 = min(5/6, 0) = 0; R3 (warm and humid → fast) α3 = min(5/6, 2/3) = 2/3; R4 (hot → fast) α4 = 0.

Slow is the trapezoid (0, 0, 20, 45), clipped at height 0.2: a plateau of 0.2 up to y = 40 (where the falling edge 45 − y/25 drops to 0.2) and then a decline to zero at 45. Fast is the trapezoid (55, 80, 100, 100), clipped at height 2/3: the edge y − 55/25 reaches 2/3 at y = 55 + 25 · 2/3 ≈ 71.67. The result:

μout(y) = 0.2 on [0, 40],   45 − y/25 on [40, 45],   0 on [45, 55],   y − 55/25 on [55, 71.67]   and   2/3 on [71.67, 100].

The whole controller as pseudocode, with the output axis divided into a grid:

def mamdani(vstup, pravidla, mrizka):        # mrizka = 0, 0.1, …, 100
    sily = []
    for r in pravidla:                          # 1. fuzzification + firing strength:
        sily.append(min(                        #    “and” = minimum, “or” = maximum
            max(mu(t, vstup[prom]) for t in terminy)
            for prom, terminy in r.kdyz))
    vystup = [max(min(a, r.pak(y)) for a, r in zip(sily, pravidla))
              for y in mrizka]                  # 2. clipping and combining by maximum
    citatel = sum(y * m for y, m in zip(mrizka, vystup))
    jmenovatel = sum(vystup)                    # 3. centroid defuzzification
    return citatel / jmenovatel if jmenovatel > 0 else 50

3. Defuzzification

Definition — defuzzification methods

Let [a, b] ⊂ ℝ, a < b, be the interval of possible outputs and μ : [a, b] → [0, 1] the membership function of the output fuzzy set, which is integrable and has positive area, ∫ab μ(y) dy > 0 (at least one rule holds). Defuzzification is a rule that assigns to the function μ a single number y* ∈ [a, b]. The three most common ones:

  1. Centroid (centre of gravity): y*T = ∫ab y · μ(y) dy/∫ab μ(y) dy.
  2. Bisector: a number y*B ∈ [a, b] for which ∫ay*B μ(y) dy = ∫y*Bb μ(y) dy. Such a number exists, because the left-hand side is a continuous non-decreasing function of the upper limit that grows from 0 to the whole area; if μ is zero around the solution, it is not unique.
  3. Mean of maxima: let h = maxy ∈ [a, b] μ(y) and let M = {y ∈ [a, b] : μ(y) = h} be the set of points where the maximum is attained. y*M is the average of the points of M; if M = [m1, m2] is an interval (as in all examples in this part), then y*M = m1 + m2/2.

So the centroid is the weighted average of all outputs with weight μ, the bisector splits the area under μ into two equal halves, and the mean of maxima looks only at the most strongly supported outputs.

In plain words

The resulting set is like a pile of sand poured over the fan-speed axis. The centroid is the point where the pile would balance on a plank; the bisector splits it into two equally large halves; the mean of maxima looks only at the highest part and ignores the rest.

y* = ∫ y · μ(y) dy/∫ μ(y) dy

y*
the crisp output — a single number that goes to the motor, because the motor does not understand fuzzy sets
y
the position on the fan-speed axis — the “lever arm”; every value votes for itself
μ(y)
the weight of the vote — values the rules support more pull the result harder (the green area in the figure)
∫ μ(y) dy
the total area — dividing by it turns the weighted sum into a weighted average; without it the result would grow with how many rules fire, not with where they point
It is exactly the formula for the centre of mass of a body from physics, only mass is replaced by the degree of membership.
00.51 0102030405060708090100 65.9 75.3 85.9 fan speed (%) degree of membership μ (0–1)
Fan output for 27 °C and 60 % and three defuzzification methods centroidbisectormean of maxima

For our input the centroid gives 65.9 %, the bisector 75.3 % and the mean of maxima 85.9 %. The difference lies in how much say the weaker rule R1 (“slow” with strength 0.2) gets: the centroid takes all of it into account, the mean of maxima none at all. The centroid is the most widely used, because the output changes smoothly. But it has a flaw: it never reaches the ends of the range. Even when only the rule “fast” fires, the centroid of its trapezoid lies at 83 %, not at 100 %.

Example — centroid, bisector and mean of maxima by hand

The output set from the section on the steps is made of rectangles and triangles, so we compute the integrals from known areas and centroids (the centroid of a right triangle lies one third of the way from its vertical side):

SegmentShapeAreaCentroidArea · centroid
[0, 40]rectangle of height 0.2820160
[40, 45]triangle, falling0.541.6720.83
[55, 71.67]triangle, rising5.5666.11367.28
[71.67, 100]rectangle of height 2/318.8985.831,621.30
total32.942,169.41

The “Area” column summed gives the denominator of the centroid formula, the “Area · centroid” column its numerator (colours as in the formula above).

  • Centroid: y* = 2,169.41/32.94 ≈ 65.85 %. The computer in src/fuzzyrizeni.js replaces the integral with a sum in steps of 0.1 % and gets 65.87 — both round to 65.9 %.
  • Bisector: half of the area is 32.94/2 = 16.47. Up to the point 71.67 we collect 8 + 0.5 + 5.56 = 14.06, so 2.41 is missing; on the plateau of height 2/3 that is 2.41/2/3 ≈ 3.62 further, i.e. y* ≈ 71.67 + 3.62 ≈ 75.3 %.
  • Mean of maxima: the maximum 2/3 holds on the whole of [71.67, 100], the average of the endpoints is 71.67 + 100/2 ≈ 85.8 %. The computer averages the grid points from 71.7 upwards, hence 85.9 %.

4. Takagi–Sugeno

Centroid defuzzification means computing an integral — in 1985, on the small processor of a washing machine or a camera, an expensive thing. Tomohiro Takagi and Michio Sugeno therefore proposed rules that return a number directly.

Definition — Takagi–Sugeno controller

Let n ≥ 1 be the number of inputs, r ≥ 1 the number of rules and T a t-norm (here the minimum; see the part on fuzzy logic). For every i = 1, …, r and j = 1, …, n let Aij be a fuzzy set on ℝ with membership function μAij : ℝ → [0, 1] and fi : ℝn → ℝ a function. The i-th rule has the form

IF x1 is Ai1 and … and xn is Ain, THEN y = fi(x1, …, xn).

For an input x = (x1, …, xn) ∈ ℝn the firing strength of the i-th rule is αi(x) = T(μAi1(x1), …, μAin(xn)) ∈ [0, 1]. If ∑i=1r αi(x) > 0, the output of the Takagi–Sugeno controller is

y*(x) = ∑i=1r αi(x) · fi(x)/∑i=1r αi(x).

The controller is

  1. zero-order if and only if every fi is constant: fi(x) = ci with ci ∈ ℝ;
  2. first-order if and only if every fi is affine (the literature usually says “linear”): fi(x) = ci0 + ci1x1 + … + cinxn with cij ∈ ℝ.

So the output is the weighted average of the proposals fi(x), with the firing strengths of the rules as weights.

In plain words

Each rule does not say “the speed is fast” (a fuzzy set) but “the speed is 90 %” (a number). The result is the average of the proposals of all rules, weighted by how much each rule holds. No integral, just a few multiplications and one division.

Let us give the fan the same rules, only with constant conclusions: slow = 15 %, medium = 50 %, fast = 90 %. At 27 °C and 60 % humidity only R1 (strength 0.2) and R3 (strength 2/3) hold, and the output is (colours as in the formula below)

y* = 0.2 · 15 + 2/3 · 90/0.2 + 2/3 = 63/0.867 ≈ 72.7 %.

y* = ∑i αi · fi/∑i αi

y*
the crisp output — directly, without an output fuzzy set and without defuzzification
αi
the firing strength of the rule, the same as in Mamdani — it determines how much say the rule gets
fi
the rule’s proposal — a number (zero order) or a linear function of the inputs (first order); it replaces the whole shape of “fast” with a single representative
∑i
adding up the votes of all rules — rules that do not hold (αi = 0) contribute zero
∑i αi
normalization — the weights αi/∑k αk sum to 1, so the result is an average of the proposals and does not depend on how strongly all the rules hold together
The centroid integral has shrunk here to a sum over the rules — four terms instead of a thousand grid points.
Theorem — zero-order Sugeno reaches the ends

Let a zero-order Takagi–Sugeno controller with r ≥ 1 rules be given, whose constant conclusions are f1, …, fr ∈ ℝ, and let x ∈ ℝn be an input for which the rules have firing strengths α1, …, αr ∈ [0, 1] with ∑i=1r αi > 0 (at least one rule holds). Denote by I = {i ∈ {1, …, r} : αi > 0} the set of rules that hold. Then

  1. mini ∈ I fi ≤ y*(x) ≤ maxi ∈ I fi;
  2. if there is a c ∈ ℝ such that fi = c for all i ∈ I, then y*(x) = c.

Proof. Let λi = αi/∑k=1r αk. Then λi ≥ 0, λi = 0 for i ∉ I, ∑ λi = 1, and y* = ∑i ∈ I λi fi is a convex combination of the numbers fi, i ∈ I. From the bound fi ≥ minI f we get y* ≥ minI f · ∑ λi = minI f, and likewise from above. If all fi with i ∈ I equal c, then y* = c ∑ λi = c. ∎

The Mamdani centroid has no such guarantee: even the conclusion “fast” alone at full height has its centroid at 83 %, because its rising edge from 55 % also enters the average.

5. The control surface

The controller is a function of two variables, so it can be drawn in full. Each cell is one combination of temperature and humidity, and the brightness says how fast the fan spins:

Mamdani (centroid) 02040 050100 temperature T (°C) relative humidity (%) Sugeno (constants) 02040 050100 temperature T (°C) relative humidity (%)
Control surfaces of the fan: Mamdani and Sugeno

Both surfaces look similar — slow below 20 °C, fast with warmth and humidity — and change smoothly, without jumps. They differ at the edges. At 35 °C and 90 % humidity Sugeno gives exactly 90 %, Mamdani only 82.2 %; in the cool of 15 °C Sugeno gives 15 %, Mamdani 18.4 %. That is the flaw of the centroid: a Mamdani controller never reaches the ends of the range. In the middle, where the rules overlap, the two behave differently again, because they average differently shaped proposals.

Definition — control surface

Let X1, X2 ⊆ ℝ be the sets of values of two inputs and R : X1 × X2 → ℝ a controller with one output. The control surface of the controller R is the graph of the function R, i.e. the set

{(x1, x2, R(x1, x2)) : x1 ∈ X1, x2 ∈ X2} ⊆ ℝ3.

For the fan x1 = T ∈ [0, 40] is the temperature in °C, x2 = h ∈ [0, 100] the relative humidity in % and R(T, h) ∈ [0, 100] the fan speed in %. The figure evaluates it on a grid of 41 temperatures (in steps of 1 °C) × 26 humidities (in steps of 4 %).

Example — a corner of the surface: 35 °C and 90 %

hot(35) = 35 − 30/36 − 30 = 5/6 ≈ 0.83, warm(35) = 0 (the triangle ends at 34), pleasant and cold are both 0. Only rule R4 (hot → fast) holds, with strength 5/6. Colours as in the Sugeno and centroid formulas above.

  • Sugeno: y* = 5/6 · 90/5/6 = 90 % — exactly, by the theorem above.
  • Mamdani: “fast” clipped at 5/6 is a triangle on [55, 75.83] (area 1/2 · 20.83 · 5/6 ≈ 8.68, centroid 55 + 2/3 · 20.83 ≈ 68.89) and a rectangle on [75.83, 100] (area 24.17 · 5/6 ≈ 20.14, centroid 87.92). y* = 8.68 · 68.89 + 20.14 · 87.92/8.68 + 20.14 ≈ 82.2 %.

In the other corner, 15 °C and 30 %, pleasant(15) = 15 − 10/17 − 10 = 5/7 ≈ 0.71 and only R1 holds; Sugeno gives exactly 15 %, the centroid of the clipped “slow” 18.4 %.

6. The fuzzy pendulum

In the part on neuroevolution the pole on the cart was balanced by a network whose weights were found by evolution. Now let us try rules that a person would write. The inputs are the angle of the pole and its angular velocity, both with three terms — negative, zero and positive; the output is a force from −10 to +10 N, zero-order Sugeno:

angle \ angular velocityfalling leftstillfalling right
tilted left−10 N−5 N0 N
upright−5 N0 N+5 N
tilted right0 N+5 N+10 N

Nine rules such as “IF the pole is tilted right AND falling right, THEN push the cart hard to the right”. The logic is the same as with a broom balanced on your palm: your hand moves under the pole in the direction it is falling.

Definition — fuzzy pendulum controller

Let the state of the system be (x, ẋ, θ, θ̇) ∈ ℝ4 as in the part on neuroevolution: x is the position of the cart (m), ẋ its velocity (m/s), θ the angle of the pole from the vertical (in degrees, positive to the right) and θ̇ the angular velocity (°/s); the loop step is Δt = 0.02 s. Let L = {negative, zero, positive} be the set of terms. The controller is determined by the following data:

  1. terms of the angle θ: μzero is the triangle (−6, 0, 6), μpositive the trapezoid (0, 6, 90, 90) — it rises from 0° to 6° and is 1 beyond that —, μnegative its mirror image, the trapezoid (−90, −90, −6, 0);
  2. terms of the angular velocity θ̇: the same shapes with 40 instead of 6 and 900 instead of 90;
  3. for every pair of terms a, b ∈ L (a for the angle, b for the velocity) a rule with firing strength wab = min(μa(θ), μb(θ̇)) and constant conclusion cab ∈ {−10, −5, 0, 5, 10} N from the table above;
  4. the force on the cart F(θ, θ̇) = max(−10, min(10, ∑a, b ∈ L wab cab/∑a, b ∈ L wab)) N, i.e. the output of a zero-order Sugeno controller clipped to [−10, 10] N (if all firing strengths were zero, F = 0).
Example — a pole tilted by 2° and falling to the right at 10 °/s

Angle: zero(2) = 6 − 2/6 = 2/3, positive(2) = 2/6 = 1/3. Velocity: zero(10) = 40 − 10/40 = 0.75, positive(10) = 10/40 = 0.25. The negative terms are 0, so four rules hold (colours as in the Takagi–Sugeno formula above: w plays the role of αi, c the role of fi):

  • upright and still: w = min(2/3, 0.75) = 2/3, conclusion 0 N,
  • upright and falling right: w = min(2/3, 0.25) = 0.25, conclusion +5 N,
  • right and still: w = min(1/3, 0.75) = 1/3, conclusion +5 N,
  • right and falling right: w = min(1/3, 0.25) = 0.25, conclusion +10 N.

F = 2/3 · 0 + 0.25 · 5 + 1/3 · 5 + 0.25 · 10/2/3 + 0.25 + 1/3 + 0.25 = 5.417/1.5 ≈ 3.61 N

The force is positive, so it points to the right — the cart moves under the pole.

pole only (zero-order Sugeno) 22.0 s pole and cart (first-order Sugeno) 24.0 s+
Fuzzy pendulum controller: the first 24 seconds

The pole stays up — after a few seconds the angle is practically zero. But the cart slowly drifts away, because the rules say nothing about the cart, and after 22 seconds it runs off the track. From the three starts of the part on neuroevolution the controller lasted 22, 12.9 and 15.7 s.

We fix this with a first-order Sugeno controller: to each constant in the table we add 1 · x + 2 · ẋ, where x is the position of the cart and ẋ its velocity. Now the controller holds the pole from all three starts for a whole minute, and the cart moves at most 0.58 m from the centre. The sign is the interesting part: when the cart drifts to the right, the controller pushes it even further right. That tilts the pole to the left — and the rules about the pole then bring the cart back. The “intuitive” opposite signs, which would push the cart straight towards the centre, knock the pole over within five seconds. The rules of an experienced operator are valuable precisely because they encode experience a layperson would not come up with.

F = ∑ wab cab/∑ wab + kx x + kv ẋ

F
the force on the cart (before clipping to ±10 N)
∑ wab cab/∑ wab
the original zero-order Sugeno — nine rules about the pole; it keeps the pole upright and knows nothing about the cart
kx x
the response to the cart’s position, kx = 1 N/m — without it the cart would run off the track unpunished; the positive sign seemingly sends the cart outwards, but in doing so it tilts the pole inwards, and the rules about the pole then bring the cart back
kv ẋ
the response to the cart’s velocity, kv = 2 N·s/m — damping; with the position alone (kv = 0) the cart oscillates around the centre more and more and, from all three starts, runs off the track within 32 to 53 s
Why the linear part can be factored out: every conclusion is cab + kxx + kvẋ with the same k, and the weighted average of the constant kxx + kvẋ is that constant itself (the weights sum to 1).

In the example above, with the cart 0.3 m to the right and moving at 0.1 m/s to the right, we therefore get F = 3.61 + 1 · 0.3 + 2 · 0.1 ≈ 4.11 N (colours as in the formula above).

7. Mamdani or Sugeno?

MamdaniSugeno
Rule conclusiona fuzzy set (“fast”)a number or a linear function
Outputdefuzzification, usually the centroidweighted average
Computationan integral over the outputa few multiplications
Readabilityrules read like sentencesnumbers in the conclusions
Ends of the rangethe centroid never reaches themreaches them
Learning from datadifficultthe parameters of the conclusions can be tuned — see ANFIS

Mamdani suits places where the rules are written and read by people. Sugeno suits places where computation speed matters and where we want to tune the controller from measured data — which is the subject of the last part of the module.

8. Fuzzy controllers in practice

  • The cement kiln of the Danish company F. L. Smidth was, around 1980, one of the first industrial deployments — the kiln is hard to model, but operators ran it from experience.
  • The Sendai subway (1987) accelerates and brakes according to fuzzy rules; the ride is smoother, and the manufacturer also reported energy savings.
  • Appliances. Around 1990 Japanese companies offered washing machines that chose a programme based on the turbidity of the water and the amount of laundry, and cameras with fuzzy focusing and image stabilization.
  • Today most industrial control is handled by PID controllers and model predictive control. Fuzzy rules are used rather “on top of them” — switching settings according to the operating mode — and wherever it is more valuable to write down experience quickly than to build an exact model.

9. Summary

  • A fuzzy controller has three steps: fuzzification, rule-based inference and defuzzification.
  • Defuzzification turns the output fuzzy set into a number; for the fan the centroid gives 65.9 %, the bisector 75.3 % and the mean of maxima 85.9 %.
  • Sugeno has numbers or linear functions in its conclusions, and the output is a weighted average — 72.7 % for the same input, without an integral.
  • The control surface shows the whole controller at once; the centroid never reaches the ends of the range.
  • Nine rules about the pole keep it up, but the cart drifts away; a first-order Sugeno controller with the position and velocity of the cart keeps both for a whole minute.

Want to get your hands on it? Have an AI agent write a fuzzy thermostat for a simulated room with delayed heating, and see how many rules it takes to keep the temperature from oscillating.

Do you see it differently? Write to support@coden-app.com.

An Agent on your computer, driven from your phone