22 lines
575 B
Python
22 lines
575 B
Python
|
class FuzzySet:
|
||
|
def __init__(self, name: str, a: float, b: float, c: float, d: float):
|
||
|
self.name = name
|
||
|
self.a = a
|
||
|
self.b = b
|
||
|
self.c = c
|
||
|
self.d = d
|
||
|
|
||
|
def affiliation(self, x: float) -> float:
|
||
|
if x <= self.a or x >= self.d:
|
||
|
return 0
|
||
|
if self.b <= x <= self.c:
|
||
|
return 1
|
||
|
|
||
|
if x <= self.b:
|
||
|
return (x - self.a) / (self.b - self.a)
|
||
|
else:
|
||
|
return (self.d - x) / (self.d - self.c)
|
||
|
|
||
|
def defuzzification(self) -> float:
|
||
|
return (self.c + self.b) / 2
|