Skip to content
Tutorials Center
My learning

Topics

Lesson 5 of 36 ยท Fuzzy Sets

Fuzzy Sets and Membership Degrees

Define fuzzy sets formally, write them in discrete and continuous form, understand membership functions, and test equality and subsets with runnable Python examples.

A fuzzy set is the basic building block of everything that follows. If you understand this lesson, membership functions, rules and inference will all feel like natural extensions. We start with the definition, then look at the two ways to write a fuzzy set (as a list of pairs, and as a function), and finish with the basic relations between sets: equality and subsets.

The definition

Fix a universe of discourse X: the collection of all values you are talking about, such as all temperatures from 0 to 40 or all whole numbers from 1 to 10. A crisp subset of X is described by a function that returns 0 or 1. A fuzzy set A in X is described by a membership function

TEXT
mu_A : X -> [0, 1]

that assigns to every element x a degree mu_A(x) telling how strongly x belongs to A. Formally you can write the set as a collection of pairs:

TEXT
A = { (x, mu_A(x)) | x in X }

A value of 1 means full membership, 0 means no membership, and everything in between is partial membership.

Discrete fuzzy sets

When the universe is a short list of values, you can simply list the pairs. In Python a dictionary is the natural data structure: the key is the element and the value is its degree. Here is the fuzzy set "numbers close to 5" on the universe 1 to 9.

Python A discrete fuzzy set as a dictionary

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.

Zadeh's classic notation writes the same set with slashes and plus signs, where the plus means "together with" and not addition:

TEXT
close_to_5 = 0.1/2 + 0.4/3 + 0.8/4 + 1/5 + 0.8/6 + 0.4/7 + 0.1/8

Elements with membership 0 are usually left out. Each term degree/element reads "this element belongs with this degree".

Continuous fuzzy sets

When the universe is a continuous range, you cannot list all pairs. You describe the set by a membership function instead: a formula that returns the degree for any x. For example "about 5" might be a bell shape around 5, and "hot" might be a ramp. This is how almost all real fuzzy systems work, and the next chapter is about the common shapes.

Python A continuous set as a 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.

The function can be evaluated at any point, so the continuous version is far more convenient inside a program. The discrete version is useful for teaching, for small universes and for the numerical sampling we will use in inference (we sample a continuous universe on a fine grid, as in np.linspace).

Membership is a modelling choice

There is no "correct" membership function for "tall". The function expresses someone's meaning of the word, for a purpose and for a population. A basketball coach and a kindergarten teacher draw different curves. That is a feature: the shape is where the human knowledge enters the system, and you can adjust it when you learn more.

Membership functions must satisfy two rules only: every value lies in [0, 1], and the function is defined for every element of the universe. Everything else (smoothness, symmetry, peak position) is your design.

Special fuzzy sets

  • The empty set has membership 0 everywhere.
  • The universal set has membership 1 everywhere.
  • A crisp set has only memberships 0 and 1: crisp sets are fuzzy sets.
  • A singleton has membership 1 at exactly one point and 0 elsewhere. Singletons are used as outputs in Sugeno systems (see Sugeno Inference).

Comparing fuzzy sets

Two basic relations carry over from crisp sets, applied point by point:

  • Equality: A = B when mu_A(x) = mu_B(x) for every x.
  • Subset (containment): A is a subset of B when mu_A(x) <= mu_B(x) for every x. Intuitively, B is at least as true as A everywhere. For instance "very tall" is a subset of "tall".

Note that two fuzzy sets can be neither equal nor in a subset relation, when one is larger in some places and smaller in others.

Python Subset and equality tests

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.

"Very small" is contained in "small" because squaring a number between 0 and 1 never makes it bigger. Small and medium are not comparable: small is larger at 1, medium at 4. The squaring trick is an example of a linguistic hedge, which Linguistic Variables and Hedges covers.

flowchart LR
    U["Universe X<br/>(all possible values)"] --> M["Membership function<br/>mu(x) in [0, 1]"]
    M --> A["Fuzzy set A"]
    A --> S["Pairs (x, mu(x))<br/>or a formula"]

A fuzzy set is a universe together with a membership function.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does a membership function return?

    mu_A maps every element of the universe to a degree of membership in [0, 1].
  2. 2. In Zadeh notation, what does 0.4/3 mean?

    The slash separates a degree from the element. The plus signs only list the pairs together.
  3. 3. When is A a subset of B for fuzzy sets?

    Containment is checked point by point: B must be at least as true as A at every element.
  4. 4. Which statement is true?

    Crisp sets are the special case of fuzzy sets whose memberships are only 0 or 1.

Summary

  • A fuzzy set is defined by a membership function that maps each element of the universe into [0, 1].
  • Discrete sets are lists of pairs (a dictionary in Python); continuous sets are formulas.
  • The membership shape expresses a meaning and is a design choice.
  • Equality and containment are tested point by point; some pairs of sets are incomparable.
  • Crisp sets, empty sets, universal sets and singletons are all special fuzzy sets.

Next: Linguistic Variables and Hedges