def almost_none() -> mf.MembershipFunction: """ Returns: mf.TrapezoidMembershipFunction """ almost_none = mf.TrapezoidMembershipFunction(0, 0, 0.05, 0.30) almost_none.name = 'almost none' return almost_none
def many() -> mf.MembershipFunction: """ Returns: mf.TriangularMembershipFunction """ many = mf.TriangularMembershipFunction(0.50, 0.70, 0.90) many.name = 'many' return many
def most() -> mf.MembershipFunction: """ Returns: mf.TrapezoidMembershipFunction """ most = mf.TrapezoidMembershipFunction(0.70, 0.90, 1, 1) most.name = 'most' return most
def few() -> mf.MembershipFunction: """ Returns: mf.TriangularMembershipFunction """ few = mf.TriangularMembershipFunction(0.05, 0.30, 0.50) few.name = 'few' return few
def some() -> mf.MembershipFunction: """ Returns: mf.TriangularMembershipFunction """ some = mf.TriangularMembershipFunction(0.30, 0.50, 0.70) some.name = 'some' return some
def get_membership_functions(self): result = {} start, end, points = self.start, self.end, self.points n = len(points) for i in range(n): if i == 0: cur = mf.TrapezoidMembershipFunction(start, start, points[0], points[1]) elif i + 1 == n: cur = mf.TrapezoidMembershipFunction(points[i - 1], points[i], end, end) else: cur = mf.TriangularMembershipFunction(points[i - 1], points[i], points[i + 1]) cur.name = self.aliases[i] result[self.aliases[i]] = cur return result
class TestRangeExtraction(unittest.TestCase): triangle_mf = mf.TriangularMembershipFunction(0, 10, 20) trap_mf = mf.TrapezoidMembershipFunction(0, 10, 20, 30) def test_triangle(self): l, r = self.triangle_mf.extract_range(0.5) self.assertAlmostEqual(5, l) self.assertAlmostEqual(15, r) def test_trapezoid(self): l, r = self.trap_mf.extract_range(0.5) self.assertAlmostEqual(5, l) self.assertAlmostEqual(25, r) def test_trapezoid_with_very(self): modifiers = dict_modifiers() very = modifiers['very'] self.trap_mf.set_modifier(very) l, r = self.trap_mf.extract_range(0.5) print('very', l, r) self.assertAlmostEqual(7.071067804794407, l) self.assertAlmostEqual(22.928932195205594, r) self.trap_mf.set_modifier(None)
def almost_none(self) -> mf.MembershipFunction: return mf.TrapezoidMembershipFunction(self.min, self.min, self._point(0.05), self._point(0.30))
def most(self) -> mf.MembershipFunction: return mf.TrapezoidMembershipFunction(self._point(0.70), self._point(0.90), self.max, self.max)
def many(self) -> mf.MembershipFunction: return mf.TriangularMembershipFunction(self._point(0.50), self._point(0.70), self._point(0.90))
def some(self) -> mf.MembershipFunction: return mf.TriangularMembershipFunction(self._point(0.30), self._point(0.50), self._point(0.70))
def few(self) -> mf.MembershipFunction: return mf.TriangularMembershipFunction(self._point(0.05), self._point(0.30), self._point(0.50))