@@ -68,7 +68,7 @@ class Domain:
68
68
in a subclass to enable concurrent evaluation for performance improvement.
69
69
"""
70
70
71
- __slots__ = ["name " , "low " , "high " , "res " , "_sets" ]
71
+ __slots__ = ["_name " , "_low " , "_high " , "_res " , "_sets" ]
72
72
73
73
def __init__ (
74
74
self ,
@@ -83,15 +83,15 @@ def __init__(
83
83
assert res > 0 , "resolution can't be negative or zero"
84
84
assert isinstance (name , str ), "Name must be a string."
85
85
assert str .isidentifier (name ), "Name must be a valid identifier."
86
- self .name = name
87
- self .high = high
88
- self .low = low
89
- self .res = res
86
+ self ._name = name
87
+ self ._high = high
88
+ self ._low = low
89
+ self ._res = res
90
90
self ._sets = {} if sets is None else sets # Name: Set(Function())
91
91
92
92
def __call__ (self , x : float ) -> dict [str , float ]:
93
93
"""Pass a value to all sets of the domain and return a dict with results."""
94
- if not (self .low <= x <= self .high ):
94
+ if not (self ._low <= x <= self ._high ):
95
95
raise FuzzyWarning (f"{ x } is outside of domain!" )
96
96
return {name : s .func (x ) for name , s in self ._sets .items ()}
97
97
@@ -101,21 +101,21 @@ def __len__(self) -> int:
101
101
102
102
def __str__ (self ) -> str :
103
103
"""Return a string to print()."""
104
- return self .name
104
+ return self ._name
105
105
106
106
def __repr__ (self ) -> str :
107
107
"""Return a string so that eval(repr(Domain)) == Domain."""
108
- return f"Domain('{ self .name } ', { self .low } , { self .high } , res={ self .res } , sets={ self ._sets } )"
108
+ return f"Domain('{ self ._name } ', { self ._low } , { self ._high } , res={ self ._res } , sets={ self ._sets } )"
109
109
110
110
def __eq__ (self , other : object ) -> bool :
111
111
"""Test equality of two domains."""
112
112
if not isinstance (other , Domain ):
113
113
return False
114
114
return all ([
115
- self .name == other .name ,
116
- self .low == other .low ,
117
- self .high == other .high ,
118
- self .res == other .res ,
115
+ self ._name == other ._name ,
116
+ self ._low == other ._low ,
117
+ self ._high == other ._high ,
118
+ self ._res == other ._res ,
119
119
self ._sets == other ._sets ,
120
120
])
121
121
@@ -161,10 +161,10 @@ def range(self) -> Array:
161
161
162
162
High upper bound is INCLUDED unlike range.
163
163
"""
164
- if int (self .res ) == self .res :
165
- return np .arange (self .low , self .high + self .res , int (self .res ))
164
+ if int (self ._res ) == self ._res :
165
+ return np .arange (self ._low , self ._high + self ._res , int (self ._res ))
166
166
else :
167
- return np .linspace (self .low , self .high , int ((self .high - self .low ) / self .res ) + 1 )
167
+ return np .linspace (self ._low , self ._high , int ((self ._high - self ._low ) / self ._res ) + 1 )
168
168
169
169
def min (self , x : float ) -> float :
170
170
"""Standard way to get the min over all membership funcs.
@@ -428,13 +428,13 @@ def __repr__(self) -> str:
428
428
# print(x)
429
429
430
430
if self .domain is not None :
431
- return f"{ self .domain .name } .{ self .name } "
431
+ return f"{ self .domain ._name } .{ self .name } " # type: ignore
432
432
return f"Set({ __name__ } ({ self .func .__qualname__ } )"
433
433
434
434
def __str__ (self ) -> str :
435
435
"""Return a string for print()."""
436
436
if self .domain is not None :
437
- return f"{ self .domain .name } .{ self .name } "
437
+ return f"{ self .domain ._name } .{ self .name } " # type: ignore
438
438
return f"dangling Set({ self .func .__name__ } "
439
439
440
440
def normalized (self ) -> Set :
@@ -511,9 +511,9 @@ def __call__(self, values: dict[Domain, float | int], method: str = "cog") -> fl
511
511
sum_weighted_cogs += then_set .center_of_gravity () * weight
512
512
sum_weights += weight
513
513
index = sum_weighted_cogs / sum_weights
514
- return (target_domain .high - target_domain .low ) / len (
514
+ return (target_domain ._high - target_domain ._low ) / len ( # type: ignore
515
515
target_domain .range
516
- ) * index + target_domain .low
516
+ ) * index + target_domain ._low # type: ignore
517
517
case "centroid" : # centroid == center of mass == center of gravity for simple solids
518
518
raise NotImplementedError ("actually the same as 'cog' if densities are uniform." )
519
519
case "bisector" :
0 commit comments