Linear S-shaped¶
The linear S-shaped membership function (LinSShapedMF) is a fundamental concept in fuzzy logic, used to define fuzzy sets. Unlike a classical set where an element either fully belongs or doesn't, a fuzzy set allows for partial membership, and the LinSShapedMF provides a smooth, continuous way to represent this degree of belonging.
It's a piecewise linear function that transitions from 0 to 1 over a defined interval.
The mathematical formula for the linear S-shaped membership function is given by:
- $μ(x) = 0$, for $x \le a$
- $μ(x) = (x - a) / (b - a)$, for $a < x < b$
- $μ(x) = 1$, for $x \ge b$
Where:
- $μ(x)$ is the degree of membership for element $x$ in the fuzzy set.
- $a$ and $b$ are the parameters that define the start and end of the linear ramp.
The function is characterized by two main parameters:
a(start point): The "left foot" of the curve. This is the point where the membership transition begins from 0.b(end point): The "right shoulder" of the curve. This is the point where the membership reaches and stays at 1. The parameterbmust always be greater thana.
Partial Derivatives (Gradients)¶
The partial derivatives of the membership function are crucial for optimization algorithms, such as backpropagation, which allow the system to adapt. They indicate how the membership value changes in response to small adjustments in the parameters a and b.
Derivative with respect to `a` ($\frac{\partial \mu}{\partial a}$)
The partial derivative with respect to a indicates how the membership value is affected when the starting point of the ramp is adjusted.
$\frac{\partial \mu}{\partial a} = -\frac{1}{b-a}$ (for the ramp region)
Derivative with respect to `b` ($\frac{\partial \mu}{\partial b}$)
The partial derivative with respect to b shows how the membership value changes when the end point of the ramp is adjusted.
$\frac{\partial \mu}{\partial b} = \frac{x-a}{(b-a)^2}$ (for the ramp region)
import numpy as np
import matplotlib.pyplot as plt
from anfis_toolbox.membership import LinSShapedMF
mf = LinSShapedMF(a=3, b=7)
x = np.linspace(0, 10, 100)
y = mf.forward(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.