Defuzzification¶
A defuzzifier collapses the aggregated output set into a crisp value. Select by
name in a Mamdani system (fz.Mamdani(defuzz=...)) or call the functions
directly from fuzzytool.defuzz.
| Name | Method |
|---|---|
centroid |
center of gravity (default) |
bisector |
splits the area into two equal halves |
mom |
mean of maxima |
som |
smallest of maxima |
lom |
largest of maxima |
wtaver / height |
weighted average Σ x·y / Σ y |
coa |
center of the largest contiguous area |
Two of these are worth knowing about specifically.
wtaver treats the samples as discrete weighted points instead of
integrating the area. It is cheaper than centroid and insensitive to uneven
sampling of the universe.
coa exists for a failure mode centroid has: when aggregation leaves two
separated humps, the centroid lands in the valley between them — a value no rule
ever supported. coa keeps only the widest connected region of positive
membership and takes its centroid, so the answer is always something a rule
actually argued for.
from fuzzytool import defuzz
import numpy as np
x = np.linspace(0, 30, 501)
y = np.maximum(0, 1 - np.abs(x - 20) / 10)
defuzz.centroid(x, y) # ~20
A custom defuzzifier is any callable (x, y) -> float; pass it directly:
When no rule fires the output set is empty; the crisp value is then chosen by the
Mamdani system's on_no_rule policy rather than
by the defuzzifier.