1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 """Defuzzification which uses the left most (local) maximum."""
20
21 __revision__ = "$Id: LM.py,v 1.6 2010-03-28 18:40:33 rliebscher Exp $"
22
23 from fuzzy.defuzzify.Base import Base, DefuzzificationException
24
26 """Defuzzification which uses the left most (local) 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(LM, 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 else:
53 break
54
55 return x
56 except:
57
58 if self.failsafe is not None:
59
60 return self.failsafe
61 else:
62 raise
63
65 """Helper for representation of instance.
66
67 Add all own params to given list in params.
68 """
69 super(LM, self)._repr_params(params)
70 if self.failsafe: params.append("failsafe=%s" % self.failsafe)
71