Pi-shaped¶
The Pi-shaped Membership Function creates a smooth bell-like curve with a flat plateau at the top. It combines S-shaped rising and Z-shaped falling edges with a trapezoidal-like plateau, making it ideal for representing concepts with gradual transitions and stable regions.
The Pi-shaped Membership Function is defined piecewise with smooth transitions:
$$\mu(x) = \begin{array}{ll} S(x; a, b) & a \leq x \leq b \\[6pt] 1 & b \leq x \leq c \\[6pt] Z(x; c, d) & c \leq x \leq d \\[6pt] 0 & \text{otherwise} \end{array}$$
Where:
- S(x; a, b) is the rising S-shaped function: smooth transition from 0 to 1
- Z(x; c, d) is the falling Z-shaped function: smooth transition from 1 to 0
The smooth transitions use cubic smoothstep functions:
S-function (rising edge): $$S(x; a, b) = 3t^2 - 2t^3 \quad \text{where} \quad t = \frac{x - a}{b - a}$$
Z-function (falling edge): $$Z(x; c, d) = 1 - S(x; c, d) = 1 - (3t^2 - 2t^3) \quad \text{where} \quad t = \frac{x - c}{d - c}$$
The function is characterized by four parameters:
- a: Left foot - where the function starts rising from 0
- b: Left shoulder - where the function reaches the plateau (μ = 1)
- c: Right shoulder - where the function starts falling from the plateau
- d: Right foot - where the function reaches 0
For a valid Pi-shaped function, parameters must satisfy: a < b ≤ c < d
Partial Derivatives¶
For optimization in ANFIS networks, we need the gradients of the membership function with respect to each parameter. The PiMF has analytical gradients computed by region:
S-Function Region (a ≤ x ≤ b)
For the rising edge: μ(x) = S(x; a, b) = 3t² - 2t³ where t = (x-a)/(b-a)- ∂μ/∂a = dS/dt · dt/da = [6t(1-t)] · [(x-b)/(b-a)²]
- ∂μ/∂b = dS/dt · dt/db = [6t(1-t)] · [-(x-a)/(b-a)²]
- ∂μ/∂c = 0 (no effect in this region)
- ∂μ/∂d = 0 (no effect in this region)
Plateau Region (b ≤ x ≤ c)
μ(x) = 1 (constant function)- ∂μ/∂a = 0 (constant function)
- ∂μ/∂b = 0 (constant function)
- ∂μ/∂c = 0 (constant function)
- ∂μ/∂d = 0 (constant function)
Z-Function Region (c ≤ x ≤ d)
For the falling edge: μ(x) = Z(x; c, d) = 1 - S(x; c, d) where t = (x-c)/(d-c)- ∂μ/∂a = 0 (no effect in this region)
- ∂μ/∂b = 0 (no effect in this region)
- ∂μ/∂c = dZ/dt · dt/dc = [-6t(1-t)] · [(x-d)/(d-c)²]
- ∂μ/∂d = dZ/dt · dt/dd = [-6t(1-t)] · [-(x-c)/(d-c)²]
Python Example¶
Let's create a Pi-shaped membership function and visualize it:
import numpy as np
import matplotlib.pyplot as plt
from anfis_toolbox.membership import PiMF
pimf = PiMF(a=1, b=3, c=7, d=9)
x = np.linspace(0, 10, 200)
y = pimf(x)
plt.plot(x, y)
plt.show()
Visualization¶
The following interactive plot shows different Pi-shaped membership functions with varying parameter combinations. Each subplot demonstrates how the plateau width and transition smoothness affect the overall shape.