Triangular¶
The Triangular membership function (TriangularMF) is one of the most fundamental and widely used membership functions in fuzzy logic. It represents fuzzy sets with a simple triangular shape, making it intuitive and computationally efficient. The function is defined by three key points that form the triangle: the left base point, the peak, and the right base point.
The function is characterized by three main parameters:
- a: Left base point of the triangle (μ(x) = 0 for x ≤ a).
- b: Peak point of the triangle (μ(b) = 1, the maximum membership value).
- c: Right base point of the triangle (μ(x) = 0 for x ≥ c).
These parameters must satisfy the constraint: a ≤ b ≤ c.
The mathematical formula for the triangular membership function is defined piecewise:
$$ \mu(x) = \begin{array}{ll} 0, & x \leq a, \\[4pt] \dfrac{x-a}{b-a}, & a < x \leq b, \\[4pt] \dfrac{c-x}{c-b}, & b < x < c, \\[4pt] 0, & x \geq c. \end{array} $$
where:
- $\mu(x)$ is the degree of membership of element $x$ in the fuzzy set.
- $x$ is the input value.
- $a$ is the left base point.
- $b$ is the peak point.
- $c$ is the right base point.
The triangular membership function is particularly useful for representing concepts like "approximately equal to b" or "around b", where the membership decreases linearly as we move away from the peak value.
Partial Derivatives¶
The partial derivatives of the triangular membership function are essential for optimization in adaptive fuzzy systems. Since the function is piecewise linear, the derivatives are computed separately for each region.
Derivative with respect to $a$
For $a < x < b$: $$\frac{\partial \mu}{\partial a} = \frac{x-b}{(b-a)^2}$$
For other regions: The derivative is 0.
Derivative with respect to $b$
For $a < x < b$: $$\frac{\partial \mu}{\partial b} = \frac{-(x-a)}{(b-a)^2}$$
For $b < x < c$: $$\frac{\partial \mu}{\partial b} = \frac{x-c}{(c-b)^2}$$
For other regions: The derivative is 0.
Derivative with respect to $c$
For $b < x < c$: $$\frac{\partial \mu}{\partial c} = \frac{x-b}{(c-b)^2}$$
For other regions: The derivative is 0.
These derivatives enable gradient-based optimization of the triangular membership function parameters, allowing the triangle to adapt its shape during training to better fit the data.
Python Example¶
import matplotlib.pyplot as plt
import numpy as np
from anfis_toolbox.membership import TriangularMF
triangular = TriangularMF(a=2, b=5, c=8)
x = np.linspace(0, 10, 100)
y = triangular(x)
plt.plot(x, y)
plt.show()
Visualization¶
Below is a comprehensive visualization showing how the TriangularMF shape changes with different parameter combinations. We'll explore variations in the base points (a, c) and peak position (b).