Skip to content
Tutorials Center
My learning

Topics

Lesson 13 of 36 ยท Membership Functions and Operations

Fuzzy Relations and Composition

Learn fuzzy relations as membership matrices, build them from fuzzy sets, compose them with max-min and max-product, test similarity properties and see how inference uses composition.

A fuzzy set says how strongly one object has a property. A fuzzy relation says how strongly two objects are connected: "x is much larger than y", "city A is close to city B", "symptom S is associated with disease D". Relations are the missing link between fuzzy sets and fuzzy rules, because an IF x THEN y rule is itself a relation between an input and an output. This lesson shows how to represent relations as matrices, combine them, and compose them.

You should know the operations from Fuzzy Complement, Union and Intersection and the idea of applying functions to fuzzy sets from Alpha-Cuts and the Extension Principle.

Crisp relations, then fuzzy relations

A crisp relation R between sets X and Y is a subset of the pairs X x Y: each pair is either related (1) or not (0). With finite sets you can write it as a 0/1 matrix. A fuzzy relation allows degrees: mu_R(x, y) is a number in [0, 1], so the matrix holds any values from 0 to 1.

Here is a relation "is close to" between three cities (rows) and three towns (columns), as a matrix. Row i, column j tells how close city i is to town j.

Python A fuzzy relation as a matrix

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.

Building a relation from two fuzzy sets

The simplest way to make a relation is the Cartesian product of two fuzzy sets A on X and B on Y:

TEXT
mu_(A x B)(x, y) = min( mu_A(x), mu_B(y) )

(any t-norm works; see T-norms and S-norms). It says "x is in A and y is in B". NumPy makes it a one-liner with broadcasting.

Python The Cartesian product of two fuzzy sets

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 result has one row per element of A and one column per element of B, 3 by 4 here.

Composition of relations

Suppose R relates X to Y and S relates Y to Z. Their composition R o S relates X to Z through the middle step: x is related to z if there is some y such that x is related to y and y is related to z. In fuzzy terms "some" is a maximum and "and" is a minimum, which gives the famous max-min composition:

TEXT
mu_(R o S)(x, z) = max over y of  min( mu_R(x, y), mu_S(y, z) )

Replacing the minimum by a product gives the max-product composition. Both are like matrix multiplication where "multiply" becomes min (or product) and "add" becomes max.

flowchart LR
    X["X"] -->|"R"| Y["Y"] -->|"S"| Z["Z"]
    X -.->|"R o S = max over y of min(R, S)"| Z

Composition chains two relations through the shared middle set.

Python Max-min and max-product composition

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 cell (0, 0) combines two paths: through the first middle element, min(0.8, 0.7) = 0.7, and through the second, min(0.3, 0.4) = 0.3; the maximum is 0.7. Composition has the usual associativity (R o S) o T = R o (S o T), but it is not commutative.

Properties: similarity relations

A relation from a set to itself (X to X) can have properties:

  • Reflexive: mu(x, x) = 1, everything is fully related to itself.
  • Symmetric: mu(x, y) = mu(y, x).
  • Max-min transitive: R o R <= R (entries of R o R never exceed those of R).

A relation that is reflexive, symmetric and max-min transitive is a similarity relation, the fuzzy version of an equivalence relation. Similarity relations underlie fuzzy clustering. If a relation is only reflexive and symmetric (a tolerance relation), you can make it transitive by composing it with itself repeatedly until it stops changing, known as the transitive closure.

Python Testing and repairing a similarity relation

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 input is not transitive: the chain from item 0 to 1 to 2 gives min(0.8, 0.6) = 0.6, but the direct relation is only 0.3. The closure repairs it by raising that entry to 0.6.

Composing a set with a relation: the heart of inference

The most useful special case is a fuzzy set A on X composed with a relation R from X to Y. Treat A as a single-row matrix:

TEXT
B = A o R,   mu_B(y) = max over x of  min( mu_A(x), mu_R(x, y) )

This is the compositional rule of inference. If R stores the rule "IF x is low THEN y is high", then giving it the input A produces the output B. Fuzzy IF-THEN Rules shows how rules become relations, and Mamdani inference is a simplified, cheaper form of exactly this operation.

Python Inference as set-relation composition

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 is the "high" set, clipped at the best match between the observation and "low": since "about 1" overlaps "low" up to degree 0.7, the output peaks at 0.7.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. How is a fuzzy relation between finite sets X and Y stored?

    Entry (i, j) holds the degree to which the i-th element of X is related to the j-th element of Y.
  2. 2. What is the max-min composition cell for min(0.8, 0.7) on one path and min(0.3, 0.4) on another?

    Take the minimum along each path (0.7 and 0.3) and then the maximum over the paths.
  3. 3. Which three properties define a similarity relation?

    A similarity relation is the fuzzy analogue of an equivalence relation.
  4. 4. How does the compositional rule of inference compute the output B from input A and relation R?

    mu_B(y) = max over x of min(mu_A(x), mu_R(x, y)): composition of a set with a relation.

Summary

  • A fuzzy relation assigns a degree in [0, 1] to each pair and is stored as a matrix.
  • The Cartesian product of two fuzzy sets builds a relation with min (or product).
  • Max-min composition chains relations: max over the middle element of the min along each path.
  • Similarity relations are reflexive, symmetric and max-min transitive; closure repairs transitivity.
  • Composing a fuzzy set with a rule relation is the compositional rule of inference.

Next: Fuzzy IF-THEN Rules