Skip to content
Tutorials Center
My learning

Topics

Lesson 36 of 46 ยท Probabilistic Reasoning

Fuzzy Logic and Belief Functions

Learn fuzzy sets, membership functions, fuzzy rules and defuzzification, then Dempster-Shafer belief and plausibility, with runnable Python examples.

Probability is not the only way to describe an uncertain world, and it is not always the best fit. Two kinds of uncertainty cause trouble. The first is vagueness: is a 38 degree room "hot"? Nobody is unsure about the temperature; the word "hot" simply has no sharp edge. The second is ignorance: a witness says the car was "red or orange", and you do not know how to split your belief between the two. Fuzzy logic was invented for the first problem and Dempster-Shafer theory for the second.

This lesson builds both from scratch. You will write a fuzzy controller that decides a fan speed from temperature and humidity, and a belief calculator that combines evidence from two sensors. Both complement the probability tools in Probability for AI and Bayesian Networks.

Crisp sets versus fuzzy sets

In classical (crisp) logic, something is in a set or it is not. "Tall" might mean 180 cm or more. Then 179.9 cm is "not tall" and 180.0 cm is "tall", which is absurd.

A fuzzy set lets an element belong partly. Each element gets a membership degree between 0 (not at all) and 1 (completely). A person of 170 cm might be tall to degree 0.3 and a person of 190 cm to degree 0.9. The function that assigns the degree is the membership function. Common shapes are:

  • triangular (rise, peak, fall), the simplest and most common,
  • trapezoidal (a flat top of fully-true values),
  • Gaussian (smooth bell curve).

Note that a membership degree is not a probability. "The temperature is hot to degree 0.7" means it is fairly hot, not that there is a 70% chance it is hot.

Python Membership functions for temperature

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.

At 18 degrees the air is both a little "cold" (0.20) and a little "warm" (0.30). Overlap is what makes control smooth: nothing flips abruptly from one category to the next.

Fuzzy operators

Logic needs AND, OR and NOT. The standard fuzzy versions (Zadeh's operators) are:

Operation Formula Meaning
AND (intersection) min(a, b) Only as true as the weaker part
OR (union) max(a, b) As true as the stronger part
NOT (complement) 1 - a Opposite degree

Other choices exist (product for AND, probabilistic sum for OR), and which to use depends on the application. Unlike Boolean logic, fuzzy logic does not obey the law of the excluded middle: a value can be 0.4 "hot" and 0.6 "not hot", and hot AND not hot is min(0.4, 0.6) = 0.4, not 0. When every degree is exactly 0 or 1, fuzzy logic collapses to ordinary Boolean logic, so it is a strict generalisation.

A fuzzy inference system

A fuzzy inference system has four steps. The best known design is the Mamdani controller:

  1. Fuzzification: turn each crisp input (22.5 degrees) into membership degrees in its fuzzy sets.
  2. Rule evaluation: apply IF-THEN rules such as IF temperature is hot AND humidity is high THEN fan is fast. The AND uses min, and the result is the firing strength of the rule.
  3. Aggregation: combine the output sets of all rules (using max, after clipping each at its firing strength).
  4. Defuzzification: convert the aggregated fuzzy output back into one crisp number. The common method is the centroid (centre of gravity) of the shape.
flowchart LR
    A["Crisp inputs<br/>temp, humidity"] --> B["Fuzzification"]
    B --> C["Rule evaluation<br/>min for AND"]
    C --> D["Aggregation<br/>max of clipped outputs"]
    D --> E["Defuzzification<br/>centroid"]
    E --> F["Crisp output<br/>fan speed"]

The controller turns numbers into degrees, reasons with rules and turns the result back into a number.

Python A fan controller with fuzzy rules

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 output moves smoothly from about 18 to 80 percent as the inputs change. A crisp rule set with hard thresholds would jump. This smooth behaviour is why fuzzy controllers appear in washing machines (load and dirtiness give wash time), air conditioners, anti-lock brakes, camera autofocus and automatic transmissions. The designer writes rules in words an expert would use, and no mathematical model of the machine is required.

Strengths and limits of fuzzy logic

  • Expert knowledge in natural language goes straight into rules.
  • Control is smooth and tolerant of noisy sensors.
  • Rule bases are easy to read and tune, but they grow quickly with the number of inputs (3 inputs with 5 sets each need up to 125 rules).
  • Membership functions are chosen by hand; there is no learning unless you add it (neuro-fuzzy systems tune them from data).

Dempster-Shafer theory: reasoning with ignorance

Probability forces you to split your belief between all possibilities. If you know nothing about a coin, you must say 50/50, which looks identical to the case where you have strong evidence the coin is fair. Dempster-Shafer (DS) theory, also called evidence theory or belief functions, can say "I have no information" explicitly.

The setup:

  • The frame of discernment Theta is the set of mutually exclusive possibilities, for example {red, green, blue}.
  • A mass function m assigns belief mass to subsets of Theta, not just to single elements. The masses add up to 1, and m(empty) = 0. Mass on a set like {red, green} means "the evidence points to one of these, but cannot tell which".
  • Mass on all of Theta is pure ignorance.

From the masses you compute two numbers for any hypothesis A:

  • Belief Bel(A): the total mass of all subsets of A. This is the evidence that surely supports A.
  • Plausibility Pl(A): the total mass of all subsets that overlap A. This is the evidence that does not contradict A.

Bel(A) <= Pl(A), and the gap between them is the uncertainty. Also Pl(A) = 1 - Bel(not A).

Python Belief and plausibility from a mass function

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.

Look at : belief is 0, because no mass supports red alone, yet plausibility is 1.0, because nothing rules it out. The hypothesis {red, green} has belief 0.6 and plausibility 1.0. A probability model would have had to invent a split between red and green.

Combining evidence: Dempster's rule

If two independent sources provide mass functions m1 and m2, Dempster's rule of combination merges them. For every pair of focal sets B (from m1) and C (from m2), multiply the masses and assign the product to B intersect C. Some pairs have an empty intersection; that product is conflict K. Remove it by dividing everything else by 1 - K.

Python Dempster's rule of combination

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 two witnesses together point at green (the only colour in both of their sets). The last example is a known weakness: when sources almost completely disagree, normalising by 1 - K can hand all the belief to the one hypothesis both dismissed, blue. Practical systems check the conflict value K and treat a large one as a warning sign, or use alternative combination rules.

Probability, fuzzy logic and Dempster-Shafer compared

Probability Fuzzy logic Dempster-Shafer
Models Chance of an uncertain event Degree of truth of a vague statement Degree of evidential support
Example "70% chance of rain" "The room is rather warm (0.6)" "The evidence supports A with 0.5, and 0.3 is unassigned"
Output One number per outcome A degree for each fuzzy set An interval [Bel, Pl]
Ignorance Hard to express Not the target Mass on the whole frame
Typical use Prediction, diagnosis Control, rule systems Sensor fusion, expert opinions

Tip: Ask what kind of uncertainty you have. If the statement is vague ("tall", "warm"), use fuzzy sets. If the event is random and you have data, use probability. If you have pieces of evidence that do not pin down a single answer, consider belief functions.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. A fuzzy membership degree of 0.7 for 'hot' means:

    Membership degrees measure how well something fits a vague category, not the likelihood of an event.
  2. 2. How does fuzzy logic compute A AND B with Zadeh's operators?

    AND takes the minimum, OR takes the maximum, NOT is 1 minus the degree.
  3. 3. What is the job of defuzzification in a Mamdani controller?

    After rules are fired and aggregated, a method such as the centroid produces the crisp control value, for example a fan speed.
  4. 4. In Dempster-Shafer theory, mass placed on the whole frame of discernment represents:

    Mass on Theta says the source supports none of the hypotheses in particular, and it raises plausibility without raising belief.
  5. 5. For a hypothesis A, which relation always holds?

    Belief counts only evidence inside A; plausibility counts everything that overlaps A, so it can never be smaller.

Summary

  • Fuzzy sets give partial membership (0 to 1) to model vague concepts; membership degrees are not probabilities.
  • Zadeh's operators are min for AND, max for OR and 1 - x for NOT.
  • A Mamdani fuzzy system fuzzifies inputs, fires rules, aggregates the clipped outputs and defuzzifies, for instance with the centroid.
  • Fuzzy controllers give smooth behaviour from expert-style rules, which is why they sit in appliances and vehicles.
  • Dempster-Shafer theory assigns mass to sets of outcomes, and reports belief and plausibility as an interval.
  • Dempster's rule combines independent evidence, but a high conflict value signals trouble.

Next: Multi-Agent Systems.