Skip to content
Tutorials Center
My learning

Topics

Lesson 18 of 36 ยท Fuzzy Inference

Defuzzification Methods

Compare defuzzification methods that turn a fuzzy output set into one number: centroid, bisector, mean, smallest and largest of maximum, and weighted average, with Python code and when to use each.

A Mamdani system ends with a fuzzy set: a curve over the output universe that says, for every possible output value, how well it is supported by the rules. A heater, a valve or a bank clerk needs one number. Defuzzification is the step that picks it. There is no single correct method; each answers "what is the best single representative of this curve?" differently. In this lesson you will implement the standard methods, compare their answers on the same set and learn how to choose.

The set we will defuzzify

Every example below uses one aggregated output set: the union of "medium" clipped at 0.7 and "high" clipped at 0.5 over a 0 to 25 percent tip. It has a long plateau at 0.7 and a lower plateau at 0.5 further right.

flowchart LR
    A["Rules fire<br/>medium 0.7, high 0.5"] --> B["Aggregated fuzzy set"] --> C["Defuzzifier"] --> D["One crisp number"]

The defuzzifier reads the whole aggregated set and returns a single value.

The main methods

Let y be points of the output universe and mu(y) the aggregated membership.

  • Centroid (centre of gravity, COG, centre of area): the balance point of the area under the curve, sum(y * mu) / sum(mu). The most common method; all rules influence the result, and it changes smoothly.
  • Bisector: the value that splits the area into two equal halves.
  • Mean of maximum (MOM): the average of the points where mu reaches its maximum.
  • Smallest of maximum (SOM) and largest of maximum (LOM): the leftmost and rightmost point of the maximum plateau.
  • Weighted average of peaks (height method): take each rule's output peak position and weight it by the rule's firing strength. It needs no set aggregation at all and is nearly the same as a zero-order Sugeno system (Sugeno Inference).
Python Five defuzzifiers on one set

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The centroid and bisector land close together, near the middle of the mass. The maximum-based methods ignore the second rule almost completely: they only look at the highest plateau, which belongs to "medium". The height method uses only two peak positions and gives a number higher than the centroid because it treats each rule's output as a point at its peak.

Smoothness: why the centroid is the default

Plot the output as an input slowly changes and you see the difference between methods. In the next experiment the strength of the "medium" rule stays at 0.6 while the strength of "high" rises from 0 to 1. A good controller output rises gradually. Maximum-based methods jump the moment the second plateau becomes the highest.

Python Sweeping a rule strength

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The centroid column climbs steadily. The mean-of-maximum column stays put until w_high passes 0.6 and then jumps to the right: a tiny change in the strength of a rule produces a sudden change in the output, which is exactly the instability fuzzy logic is supposed to avoid. For this reason, MOM and its relatives are used only when you want a decisive choice (for example, in classification-like decisions or when the output must be one of the "real" output values and not a blend).

A trap: the centroid can land where the set is zero

Suppose the output set is two separate peaks: "turn left" and "turn right", with almost equal strength. The centroid lies exactly between them, at "go straight", which may be the worst possible action (an obstacle is straight ahead). The same problem appears whenever the aggregated set is multimodal and the output must be one of the alternatives.

Python Centroid between two peaks

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

When this matters, use a maximum-based method, or redesign the rules (for example, add an obstacle input) so that the output is no longer bimodal.

Choosing a method

Method Smooth? Uses all rules? Cost Typical use
Centroid Yes Yes Medium Default for control and decision support
Bisector Yes Yes Medium Alternative to centroid
MOM / SOM / LOM No Only the strongest Low Classification-like decisions, safety-critical choices
Height (weighted peaks) Yes Yes Very low Embedded systems, Sugeno-style

Three practical hints:

  1. Fix the resolution: sample the output universe with 100 to 1000 points; too coarse a grid makes the centroid wobble.
  2. Handle the empty set: if no rule fires, mu.sum() is 0 and the centroid is undefined; return a safe default or raise an error.
  3. Remember the edges: because the centroid is an average, it can never reach the ends of the output range unless the set is a singleton there (a tip can never reach exactly 25 % even for the best input). Widen the output universe a bit or use shoulder sets if you need to reach the limits.

Tip: In a real project, test the whole input range and plot the output curve. If the curve has wiggles or jumps, look at the defuzzification method and the overlap of the output terms before touching the rules.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What does the centroid method compute?

    The centroid is sum(y * mu) / sum(mu), the centre of gravity of the area.
  2. 2. Which method returns the average of the points where the membership is maximal?

    MOM averages all points of the highest plateau.
  3. 3. Why can mean of maximum make a controller output jump?

    Only the maximum region counts, so a small change can move the maximum to a different place.
  4. 4. Two equally strong output peaks, left and right, produce a centroid in the middle. When is that a problem?

    The centroid blends alternatives; for choices that cannot be blended use a maximum-based method or redesign the rules.
  5. 5. What should you do if no rule fires?

    With an empty aggregated set the centroid divides by zero, so the system needs an explicit fallback.

Summary

  • Defuzzification converts the aggregated output set into one crisp number.
  • Centroid and bisector use the whole set and vary smoothly; MOM, SOM and LOM use only the maximum plateau and can jump.
  • The height method weights rule peaks by firing strength and is very cheap.
  • Centroids can fall between two alternatives and give a bad compromise.
  • Use a fine output grid, handle the empty set and test the full input range.

Next: The Architecture of a Fuzzy Controller