1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 """Defuzzification which uses the center of gravity method."""
20
21 __revision__ = "$Id: COG.py,v 1.9 2010-03-28 18:40:33 rliebscher Exp $"
22
23 from fuzzy.defuzzify.Base import Base
24
26 """Defuzzification which uses
27 the center of gravity method."""
28
29 - def __init__(self, INF=None, ACC=None, failsafe=None, segment_size=None, *args, **keywords):
30 """
31 @param failsafe: if is not possible to calculate a center of gravity,
32 return this value if not None or forward the exception
33 @param segment_size: maximum length of segment in polygon of accumulated result set
34 """
35 super(COG, self).__init__(INF, ACC, *args, **keywords)
36 self.failsafe = failsafe
37 self.segment_size = segment_size
38
40 """Defuzzification using center of gravity method."""
41 temp = self.accumulate(variable, self.segment_size)
42 try:
43 return temp.getCOG()
44 except:
45
46 if self.failsafe is not None:
47
48 return self.failsafe
49 else:
50
51 raise
52
54 """Helper for representation of instance.
55
56 Add all own params to given list in params.
57 """
58 super(COG, self)._repr_params(params)
59 if self.failsafe: params.append("failsafe=%s" % self.failsafe)
60 if self.segment_size: params.append("segment_size=%s" % self.segment_size)
61