mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-05-19 15:41:34 +00:00
Fix the bug , for which test were failing
This commit is contained in:
parent
6d751f806d
commit
e778cb35b7
@ -10,7 +10,8 @@ import numpy as np
|
|||||||
|
|
||||||
class FuzzySet:
|
class FuzzySet:
|
||||||
"""
|
"""
|
||||||
A class for representing and manipulating triangular fuzzy sets.
|
A class for representing and
|
||||||
|
manipulating triangular fuzzy sets.
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
name (str): The name or label of the fuzzy set.
|
name (str): The name or label of the fuzzy set.
|
||||||
@ -19,21 +20,27 @@ class FuzzySet:
|
|||||||
c (float): The right boundary of the fuzzy set.
|
c (float): The right boundary of the fuzzy set.
|
||||||
|
|
||||||
Methods:
|
Methods:
|
||||||
membership(x): Calculate the membership value of an input 'x' in the fuzzy set.
|
membership(x): Calculate the membership value
|
||||||
union(other): Calculate the union of this fuzzy set with another fuzzy set.
|
of an input 'x' in the fuzzy set.
|
||||||
intersection(other): Calculate the intersection of this fuzzy set with another fuzzy set.
|
union(other): Calculate the union of this fuzzy set
|
||||||
complement(): Calculate the complement (negation) of this fuzzy set.
|
with another fuzzy set.
|
||||||
|
intersection(other): Calculate the intersection of this fuzzy set
|
||||||
|
with another fuzzy set.
|
||||||
|
complement(): Calculate the complement (negation)
|
||||||
|
of this fuzzy set.
|
||||||
plot(): Plot the membership function of the fuzzy set.
|
plot(): Plot the membership function of the fuzzy set.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, name, a, b, c):
|
def __init__(self, name, a, b, c):
|
||||||
"""
|
"""
|
||||||
Initializes a triangular fuzzy set with the given parameters.
|
Initializes a triangular fuzzy set
|
||||||
|
with the given parameters.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
name (str): The name or label of the fuzzy set.
|
name (str): The name or label of the fuzzy set.
|
||||||
a (float): The left boundary of the fuzzy set.
|
a (float): The left boundary of the fuzzy set.
|
||||||
b (float): The peak (central) value of the fuzzy set.
|
b (float): The peak (central) value of
|
||||||
|
the fuzzy set.
|
||||||
c (float): The right boundary of the fuzzy set.
|
c (float): The right boundary of the fuzzy set.
|
||||||
"""
|
"""
|
||||||
self.name = name # Fuzzy set name
|
self.name = name # Fuzzy set name
|
||||||
@ -43,13 +50,16 @@ class FuzzySet:
|
|||||||
|
|
||||||
def membership(self, x):
|
def membership(self, x):
|
||||||
"""
|
"""
|
||||||
Calculate the membership value of an input 'x' in the fuzzy set.
|
Calculate the membership value of
|
||||||
|
an input 'x' in the fuzzy set.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
x (float): The input value for which the membership is calculated.
|
x (float): The input value for
|
||||||
|
which the membership is calculated.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
float: The membership value of 'x' in the fuzzy set.
|
float: The membership value of 'x' in
|
||||||
|
the fuzzy set.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if x <= self.a or x >= self.c:
|
if x <= self.a or x >= self.c:
|
||||||
@ -61,13 +71,16 @@ class FuzzySet:
|
|||||||
|
|
||||||
def union(self, other):
|
def union(self, other):
|
||||||
"""
|
"""
|
||||||
Calculate the union of this fuzzy set with another fuzzy set.
|
Calculate the union of this fuzzy set
|
||||||
|
with another fuzzy set.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
other (FuzzySet): Another fuzzy set to union with.
|
other (FuzzySet): Another fuzzy set
|
||||||
|
to union with.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
FuzzySet: A new fuzzy set representing the union.
|
FuzzySet: A new fuzzy
|
||||||
|
set representing the union.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
union_name = f"{self.name} ∪ {other.name}"
|
union_name = f"{self.name} ∪ {other.name}"
|
||||||
@ -80,7 +93,8 @@ class FuzzySet:
|
|||||||
|
|
||||||
def intersection(self, other):
|
def intersection(self, other):
|
||||||
"""
|
"""
|
||||||
Calculate the intersection of this fuzzy set with another fuzzy set.
|
Calculate the intersection of this
|
||||||
|
fuzzy set with another fuzzy set.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
other (FuzzySet): Another fuzzy set to intersect with.
|
other (FuzzySet): Another fuzzy set to intersect with.
|
||||||
@ -132,13 +146,13 @@ if __name__ == "__main__":
|
|||||||
plt.legend()
|
plt.legend()
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
union_AB = A.union(B)
|
union_ab = A.union(B)
|
||||||
intersection_AB = A.intersection(B)
|
intersection_ab = A.intersection(B)
|
||||||
complement_A = A.complement()
|
complement_a = A.complement()
|
||||||
|
|
||||||
union_AB.plot()
|
union_ab.plot()
|
||||||
intersection_AB.plot()
|
intersection_ab.plot()
|
||||||
complement_A.plot()
|
complement_a.plot()
|
||||||
|
|
||||||
plt.xlabel("x")
|
plt.xlabel("x")
|
||||||
plt.ylabel("Membership")
|
plt.ylabel("Membership")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user