Z-shaped¶
The Z-shaped Membership Function (ZShapedMF) is a fundamental type of membership function in fuzzy logic. It provides a smooth and continuous transition from a full degree of membership (1.0) to zero. This form is ideal for modeling concepts like "cold" or "slow," where membership is high up to a certain point and then decreases gradually. The transition is defined using a cubic polynomial, resulting in a smooth curve without angular points.
The function is defined by two key parameters that delimit the transition region:
a(Left Shoulder): The point where the transition from a full degree of membership (1.0) begins. For input values less than or equal toa, the membership is always 1.0.b(Right Foot): The point where the transition ends and the degree of membership becomes zero. For input values greater than or equal tob, the membership is always 0.0.
It is crucial that a is less than b for the transition to occur correctly.
The formula for the ZShapedMF is based on the smoothstep function, a third-degree polynomial. The function is defined in parts:
$$ \mu(x) = \begin{array}{ll} 1, & x \leq a, \\[6pt] 1 - \bigl(3t^{2} - 2t^{3}\bigr), & a < x < b \\[6pt] 0, & x \geq b. \end{array} $$
Where:
$\mu(x)$ is the degree of membership of element $x$ and $t = \dfrac{x-a}{\,b-a\,}$.
Partial Derivatives (Gradients)¶
The partial derivatives are crucial for optimizing the parameters a and b in adaptive fuzzy systems. They show how the function's output changes in response to small changes in these parameters.
Derivative with respect to `a` ($\frac{\partial \mu}{\partial a}$)
This derivative indicates how the degree of membership is affected by adjusting the starting point of the transition.
$$\frac{\partial \mu}{\partial a} = \frac{\partial \mu}{\partial t} \frac{\partial t}{\partial a} = - (6t(t-1)) \cdot \frac{x-b}{(b-a)^2}$$
Derivative with respect to `b` ($\frac{\partial \mu}{\partial b}$)
This derivative indicates how the degree of membership is affected by adjusting the endpoint of the transition.
$$\frac{\partial \mu}{\partial b} = \frac{\partial \mu}{\partial t} \frac{\partial t}{\partial b} = - (6t(t-1)) \cdot - \frac{x-a}{(b-a)^2}$$
Python Example¶
import numpy as np
import matplotlib.pyplot as plt
from anfis_toolbox.membership import ZShapedMF
mf = ZShapedMF(a=15, b=25)
x = np.linspace(0, 40, 100)
y = mf(x)
plt.plot(x, y)
plt.show()
Visualization¶
Below is a comprehensive visualization showing how the ZShapedMF shape changes with different parameter combinations.