The idea: rules in words, numbers in and out
A fan should run faster when the room is hot or humid. A person can say that in words, but a controller needs numbers. Fuzzy inference is the bridge. In ordinary logic a temperature is either "warm" or not. In fuzzy logic it is warm to a degree between 0 and 1. The page shows the most common design, a Mamdani controller. It takes two crisp (exact) inputs, temperature T and humidity H, and gives one crisp output, the fan speed S. In between it works in four steps: fuzzify, fire the rules, clip and aggregate, defuzzify.
The controller on this page has three rules:
| rule | if | then | strength |
|---|---|---|---|
| R1 | temp is cold | fan is low | cold |
| R2 | temp is warm AND air is dry | fan is medium | min(warm, dry) |
| R3 | temp is hot OR air is humid | fan is high | max(hot, humid) |
Membership functions: triangles and trapezoids
A fuzzy set such as "warm" is described by a membership function μ. For every value x it gives the degree of membership μ(x): 0 means not in the set, 1 means fully in, and anything between means partly in. Almost all controllers use two simple shapes. A triangle (a, b, c) rises from 0 at a to 1 at b and falls back to 0 at c. A trapezoid (a, b, c, d) has a flat top: it is 1 from b to c. The sets at the two ends of an axis are trapezoids that stay at 1 to the edge, often called shoulders: anything below 10 °C is fully cold.
| variable | set | shape | corners |
|---|---|---|---|
| temperature T, 0–40 °C | cold | trapezoid (left shoulder) | 0, 0, 10, 20 |
| warm | triangle | 10, 20, 30 | |
| hot | trapezoid (right shoulder) | 20, 30, 40, 40 | |
| humidity H, 0–100 % | dry | trapezoid (left shoulder) | 0, 0, 30, 70 |
| humid | trapezoid (right shoulder) | 30, 70, 100, 100 | |
| fan speed S, 0–100 % | low | triangle, peak at 0 | 0, 0, 50 |
| medium | triangle | 25, 50, 75 | |
| high | triangle, peak at 100 | 50, 100, 100 |
Step 1: fuzzify
Fuzzification reads each crisp input on every set of its axis. At T = 24 °C the line is on the falling side of warm, so warm = (30 − 24) / 10 = 0.60, and on the rising side of hot, so hot = (24 − 20) / 10 = 0.40. Cold is 0. At H = 40 %, dry = (70 − 40) / 40 = 0.75 and humid = (40 − 30) / 40 = 0.25. Neighbouring sets overlap on purpose, so one value usually belongs to two sets at once (Demo: the four steps, T = 24 °C, H = 40 %). These degrees are not probabilities: 24 °C is not "warm with a 60 % chance". It is simply warm to degree 0.60.
Step 2: fire the rules with min and max
Each rule gets a firing strength from the degrees of its premises. AND takes the minimum: a rule is only as true as its weakest premise. OR takes the maximum: one strong premise is enough. With degrees of exactly 0 and 1 these give the ordinary truth tables, so fuzzy logic contains ordinary logic as a special case. For the inputs above, R2 = min(0.60, 0.75) = 0.60 and R3 = max(0.40, 0.25) = 0.40. R1 has strength 0 and does not fire. Unlike crisp rules, several rules fire at the same time, each to its own degree.
At T = 20 °C the room is fully warm, but at H = 60 % the air is dry only to 0.25, so R2 = min(1, 0.25) = 0.25 (Demo: AND takes the min). At T = 28 °C and H = 60 %, R3 = max(0.80, 0.75) = 0.80 (Demo: OR takes the max).
See also Truth Tables and Sets for AND and OR on crisp values, and Forward vs Backward Chaining for if-then rules that are simply true or false.
Step 3: clip and aggregate
A rule's conclusion is a fuzzy set too ("fan is medium"). The rule's strength limits it: the output set is clipped, cut off flat, at that height. A triangle clipped at 0.60 becomes a trapezoid of height 0.60. This is implication by min, the choice that makes a controller a Mamdani controller. Then the clipped sets of all rules are aggregated into one shape by taking, at every speed s, the largest of them (max). The result is a fuzzy set that says how much each fan speed is supported by the rules together.
Rules can pull in opposite directions. At T = 5 °C and H = 80 % the room is fully cold (R1 = 1, fan low) and fully humid (R3 = 1, fan high). Both output sets are kept whole and the aggregate has two peaks (Demo: two rules disagree, cold but humid).
Step 4: defuzzify with the centroid
The fan needs one number. The usual choice is the centroid (centre of gravity) of the aggregated shape: the point on the axis where the shape would balance. The page computes it at the 101 whole speeds 0, 1, …, 100:
For T = 24 °C and H = 40 % the sums are 2077.6 / 33.04, so the fan runs at 62.9 %. When two rules disagree fully the shape is symmetric and the centroid is the compromise, exactly 50.0 %. The centroid also has a limit: at T = 35 °C only R3 fires, with strength 1, and the answer is the centroid of the whole "high" triangle, 83.7 %, not 100 % (Demo: one rule at full strength, still not 100 %). In the same way the lowest speed this controller can give is 16.3 %. Designers fix this by placing the outer output sets beyond the range they want to reach.
| demo inputs | R1 low | R2 medium | R3 high | fan speed |
|---|---|---|---|---|
| T = 24 °C, H = 40 % | 0 | min(0.60, 0.75) = 0.60 | max(0.40, 0.25) = 0.40 | 62.9 % |
| T = 20 °C, H = 60 % | 0 | min(1, 0.25) = 0.25 | max(0, 0.75) = 0.75 | 73.6 % |
| T = 28 °C, H = 60 % | 0 | min(0.20, 0.25) = 0.20 | max(0.80, 0.75) = 0.80 | 75.4 % |
| T = 5 °C, H = 80 % | 1 | min(0, 0) = 0 | max(0, 1) = 1 | 50.0 % |
| T = 35 °C, H = 20 % | 0 | min(0, 1) = 0 | max(1, 0) = 1 | 83.7 % |
Why bother: a smooth control curve
A controller with crisp rules ("below 15 °C run at 20 %, up to 25 °C at 50 %, above that at 85 %") jumps at each threshold, so the fan changes speed with a jolt and may flip back and forth when the temperature sits near a border. In the fuzzy controller the sets overlap, so as the temperature rises one rule fades out while the next fades in, and the centroid slides across. At H = 40 % the speed goes 35.1 → 43.4 → 58.5 → 65.7 → 83.7 → 83.7 % for T = 10, 15, 20, 25, 30, 35 °C (Demo: sweep the temperature, the fan speeds up smoothly). The rules stay readable, and tuning the controller means moving corner points of the sets.
A learned set of crisp thresholds is what Decision Tree Learning builds. For reasoning with probabilities, which measure how likely something is and not how much it belongs to a set, see Bayesian Network Inference.
What the page leaves out
Real controllers often have more inputs (for example the error and its rate of change), 5 or 7 sets per variable and a full rule table, and they run the four steps again at every sample time. The page shows only min and max; other choices exist, such as product for AND, scaling the output set by the strength where the page clips it, and adding where the page takes the max. Other defuzzifiers are the bisector, the mean of maxima and the weighted average. A Sugeno (TSK) controller replaces the output sets with constants or linear functions, so step 4 is a simple weighted average. The page also skips smooth shapes such as Gaussian and bell membership functions, rule weights, NOT (1 − μ), and how sets and rules are tuned or learned from data (ANFIS). The centroid here is a sum over 101 points; an exact integral gives slightly different last digits.