Types of Membership Functions
Membership functions help you define how much an input belongs to a fuzzy set, using values between 0 (not a member) and 1 (fully a member). These functions are the core of fuzzy logic systems. The most common types are triangular, trapezoidal, and Gaussian membership functions.
A triangular membership function has a simple, triangle shape. Imagine a mountain with one sharp peak. The left side rises up, the top is a single point (the peak), and the right side goes back down. For example, if you want to describe what "medium temperature" means, you might say that 20 degrees is not medium, 25 degrees is fully medium, and 30 degrees is not medium again. The highest membership is only at the peak value.
Here is how you can define a triangular membership function in Python using if-else statements:
def triangular(x, a, b, c):
if x <= a or x >= c:
return 0.0
elif a < x < b:
return (x - a) / (b - a)
elif b <= x < c:
return (c - x) / (c - b)
else:
return 0.0
ais where the function starts rising;bis the peak (full membership);cis where the function returns to zero.
A trapezoidal membership function is like a triangle with the top cut off. It rises up, stays flat for a while, and then goes down. This means that several values are considered fully in the set. For example, if "acceptable speed" is between 40 and 60, then 40 to 60 are all fully acceptable, while speeds below 35 or above 65 are not acceptable at all. The flat top shows a range of full membership.
Here is a Python function for a trapezoidal membership function using if-else statements:
def trapezoidal(x, a, b, c, d):
if x <= a or x >= d:
return 0.0
elif a < x < b:
return (x - a) / (b - a)
elif b <= x <= c:
return 1.0
elif c < x < d:
return (d - x) / (d - c)
else:
return 0.0
ais where the function starts rising;bis where it reaches full membership;cis where it starts falling;dis where it returns to zero.
A Gaussian membership function looks like a smooth hill or a bell curve. The highest point is in the center, and it slowly drops off on both sides. There are no sharp corners or flat tops. For example, if you have a sensor reading, the value closest to the center is most typical, and values farther away are less typical, but the change is always smooth.
Here is a Python function for a Gaussian membership function using if-else statements:
def gaussian(x, mean, sigma):
return math.exp(-0.5 * ((x - mean) / sigma) ** 2)
meanis the center of the bell curve;sigmacontrols how wide the curve is.
You choose the type of membership function based on what you want to model: use triangular for simple, sharp peaks; trapezoidal for ranges where many values are equally good; and Gaussian for smooth, gradual changes.
12345678910111213141516171819202122232425262728293031323334import numpy as np import matplotlib.pyplot as plt def trapezoidal(x, a, b, c, d): """ Trapezoidal membership function using if-else statements. - a: left foot (where membership starts to rise) - b: left shoulder (where membership becomes 1) - c: right shoulder (where membership starts to fall) - d: right foot (where membership returns to 0) """ if x <= a or x >= d: return 0.0 elif a < x < b: return (x - a) / (b - a) elif b <= x <= c: return 1.0 elif c < x < d: return (d - x) / (d - c) else: return 0.0 # Vectorize the function to work with numpy arrays tv_trapezoidal = np.vectorize(trapezoidal) x = np.linspace(0, 10, 100) y_trap = tv_trapezoidal(x, a=2, b=4, c=6, d=8) plt.plot(x, y_trap, label="Trapezoidal MF (a=2, b=4, c=6, d=8)") plt.xlabel("x") plt.ylabel("Membership Degree") plt.title("Trapezoidal Membership Function") plt.legend() plt.show()
When comparing the outputs of triangular and trapezoidal membership functions for the same input range, you will notice key differences. The triangular function, with its single peak, assigns the highest membership to only one value, and membership decreases linearly on both sides. In contrast, the trapezoidal function features a plateau where the membership degree remains at one for a range of input values, not just a single point. This means that, for a given input range, the trapezoidal function allows multiple values to be considered full members of the fuzzy set, while the triangular function is more restrictive. The choice between these functions depends on whether you want a single peak or a range of full membership in your fuzzy set.
Obrigado pelo seu feedback!
Pergunte à IA
Pergunte à IA
Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo
Incrível!
Completion taxa melhorada para 6.67
Types of Membership Functions
Deslize para mostrar o menu
Membership functions help you define how much an input belongs to a fuzzy set, using values between 0 (not a member) and 1 (fully a member). These functions are the core of fuzzy logic systems. The most common types are triangular, trapezoidal, and Gaussian membership functions.
A triangular membership function has a simple, triangle shape. Imagine a mountain with one sharp peak. The left side rises up, the top is a single point (the peak), and the right side goes back down. For example, if you want to describe what "medium temperature" means, you might say that 20 degrees is not medium, 25 degrees is fully medium, and 30 degrees is not medium again. The highest membership is only at the peak value.
Here is how you can define a triangular membership function in Python using if-else statements:
def triangular(x, a, b, c):
if x <= a or x >= c:
return 0.0
elif a < x < b:
return (x - a) / (b - a)
elif b <= x < c:
return (c - x) / (c - b)
else:
return 0.0
ais where the function starts rising;bis the peak (full membership);cis where the function returns to zero.
A trapezoidal membership function is like a triangle with the top cut off. It rises up, stays flat for a while, and then goes down. This means that several values are considered fully in the set. For example, if "acceptable speed" is between 40 and 60, then 40 to 60 are all fully acceptable, while speeds below 35 or above 65 are not acceptable at all. The flat top shows a range of full membership.
Here is a Python function for a trapezoidal membership function using if-else statements:
def trapezoidal(x, a, b, c, d):
if x <= a or x >= d:
return 0.0
elif a < x < b:
return (x - a) / (b - a)
elif b <= x <= c:
return 1.0
elif c < x < d:
return (d - x) / (d - c)
else:
return 0.0
ais where the function starts rising;bis where it reaches full membership;cis where it starts falling;dis where it returns to zero.
A Gaussian membership function looks like a smooth hill or a bell curve. The highest point is in the center, and it slowly drops off on both sides. There are no sharp corners or flat tops. For example, if you have a sensor reading, the value closest to the center is most typical, and values farther away are less typical, but the change is always smooth.
Here is a Python function for a Gaussian membership function using if-else statements:
def gaussian(x, mean, sigma):
return math.exp(-0.5 * ((x - mean) / sigma) ** 2)
meanis the center of the bell curve;sigmacontrols how wide the curve is.
You choose the type of membership function based on what you want to model: use triangular for simple, sharp peaks; trapezoidal for ranges where many values are equally good; and Gaussian for smooth, gradual changes.
12345678910111213141516171819202122232425262728293031323334import numpy as np import matplotlib.pyplot as plt def trapezoidal(x, a, b, c, d): """ Trapezoidal membership function using if-else statements. - a: left foot (where membership starts to rise) - b: left shoulder (where membership becomes 1) - c: right shoulder (where membership starts to fall) - d: right foot (where membership returns to 0) """ if x <= a or x >= d: return 0.0 elif a < x < b: return (x - a) / (b - a) elif b <= x <= c: return 1.0 elif c < x < d: return (d - x) / (d - c) else: return 0.0 # Vectorize the function to work with numpy arrays tv_trapezoidal = np.vectorize(trapezoidal) x = np.linspace(0, 10, 100) y_trap = tv_trapezoidal(x, a=2, b=4, c=6, d=8) plt.plot(x, y_trap, label="Trapezoidal MF (a=2, b=4, c=6, d=8)") plt.xlabel("x") plt.ylabel("Membership Degree") plt.title("Trapezoidal Membership Function") plt.legend() plt.show()
When comparing the outputs of triangular and trapezoidal membership functions for the same input range, you will notice key differences. The triangular function, with its single peak, assigns the highest membership to only one value, and membership decreases linearly on both sides. In contrast, the trapezoidal function features a plateau where the membership degree remains at one for a range of input values, not just a single point. This means that, for a given input range, the trapezoidal function allows multiple values to be considered full members of the fuzzy set, while the triangular function is more restrictive. The choice between these functions depends on whether you want a single peak or a range of full membership in your fuzzy set.
Obrigado pelo seu feedback!