[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2023-10-27 18:48:45 +00:00
parent 5e1dfe63d1
commit 6d751f806d

View File

@ -1,11 +1,13 @@
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import numpy as np import numpy as np
"""" """"
FuzzySet class for triangular fuzzy sets FuzzySet class for triangular fuzzy sets
Author: Shreya123714 Author: Shreya123714
Source: https://en.wikipedia.org/wiki/Fuzzy_set Source: https://en.wikipedia.org/wiki/Fuzzy_set
""" """
class FuzzySet: class FuzzySet:
""" """
A class for representing and manipulating triangular fuzzy sets. A class for representing and manipulating triangular fuzzy sets.
@ -39,7 +41,6 @@ class FuzzySet:
self.b = b # Peak value self.b = b # Peak value
self.c = c # Right boundary self.c = c # Right boundary
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.
@ -58,7 +59,6 @@ class FuzzySet:
elif self.b < x < self.c: elif self.b < x < self.c:
return (self.c - x) / (self.c - self.b) return (self.c - x) / (self.c - self.b)
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.
@ -71,11 +71,15 @@ class FuzzySet:
""" """
union_name = f"{self.name} {other.name}" union_name = f"{self.name} {other.name}"
return FuzzySet(union_name, min(self.a, other.a), max(self.c, other.c), (self.b + other.b) / 2) return FuzzySet(
union_name,
min(self.a, other.a),
max(self.c, other.c),
(self.b + other.b) / 2,
)
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:
@ -84,9 +88,13 @@ class FuzzySet:
Returns: Returns:
FuzzySet: A new fuzzy set representing the intersection. FuzzySet: A new fuzzy set representing the intersection.
""" """
intersection_name = f"{self.name}{other.name}" intersection_name = f"{self.name}{other.name}"
return FuzzySet(intersection_name, max(self.a, other.a), min(self.c, other.c), (self.b + other.b) / 2) return FuzzySet(
intersection_name,
max(self.a, other.a),
min(self.c, other.c),
(self.b + other.b) / 2,
)
def complement(self): def complement(self):
""" """
@ -98,7 +106,6 @@ class FuzzySet:
complement_name = f"¬{self.name}" complement_name = f"¬{self.name}"
return FuzzySet(complement_name, 1 - self.c, 1 - self.a, 1 - self.b) return FuzzySet(complement_name, 1 - self.c, 1 - self.a, 1 - self.b)
def plot(self): def plot(self):
""" """
Plot the membership function of the fuzzy set. Plot the membership function of the fuzzy set.
@ -108,8 +115,6 @@ class FuzzySet:
plt.plot(x, y, label=self.name) plt.plot(x, y, label=self.name)
def __str__(self): def __str__(self):
return f"{self.name}: [{self.a}, {self.b}, {self.c}]" return f"{self.name}: [{self.a}, {self.b}, {self.c}]"
@ -139,5 +144,3 @@ if __name__ == "__main__":
plt.ylabel("Membership") plt.ylabel("Membership")
plt.legend() plt.legend()
plt.show() plt.show()