Skip to content

Commit 8422b3b

Browse files
authored
Update fuzzy_operations.py
1 parent 7d337fc commit 8422b3b

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

fuzzy_logic/fuzzy_operations.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -138,23 +138,27 @@ def membership(self, x: float) -> float:
138138
msg = f"Invalid value {x} for fuzzy set {self}"
139139
raise ValueError(msg)
140140

141-
def union(self, other) -> FuzzySet:
142-
"""
143-
Calculate the union of this fuzzy set with another fuzzy set.
144-
Args:
145-
other (FuzzySet): Another fuzzy set to union with.
146-
Returns:
147-
FuzzySet: A new fuzzy set representing the union.
148-
149-
>>> FuzzySet("a", 0.1, 0.2, 0.3).union(FuzzySet("b", 0.4, 0.5, 0.6))
150-
FuzzySet(name='a U b', left_boundary=0.1, peak=0.6, right_boundary=0.35)
151-
"""
152-
return FuzzySet(
153-
f"{self.name} U {other.name}",
154-
min(self.left_boundary, other.left_boundary),
155-
max(self.right_boundary, other.right_boundary),
156-
(self.peak + other.peak) / 2,
157-
)
141+
def union(self, other: FuzzySet) -> FuzzySet:
142+
"""
143+
Calculate the union of this fuzzy set with another fuzzy set.
144+
The union of two fuzzy sets is determined by taking the maximum
145+
membership value at each point.
146+
147+
Args:
148+
other (FuzzySet): Another fuzzy set to union with.
149+
150+
Returns:
151+
FuzzySet: A new fuzzy set representing the union.
152+
153+
>>> FuzzySet("a", 0.1, 0.2, 0.3).union(FuzzySet("b", 0.4, 0.5, 0.6))
154+
FuzzySet(name='a U b', left_boundary=0.1, peak=0.5, right_boundary=0.6)
155+
"""
156+
return FuzzySet(
157+
f"{self.name} U {other.name}",
158+
min(self.left_boundary, other.left_boundary),
159+
max(self.peak, other.peak),
160+
max(self.right_boundary, other.right_boundary)
161+
)
158162

159163
def plot(self):
160164
"""

0 commit comments

Comments
 (0)