Mamdani fan controller
An old-school rule of thumb, wired up as a fuzzy controller: if it's hot and humid, run the fan hard; if it's cold, leave it off. Two crisp inputs get fuzzified into overlapping term sets, seven rules fire with varying strength, the output terms get clipped and aggregated, and the centroid of that aggregated shape is the crisp fan speed.
Math runs server-side through Fugue.Fuzzy
(ported from Hazy, the Haskell fuzzy-logic library this used to call out to
over HTTP). Drag the sliders to watch the rule firings, output shape, and
defuzzified crisp value respond.
A full Mamdani controller: fuzzify, fire every rule, clip each consequent, aggregate the envelope, then defuzzify by centroid. The rule set is plain data, so changing a rule doesn't mean changing any code. -> mamdani.ex
Top row shows each input fuzzified into its term set, with a dashed crisp line and dots marking the degree of membership at that input. Middle shows each rule's firing strength, colored by the fan speed term it votes for. Bottom layers each rule's clipped consequent underneath the aggregated envelope; the white marker is the centroid.
source fugue