Trapezoidal¶
The Trapezoidal Membership Function is a piecewise linear function that creates a trapezoid-shaped membership curve. It is widely used in fuzzy logic systems when you need a plateau region of full membership, providing robustness to noise and uncertainty.
The Trapezoidal Membership Function is defined by the piecewise linear equation:
$$\mu(x) = \begin{array}{ll} 0 & x \leq a \\ \frac{x - a}{b - a} & a < x < b \\ 1 & b \leq x \leq c \\ \frac{d - x}{d - c} & c < x < d \\ 0 & x \geq d \end{array}$$
The function is characterized by four parameters:
- a: Left base point (lower support bound) - where μ(x) starts increasing from 0
- b: Left peak point (start of plateau) - where μ(x) reaches 1
- c: Right peak point (end of plateau) - where μ(x) starts decreasing from 1
- d: Right base point (upper support bound) - where μ(x) returns to 0
Parameter Constraints For a valid trapezoidal function, parameters must satisfy: a ≤ b ≤ c ≤ d
Geometric Interpretation
- The region [a, b] forms the left slope (rising edge)
- The region [b, c] forms the plateau (full membership region)
- The region [c, d] forms the right slope (falling edge)
- Outside [a, d], membership is zero
This shape is particularly useful when you need:
- A stable region of full membership (plateau)
- Gradual transitions at the boundaries
- Robustness to small variations in input values
Partial Derivatives¶
For optimization in ANFIS networks, we need the gradients of the membership function with respect to each parameter. The derivatives are computed analytically for each region:
Left Slope Region (a < x < b)
$$\mu(x) = \frac{x - a}{b - a}$$- ∂μ/∂a = -1/(b-a)
- ∂μ/∂b = -(x-a)/(b-a)²
- ∂μ/∂c = 0 (no effect in this region)
- ∂μ/∂d = 0 (no effect in this region)
Plateau Region (b ≤ x ≤ c)
$$\mu(x) = 1$$- ∂μ/∂a = 0 (constant function)
- ∂μ/∂b = 0 (constant function)
- ∂μ/∂c = 0 (constant function)
- ∂μ/∂d = 0 (constant function)
Right Slope Region (c < x < d)
$$\mu(x) = \frac{d - x}{d - c}$$- ∂μ/∂a = 0 (no effect in this region)
- ∂μ/∂b = 0 (no effect in this region)
- ∂μ/∂c = (x-d)/(d-c)²
- ∂μ/∂d = (x-c)/(d-c)²
Python Example¶
Let's create a trapezoidal membership function and visualize it:
import numpy as np
import matplotlib.pyplot as plt
from anfis_toolbox.membership import TrapezoidalMF
trapezoidal = TrapezoidalMF(a=2, b=4, c=6, d=8)
x = np.linspace(0, 10, 200)
y = trapezoidal(x)
plt.plot(x, y)
plt.show()
Visualization¶
The following interactive plot shows different trapezoidal membership functions with varying parameter combinations. Each subplot demonstrates how the shape changes with different plateau widths and slope characteristics.