MII_Labs_Mochalov_PI-33/lab12/FuzzySet.py

22 lines
575 B
Python
Raw Normal View History

2024-05-11 02:04:28 +04:00
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