Skip to content

Commit dc6f407

Browse files
committed
typing fixed
1 parent bc420cd commit dc6f407

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/fuzzylogic/classes.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ def __init__(
8989
self._res = res
9090
self._sets = {} if sets is None else sets # Name: Set(Function())
9191

92-
def __call__(self, x: float) -> dict[str, float]:
92+
def __call__(self, x: float) -> dict[Set, float]:
9393
"""Pass a value to all sets of the domain and return a dict with results."""
9494
if not (self._low <= x <= self._high):
9595
raise FuzzyWarning(f"{x} is outside of domain!")
96-
return {name: s.func(x) for name, s in self._sets.items()}
96+
return {self._sets[name]: s.func(x) for name, s in self._sets.items()}
9797

9898
def __len__(self) -> int:
9999
"""Return the size of the domain, as the actual number of possible values, calculated internally."""
@@ -423,19 +423,18 @@ def __repr__(self) -> str:
423423
"""
424424

425425
# experimental
426-
# x = f"{self.func.__qualname__.split('.')[0]}({self.func.__closure__[0].
427-
# cell_contents.__code__.co_nlocals}))"
426+
# x = f"{self.func.__qualname__.split('.')[0]}({self.func.__closure__[0].cell_contents.__code__.co_nlocals}))" # noqa: E501
428427
# print(x)
429428

430429
if self.domain is not None:
431430
return f"{self.domain._name}.{self.name}" # type: ignore
432-
return f"Set({__name__}({self.func.__qualname__})"
431+
return f"Set(({self.func.__qualname__})"
433432

434433
def __str__(self) -> str:
435434
"""Return a string for print()."""
436435
if self.domain is not None:
437436
return f"{self.domain._name}.{self.name}" # type: ignore
438-
return f"dangling Set({self.func.__name__}"
437+
return f"Set({self.func.__name__})"
439438

440439
def normalized(self) -> Set:
441440
"""Return a set that is normalized *for this domain* with 1 as max."""

src/fuzzylogic/combinators.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ def F(z: float) -> float:
7474
def product(*guncs: Membership) -> Membership:
7575
"""AND variant."""
7676
funcs = list(guncs)
77+
epsilon = 1e-10 # Small value to prevent underflow
7778

7879
def F(z: float) -> float:
79-
return reduce(multiply, (f(z) for f in funcs))
80+
return reduce(multiply, (max(f(z), epsilon) for f in funcs))
8081

8182
return F
8283

@@ -238,6 +239,7 @@ def simple_disjoint_sum(*funcs: Membership) -> Membership: # sourcery skip: unw
238239
Basic idea:
239240
(A AND ~B) OR (~A AND B)
240241
242+
>>> from .functions import noop
241243
>>> xor = simple_disjoint_sum(noop(), noop())
242244
>>> xor(0)
243245
0

0 commit comments

Comments
 (0)