Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions fuzzy_logic/fuzzy_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,23 +138,27 @@
msg = f"Invalid value {x} for fuzzy set {self}"
raise ValueError(msg)

def union(self, other) -> FuzzySet:
"""
Calculate the union of this fuzzy set with another fuzzy set.
Args:
other (FuzzySet): Another fuzzy set to union with.
Returns:
FuzzySet: A new fuzzy set representing the union.

>>> FuzzySet("a", 0.1, 0.2, 0.3).union(FuzzySet("b", 0.4, 0.5, 0.6))
FuzzySet(name='a U b', left_boundary=0.1, peak=0.6, right_boundary=0.35)
"""
return FuzzySet(
f"{self.name} U {other.name}",
min(self.left_boundary, other.left_boundary),
max(self.right_boundary, other.right_boundary),
(self.peak + other.peak) / 2,
)
def union(self, other: FuzzySet) -> FuzzySet:

Check failure on line 141 in fuzzy_logic/fuzzy_operations.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff

fuzzy_logic/fuzzy_operations.py:141:4: SyntaxError: unindent does not match any outer indentation level
"""
Calculate the union of this fuzzy set with another fuzzy set.
The union of two fuzzy sets is determined by taking the maximum
membership value at each point.

Check failure on line 146 in fuzzy_logic/fuzzy_operations.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

fuzzy_logic/fuzzy_operations.py:146:1: W293 Blank line contains whitespace
Args:
other (FuzzySet): Another fuzzy set to union with.

Check failure on line 149 in fuzzy_logic/fuzzy_operations.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

fuzzy_logic/fuzzy_operations.py:149:1: W293 Blank line contains whitespace
Returns:
FuzzySet: A new fuzzy set representing the union.

Check failure on line 152 in fuzzy_logic/fuzzy_operations.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

fuzzy_logic/fuzzy_operations.py:152:1: W293 Blank line contains whitespace
>>> FuzzySet("a", 0.1, 0.2, 0.3).union(FuzzySet("b", 0.4, 0.5, 0.6))
FuzzySet(name='a U b', left_boundary=0.1, peak=0.5, right_boundary=0.6)
"""
return FuzzySet(
f"{self.name} U {other.name}",
min(self.left_boundary, other.left_boundary),
max(self.peak, other.peak),
max(self.right_boundary, other.right_boundary)
)

def plot(self):
"""
Expand Down Expand Up @@ -193,3 +197,3 @@
plt.ylabel("Membership")
plt.legend()
plt.show()
Loading