Vagueness and fuzzy sets
Week 3 ended with a weakness of crisp rules: A threshold of 70 degrees makes a reading of 69.9 normal and a reading of 70.1 overheated. Engineers rarely think in such steps. A temperature is more or less high, a load is fairly heavy, a surface is quite rough. Zadeh proposed fuzzy sets to represent such graded concepts [1]. A fuzzy set A on a universe of discourse X is defined by a membership function that assigns every element x a degree between 0 and 1. A room at 23 degrees may belong to the set of comfortable rooms with degree 0.6 and to the set of warm rooms with degree 0.125.
Vagueness is not probability. A membership degree of 0.6 does not say that the room is comfortable with probability 0.6. It says that 23 degrees fits the concept "comfortable" to degree 0.6, and there is nothing random about it. Probability describes uncertainty about whether an event happens; fuzzy membership describes how well a precisely known value fits an imprecise concept. The two can be combined, but they answer different questions.
Common membership functions are triangular, defined by a left foot, a peak and a right foot; trapezoidal, with a flat top; and Gaussian, with a centre and a width. The support of a fuzzy set is where its membership is positive, the core is where it equals one, and an alpha-cut is the crisp set of elements whose membership is at least alpha. A linguistic variable, such as tank level, takes linguistic values, such as low, okay and high, each represented by a fuzzy set on the same universe [2].

Check your understanding. A water temperature of 58 degrees has membership 0.7 in the fuzzy set "hot". What does this mean?
Formulas: Membership functions
A fuzzy set on a universe of discourse , for example the room temperatures from 0 to 40 degrees, is defined by a membership function
that gives every element a degree of membership between 0 and 1 [1]. The Greek letter mu, , is the usual symbol. A crisp set is the special case in which is either 0 or 1. Three shapes are common. A triangular set with left foot , peak and right foot rises linearly from to and falls linearly from to :
The first fraction is the rising side, the second the falling side, the minimum picks the side on which lies, and the maximum with 0 sets the membership to zero outside the feet. When , the rising side is replaced by 1 and the set becomes a left shoulder, which keeps full membership at the low end of the universe; gives a right shoulder. A trapezoidal set has a flat top from to :
A Gaussian set with centre and width (sigma) is smooth everywhere:
Three crisp sets describe a fuzzy set. The support holds the elements with positive membership, the core those with full membership, and the alpha-cut those with membership of at least :
Worked example: How warm is a room at 23 degrees?
Figure 4.1 and the notebook use three triangular sets on the room temperature: cool , comfortable and warm , each written as (left foot, peak, right foot).
Step 1. Cool. The value 23 lies above the right foot 20, so the falling side is negative, , and the maximum with 0 gives .
Step 2. Comfortable. Both sides are evaluated and the smaller one is kept:
Step 3. Warm.
The room is comfortable to degree 0.6 and warm to degree 0.125, while the crisp set "warm" of Figure 4.1, the interval from 22 to 30 degrees, would give it full membership.
Step 4. Other shapes. A Gaussian set "comfortable" with centre 21 and width 2.5, as in the notebook, gives
and a trapezoidal set with feet 16 and 26 and a flat top from 20 to 22 gives
Step 5. Support, core and alpha-cut of the triangular set "comfortable". The support is the open interval from 16 to 26, and the core is the single temperature 21. For , the rising side reaches 0.5 where , that is at , and the falling side where , at . The alpha-cut is the interval from 18.5 to 23.5 degrees.
Operations on fuzzy sets
The classical set operations generalise. The complement NOT A has membership 1 minus the membership of A. The intersection A AND B is usually computed with the minimum of the two memberships, and the union A OR B with the maximum [1]. Other choices are possible: The product is also a valid intersection, called a t-norm, and the probabilistic sum a + b - ab is a valid union, called an s-norm. The choice changes the smoothness of the resulting controller but not the principle. Some classical laws fail on purpose: A AND NOT A need not be empty, because a temperature can be somewhat warm and somewhat not warm at the same time.
Formulas: Complement, intersection and union
For fuzzy sets and on the same universe, the standard operations of Zadeh work point by point [1]:
For degrees of 0 and 1 they reproduce the truth tables of Week 3. The minimum is one member of a family of intersections called t-norms, functions of two degrees that are commutative, associative, non-decreasing in each argument and satisfy . The product is another t-norm. Every t-norm has a matching union, its s-norm, obtained through the complement:
For the minimum this gives the maximum. For the product it gives the probabilistic sum,
With these pairs the laws of De Morgan hold, for example , whereas the law of contradiction does not: is zero only when is 0 or 1 [1, 3].
Worked example: Combining the two memberships of the room
At 23 degrees the room is comfortable with and warm with .
Step 1. Complements. Not warm: . Not comfortable: .
Step 2. Comfortable and warm. With the minimum, . With the product, .
Step 3. Comfortable or warm. With the maximum, . With the probabilistic sum, .
Step 4. De Morgan. On the left side, . On the right side, . The two sides agree.
Step 5. A set and its complement. Comfortable and not comfortable: , not 0. Comfortable or not comfortable: , not 1. The room is partly comfortable and partly not, which is exactly the vagueness the fuzzy set expresses. Part A of the interactive lab evaluates triangular, trapezoidal and Gaussian sets and these operations for any input.
Mamdani inference
A fuzzy rule has linguistic conditions and a linguistic conclusion: IF level error is low AND level rate is none THEN valve change is open fast. Mamdani inference evaluates a rule base in five steps [4, 5]. First, fuzzification computes the membership of each crisp input in each of its fuzzy sets. Second, each rule receives a firing strength, the minimum of the memberships in its conditions. Third, implication clips the output fuzzy set of each rule at its firing strength. Fourth, aggregation combines the clipped sets of all rules with the maximum. Fifth, defuzzification turns the aggregated fuzzy set into one crisp output, most often with the centroid, the centre of gravity of the area under the aggregated membership function.
Animation: Inside a Mamdani controller
Move the two inputs of a tank level controller. The bars show fuzzification, the clipped shapes show the rules that fire, and the vertical line marks the centroid that becomes the valve command.
The controller defined by a rule base is a nonlinear function from inputs to output, and its control surface can be drawn for two inputs. Overlapping membership functions make the surface smooth; more sets and rules add detail. A rule table, with one input along the rows and the other along the columns, is the usual design tool: Every cell holds the conclusion for one combination of linguistic values, and gaps in the table leave parts of the input space without any action. Symmetry of the table usually leads to symmetric behaviour of the loop.
Check your understanding. Two rules fire with strengths 0.3 and 0.8 and conclude "open slow" and "open fast". What happens in Mamdani inference before defuzzification?
Formulas: The five steps of Mamdani inference
Consider rules with two inputs, IF is AND is THEN is , for , and crisp inputs and [4, 5].
1. Fuzzification computes the memberships and of the inputs in every set used by the rules.
2. Firing strength. The AND of a rule is the minimum of its memberships:
3. Implication clips the output set of each rule at its firing strength:
4. Aggregation joins the clipped sets of all rules with the maximum:
5. Defuzzification by the centroid returns the centre of gravity of the area under . On a grid of output values the integrals become sums:
The integral sign adds up infinitely many thin strips; the sum on the right adds up the values at the grid points, and a finer grid brings it closer to the integral.
Worked example: The tank level controller of the animation
The controller of the animation and the notebook has the level error (set point minus level, in metres) and the level rate (in metres per second) as inputs and the change of the valve opening per second as output. Its sets, written as (left foot, peak, right foot), are high , okay and low for the error; negative , none and positive for the rate; and close fast , close slow , no change , open slow and open fast for the output. The five rules are: R1 IF is low THEN open fast; R2 IF is high THEN close fast; R3 IF is okay AND is none THEN no change; R4 IF is okay AND is positive THEN close slow; R5 IF is okay AND is negative THEN open slow. The inputs are m, the level is a quarter of a metre below the set point, and m/s, the level is rising.
Step 1. Fuzzification of the error.
Step 2. Fuzzification of the rate.
Step 3. Firing strengths. R1: . R2: . R3: . R4: . R5: . Rules R2 and R5 do not fire.
Step 4. Implication on a grid. The output universe from to is sampled every 0.01, which gives 15 grid points. Close slow is positive at three of them: at , 1 at and at . Clipped at , all three become . No change is positive at with , at 0 with 1 and at 0.01 with ; clipped at these become 0.1667, 0.3333 and 0.1667. Open fast is positive at 0.04 with , at 0.05 with 1 and at 0.06 with ; clipped at all three become 0.25.
Step 5. Aggregation and the products for the centroid. The column holds the maximum of the three clipped sets; at , for example, .
| close slow | no change | open fast | |||
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | ||
| 0 | 0 | 0 | 0 | ||
| 0 | 0 | 0 | 0 | ||
| 0 | 0 | 0 | 0 | ||
| 0.2 | 0 | 0 | 0.2 | ||
| 0.2 | 0 | 0 | 0.2 | ||
| 0.2 | 0.1667 | 0 | 0.2 | ||
| 0 | 0.3333 | 0 | 0.3333 | ||
| 0 | 0.1667 | 0 | 0.1667 | ||
| 0 | 0 | 0 | 0 | ||
| 0 | 0 | 0 | 0 | ||
| 0 | 0 | 0.25 | 0.25 | ||
| 0 | 0 | 0.25 | 0.25 | ||
| 0 | 0 | 0.25 | 0.25 | ||
| 0 | 0 | 0 | 0 |
Step 6. Centroid.
The valve opens by about 0.0147 of its range per second: The level is low, which calls for opening, and the rising level holds the action back. The grid of 15 points is coarse. A grid every 0.005, with 29 points, gives 0.0177, and the 561 points of the notebook give 0.0169, the value that the integral approaches. Part B of the interactive lab repeats all steps for any inputs and grid.
Takagi-Sugeno models and learning fuzzy systems
Takagi and Sugeno replaced the fuzzy conclusion by a function of the inputs: IF x is A AND y is B THEN z = p x + q y + r [6]. The output is the average of the rule outputs weighted by their firing strengths, so no defuzzification of a shape is needed. A zero-order Sugeno model has constant conclusions and behaves much like a Mamdani model with narrow output sets; a first-order model blends local linear models, which makes it attractive for modelling and for gain scheduling of controllers.
Because the Sugeno output is a differentiable function of its parameters, the parameters can be learned from data. ANFIS represents a Sugeno system as a five-layer adaptive network and trains the premise parameters with gradient descent and the linear consequent parameters with least squares [7]. Metaheuristic training is an alternative when gradients are unreliable: In one study, ANFIS supported by the vortex optimisation algorithm forecast chaotic electroencephalogram time series [8]. Such neuro-fuzzy systems link this week to the optimisation of Weeks 5 and 6 and to the neural networks of Week 10.
Check your understanding. What distinguishes a first-order Takagi-Sugeno rule from a Mamdani rule?
Formulas: Takagi-Sugeno models and ANFIS
A first-order Takagi-Sugeno rule has a linear function as its conclusion [6]:
A zero-order rule has a constant conclusion, . The firing strength is computed as in Mamdani inference, with the minimum or with the product of the memberships, and the output is the weighted average of the rule outputs:
The normalised strengths add up to one. ANFIS computes the same output with a five-layer network: Layer 1 evaluates the membership functions, layer 2 multiplies them into the strengths , layer 3 normalises them, layer 4 forms , and layer 5 adds these up [7]. Its hybrid learning rule uses two facts. First, once the membership functions are fixed, is linear in the consequent parameters, so these follow from a least-squares fit to the training pairs . Second, the membership parameters, such as the centre of a Gaussian set, are improved by gradient descent on the squared error with a learning rate (eta):
The symbol is the partial derivative, the rate at which changes when only changes. For two rules with Gaussian sets of width , the chain rule gives
because changes by per unit of , and changes by per unit of .
Worked example: A zero-order Sugeno version of the tank controller
Replacing each output set of the controller by its peak gives the constants close fast , close slow , no change 0, open slow 0.02 and open fast 0.05. With the firing strengths of the Mamdani example, :
The Sugeno controller needs no output shapes and no grid, and its output, 0.010852, is close to the Mamdani centroid of 0.0169. The difference comes from the widths and overlaps of the Mamdani output sets.
Worked example: One learning cycle of a small ANFIS
A sensor has the input and the measured output at three points, , and . A model with two zero-order rules, IF is small THEN and IF is large THEN , uses Gaussian sets with centres and and width , so that .
Step 1. Layers 1 to 3 for each training point. For : and . All three points:
| 2 | 3 | 0.867036 | 0.132964 | ||
| 5 | 5 | 0.5 | 0.5 | ||
| 8 | 8 | 0.132964 | 0.867036 |
For , for example, .
Step 2. Least squares for the consequents. The model output is . Setting the derivatives of with respect to and to zero gives the normal equations
The sums over the three points are
Cramer's rule solves the two equations with the determinant
The fitted outputs are 2.833325, 5.333334 and 7.833342 for the targets 3, 5 and 8.
Step 3. One gradient step for the centre at the first point. At the error is . The factors of the chain rule are , and :
With the centre moves to . The step is small because the first rule already fits this point well. ANFIS repeats such least-squares and gradient steps over all points until the error stops falling [7]. Part C of the interactive lab runs these cycles on editable data.
Fuzzy control in engineering
The first industrial success was the control of a cement kiln in Denmark, where operators' rules for burning zone temperature and oxygen were encoded as fuzzy rules [9]. The Sendai subway in Japan used predictive fuzzy control for automatic train operation, which improved riding comfort and stopping accuracy [10]. Fuzzy controllers later appeared in washing machines, cameras, heating systems, water treatment dosing and vehicle subsystems, and textbooks collect applications across civil, mechanical, chemical and electrical engineering [3].
Fuzzy control is most useful when a good mathematical model is missing but operator experience exists, when the process is nonlinear, and when smooth, explainable behaviour matters. It does not remove the need for analysis: Stability, robustness to disturbances and the effect of measurement noise must still be checked, for example by simulation over the operating range, as in the notebook. When a reliable model exists, classical or model-based control is often the better engineering choice.
Formulas: The tank under fuzzy control
The tank of the notebook and the lab has the cross-section m². The inflow is with the valve opening between 0 and 1 and m³/s, and the outflow through the outlet follows Torricelli's law, with . The mass balance gives the rate of change of the level :
The level is steady when inflow and outflow are equal, which requires the valve opening
The fuzzy controller does not set the valve directly: It sets the change of the opening per second, , so that in each time step of length
where the opening is kept between 0 and 1. The level equation is the Euler step of Week 1.
Worked example: The first control step after a change of the set point
The tank is at m with , which is steady, because . The set point now jumps to 1.5 m.
Step 1. The target opening. To hold 1.5 m the valve must reach .
Step 2. The inputs of the controller. The error is m, and the level does not move yet, so .
Step 3. Fuzzification and rules. For the error, and ; for the rate, . Only R1 fires, with ; R3 gets .
Step 4. Defuzzification. The aggregated set is open fast clipped at 0.5, a trapezoid that is symmetric about the peak 0.05, so its centroid is per second.
Step 5. One time step of s.
The level starts to rise. As it approaches the set point the error enters the set okay, rules R3 and R4 take over and the valve settles near 0.7348. Part D of the interactive lab simulates the whole response.
Python step 4: NumPy arrays and first plots
The Python step of this week is part of the Colab notebook, where every explanation stands next to a cell that runs it and the step closes with a quick check and exercises with immediate feedback. The printable lecture notes contain the same step together with the outputs of its code. The Colab button below opens the notebook at the step. Run the setup cell just above the step first, since the exercises use its check function.
Review cards
Select a card to turn it over.
Continue the week
The week continues with the simulation and the self-assessment of the interactive lab and with the Python step and the hands-on work of the Colab notebook. The week overview lists the discipline challenges, the weekly task and the research assignment.
Interactive lab Colab notebook Self-assessment Week overview and tasks
References
[1] Zadeh, L. A. (1965). Fuzzy sets. Information and Control, 8(3), 338-353. https://doi.org/10.1016/S0019-9958(65)90241-X
[2] Zadeh, L. A. (1973). Outline of a new approach to the analysis of complex systems and decision processes. IEEE Transactions on Systems, Man, and Cybernetics, SMC-3(1), 28-44. https://doi.org/10.1109/TSMC.1973.5408575
[3] Ross, T. J. (2017). Fuzzy Logic with Engineering Applications (4th ed.). Wiley.
[4] Mamdani, E. H., & Assilian, S. (1975). An experiment in linguistic synthesis with a fuzzy logic controller. International Journal of Man-Machine Studies, 7(1), 1-13. https://doi.org/10.1016/S0020-7373(75)80002-2
[5] Lee, C. C. (1990). Fuzzy logic in control systems: Fuzzy logic controller, Part I. IEEE Transactions on Systems, Man, and Cybernetics, 20(2), 404-418. https://doi.org/10.1109/21.52551
[6] Takagi, T., & Sugeno, M. (1985). Fuzzy identification of systems and its applications to modeling and control. IEEE Transactions on Systems, Man, and Cybernetics, SMC-15(1), 116-132. https://doi.org/10.1109/TSMC.1985.6313399
[7] Jang, J.-S. R. (1993). ANFIS: Adaptive-network-based fuzzy inference system. IEEE Transactions on Systems, Man, and Cybernetics, 23(3), 665-685. https://doi.org/10.1109/21.256541
[8] Kose, U., & Arslan, A. (2017). Forecasting chaotic time series via ANFIS supported by vortex optimization algorithm: Applications on electroencephalogram time series. Arabian Journal for Science and Engineering, 42(8), 3103-3114. https://doi.org/10.1007/s13369-016-2279-z
[9] Holmblad, L. P., & Østergaard, J.-J. (1982). Control of a cement kiln by fuzzy logic. In Fuzzy Information and Decision Processes (M. M. Gupta & E. Sanchez, Eds.) (pp. 389-399). North-Holland.
[10] Yasunobu, S., & Miyamoto, S. (1985). Automatic train operation system by predictive fuzzy control. In Industrial Applications of Fuzzy Control (M. Sugeno, Ed.) (pp. 1-18). North-Holland.