Ultralytics YOLO27: Join the waitlist.
License YOLO
Back to Ultralytics Glossary

Fuzzy Logic

Fuzzy logic assigns truth values between 0 and 1, so rule-based systems can reason with vague terms like warm or near. Covers controllers and code.

Fuzzy logic is a form of many-valued logic in which a statement can be partly true, with a degree of truth anywhere from 0 to 1 instead of only true or false. It grew out of Lotfi Zadeh's 1965 paper on fuzzy sets at the University of California, Berkeley, and gives computers a way to use vague human terms such as "warm," "near," or "fast" in precise calculations. A fuzzy system encodes expert knowledge as plain if-then rules and blends the rules that partly apply, so its output changes smoothly as its inputs change. That property made fuzzy logic a staple of control engineering, from train braking to washing machines, and it remains part of artificial intelligence (AI) systems that need interpretable, hand-tunable rules.

Fuzzy Sets and Membership Functions#

In classical set theory an element either belongs to a set or does not. A fuzzy set assigns each element a membership degree between 0 and 1 through a membership function, usually a triangle, trapezoid, or Gaussian curve over the input range. Neighboring sets overlap, so a room at 24 °C might be 0.6 "warm" and 0.2 "hot" at the same time, and the label changes gradually instead of jumping at a threshold. Logical operators extend to degrees: Zadeh's original definitions take the minimum of two degrees for AND, the maximum for OR, and 1 minus the degree for NOT, and other choices such as the product for AND belong to a family called t-norms.

How a Fuzzy Inference System Works#

A fuzzy controller turns crisp sensor readings into a crisp command in four steps:

  1. Fuzzification: Map each input value to its membership degree in every fuzzy set, for example how "near," "medium," and "far" an obstacle is.
  2. Rule evaluation: Fire each if-then rule, such as "if the distance is near, braking is hard," to the degree its condition holds.
  3. Aggregation: Clip each rule's output set at its firing strength and combine the clipped sets, usually with a maximum.
  4. Defuzzification: Reduce the combined set to one number, most often its centroid.

This scheme is the Mamdani method, named for Ebrahim Mamdani, who used it with Sedrak Assilian to control a laboratory steam engine in 1975. Takagi-Sugeno systems replace the output sets with formulas of the inputs and average them, which is cheaper to compute and easier to tune from data. This example implements a three-rule Mamdani controller that sets braking force from the distance to an obstacle:

import numpy as np

# Output fuzzy sets over braking force (0-100%)
force = np.linspace(0, 100, 501)
gentle = np.interp(force, [0, 40], [1, 0])
firm = np.interp(force, [20, 50, 80], [0, 1, 0])
hard = np.interp(force, [60, 100], [0, 1])

for distance in [8, 15, 22, 35]:
    # Fuzzification: how near, medium, and far the obstacle is (meters)
    near = np.interp(distance, [5, 20], [1, 0])
    medium = np.interp(distance, [10, 20, 30], [0, 1, 0])
    far = np.interp(distance, [20, 40], [0, 1])

    # Rules: near -> hard, medium -> firm, far -> gentle; clip each set (min), combine (max)
    combined = np.maximum.reduce([np.minimum(near, hard), np.minimum(medium, firm), np.minimum(far, gentle)])

    # Defuzzification: the centroid of the combined set is the crisp braking command
    print(f"{distance:>2} m -> brake {np.sum(force * combined) / np.sum(combined):.0f}%")

The script prints braking forces of 86%, 60%, 47%, and 14% for distances of 8, 15, 22, and 35 meters. At 15 meters the obstacle is 0.33 "near" and 0.5 "medium," so the hard and firm rules both fire partly and their blend gives 60%. Three rules produce a smooth braking curve with no threshold at which the command jumps.

Applications#

  • Control systems: Hitachi's fuzzy automatic train operation controlled acceleration and braking on the Sendai Subway Namboku Line when it opened in 1987, giving smoother rides and more accurate stops. Fuzzy controllers also adjust consumer appliances such as washing machines, rice cookers, and air conditioners from imprecise sensor readings.
  • Image segmentation: Fuzzy c-means, a soft version of k-means clustering, gives each pixel a degree of membership in every cluster. It is widely used in medical image analysis, for example to separate brain tissue types in MRI scans, where a pixel on a boundary can contain both tissues.
  • Vision-driven decisions: The Ultralytics speed estimation solution tracks vehicles with a YOLO26 model and reports each one's speed in km/h, a crisp input that a fuzzy rule base can grade as slow, moderate, or fast before setting a warning level or signal timing.
  • Neuro-fuzzy systems: The adaptive neuro-fuzzy inference system (ANFIS), introduced by Jyh-Shing Roger Jang in 1993, learns membership functions and rule parameters from data with neural network training methods while keeping the rules readable.

Fuzzy Logic vs. Probability and Symbolic AI#

Fuzzy logic and probability both use numbers between 0 and 1 but describe different kinds of uncertainty. A probability, the quantity that Bayesian networks reason with, expresses how likely a crisply defined event is, such as a 30% chance that it rains tomorrow. A fuzzy membership expresses how well a vague description fits a known state, such as a cup of coffee at 50 °C being 0.7 "warm". Compared with classical symbolic AI, fuzzy rule bases keep the readable if-then form of expert systems while replacing each rule's yes-or-no condition with a degree, which lets several rules contribute to one decision at once.

Explore solutions

Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Turn drone and aerial imagery into real-time insights for agriculture, aquaculture, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Apply computer vision in aerospace with Ultralytics YOLO for aircraft inspection, runway FOD detection, airport ground operations, and composite defect detection.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more

Let's build the future of AI together!

Begin your journey with the future of machine learning