[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-28 09:19:39 +00:00
parent de13593d4e
commit cacc1d104c

View File

@ -7,6 +7,7 @@ import numpy as np
Source: https://en.wikipedia.org/wiki/Fuzzy_set
"""
class FuzzySet:
"""
A class for representing and
@ -46,6 +47,7 @@ class FuzzySet:
self.peak = peak # Peak value
self.right_boundary = right_boundary # Right boundary
def membership(self, x):
"""
Calculate the membership value of
@ -61,6 +63,7 @@ def membership(self, x):
elif self.peak < x < self.right_boundary:
return (self.right_boundary - x) / (self.right_boundary - self.peak)
def union(self, other):
"""
Calculate the union of this fuzzy set
@ -103,6 +106,7 @@ def intersection(self, other):
(self.peak + other.peak) / 2,
)
def complement(self):
"""
Calculate the complement (negation) of this fuzzy set.
@ -111,7 +115,10 @@ def complement(self):
FuzzySet: A new fuzzy set representing the complement.
"""
complement_name = f"¬{self.name}"
return FuzzySet(complement_name, 1 - self.right_boundary, 1 - self.left_boundary, 1 - self.peak)
return FuzzySet(
complement_name, 1 - self.right_boundary, 1 - self.left_boundary, 1 - self.peak
)
def plot(self):
"""
@ -122,9 +129,11 @@ def plot(self):
plt.plot(x, y, label=self.name)
def __str__(self):
return f"{self.name}: [{self.left_boundary}, {self.peak}, {self.right_boundary}]"
if __name__ == "__main__":
A = FuzzySet("A", 0, 0.5, 1)
B = FuzzySet("B", 0.2, 0.7, 1)