1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 """Defuzzification which uses the left global maximum."""
20
21 __revision__ = "$Id: MaxLeft.py,v 1.8 2010-03-28 18:40:33 rliebscher Exp $"
22
23 from fuzzy.defuzzify.Base import Base, DefuzzificationException
24
26 """Defuzzification which uses the left global maximum."""
27
28 - def __init__(self, INF=None, ACC=None, failsafe=None, *args, **keywords):
29 """Initialize the defuzzification method with INF,ACC
30 and an optional value in case defuzzification is not possible"""
31 super(MaxLeft, self).__init__(INF, ACC, *args, **keywords)
32 self.failsafe = failsafe
33
35 """Defuzzification."""
36 try:
37 temp = self.accumulate(variable)
38
39
40 table = list(self.value_table(temp))
41
42 if len(table) == 0:
43 raise DefuzzificationException("no value calculable: complete undefined set")
44
45 y = table[0][1]
46 x = float('-inf')
47
48 for (x_, y_) in table[1:]:
49 if y_ > y:
50 y = y_
51 x = x_
52
53 return x
54 except:
55
56 if self.failsafe is not None:
57
58 return self.failsafe
59 else:
60 raise
61
63 """Helper for representation of instance.
64
65 Add all own params to given list in params.
66 """
67 super(MaxLeft, self)._repr_params(params)
68 if self.failsafe: params.append("failsafe=%s" % self.failsafe)
69