S-shaped¶
The S-shaped Membership Function (SShapedMF) is a type of membership function used in fuzzy logic. It models the gradual transition from a zero degree of membership (0.0) to a full degree (1.0). This form is ideal for representing concepts like "hot" or "fast," where membership starts low and progressively increases to a certain point. The transition is defined by a cubic polynomial, resulting in a smooth, continuous curve without angular points.
The S-shaped function's curve is defined by two main parameters:
- $a$: The point where the function begins to rise from a membership degree of 0.0.
- $b$: The point where the function reaches a membership degree of 1.0.
The transition between these two points is described by the following equation:
$$ S(x; a, b) = \begin{array}{ll} 0 & x \le a \\[6pt] 2 \left( \frac{x-a}{b-a} \right)^2 & a < x \le \frac{a+b}{2} \\[6pt] 1 - 2 \left( \frac{x-b}{b-a} \right)^2 & \frac{a+b}{2} < x < b \\[6pt] 1 & x \ge b \end{array}{ll} $$
This formulation ensures a smooth and continuous transition between the different segments of the curve, which is fundamental for representing uncertainties and imprecision in fuzzy logic systems.
Partial Derivatives¶
To optimize the shape of the S-shaped membership function for a specific application, it's often necessary to calculate the partial derivatives with respect to its parameters, $a$ and $b$. These derivatives are crucial for optimization algorithms like gradient descent.
Partial Derivative with Respect to $a$
The partial derivative of the S-shaped function with respect to the parameter $a$ is calculated as follows:
$$ \frac{\partial S}{\partial a} = \begin{array}{ll} 0 & x \le a \\[6pt] \frac{-4(x-a)}{(b-a)^2} + \frac{4(x-a)^2}{(b-a)^3} & a < x \le \frac{a+b}{2} \\[6pt] \frac{4(x-b)^2}{(b-a)^3} & \frac{a+b}{2} < x < b \\[6pt] 0 & x \ge b \end{array} $$
This derivative shows how the membership value changes as the starting point of the curve, $a$, is adjusted.
Partial Derivative with Respect to $b$
The partial derivative of the S-shaped function with respect to the parameter $b$ is calculated as follows:
$$ \frac{\partial S}{\partial b} = \begin{array}{ll} 0 & x \le a \\[6pt] \frac{-4(x-a)^2}{(b-a)^3} & a < x \le \frac{a+b}{2} \\[6pt] \frac{-4(x-b)}{(b-a)^2} + \frac{4(x-b)^2}{(b-a)^3} & \frac{a+b}{2} < x < b \\[6pt] 0 & x \ge b \end{array} $$
This derivative indicates how the membership value changes as the ending point of the curve, $b$, is adjusted.
These partial derivatives are essential tools for tuning the S-shaped membership function to better fit data or to meet specific system requirements. They enable gradient-based optimization by providing the direction and magnitude of the steepest ascent/descent for the parameters.
Python Example¶
import numpy as np
import matplotlib.pyplot as plt
from anfis_toolbox.membership import SShapedMF
mf = SShapedMF(a=2, b=8)
x = np.linspace(0, 10, 200)
y = mf(x)
plt.plot(x, y)
plt.show()
Visualization¶
Below is a visual representation of the S-shaped membership function, showing how its shape is influenced by the parameters a and b.