1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 """Abstract base class for defuzzification which results in a numeric value."""
20
21 __revision__ = "$Id: Base.py,v 1.12 2010-03-28 18:40:33 rliebscher Exp $"
22
23
24 from fuzzy.norm.Max import Max
25 from fuzzy.norm.Min import Min
26 from fuzzy.set.Set import norm, merge
27 from fuzzy.Exception import FuzzyException
28
31
33 """Abstract base class for defuzzification
34 which results in a numeric value.
35
36 @ivar INF: inference norm, used with set of adjective and given value for it
37 @type INF: L{fuzzy.norm.Norm.Norm}
38 @ivar ACC: norm for accumulation of set of adjectives
39 @type ACC: L{fuzzy.norm.Norm.Norm}
40 @cvar _INF: default value when INF is None
41 @type _INF: L{fuzzy.norm.Norm.Norm}
42 @cvar _ACC: default value when ACC is None
43 @type _ACC: L{fuzzy.norm.Norm.Norm}
44 @ivar activated_sets: results of activation of adjectives of variable.
45 @type activated_sets: {string:L{fuzzy.set.Polygon.Polygon}}
46 @ivar accumulated_set: result of accumulation of activated sets
47 @type accumulated_set: L{fuzzy.set.Polygon.Polygon}
48 """
49
50
51 _INF = Min()
52 _ACC = Max()
53
55 """
56 @param INF: inference norm, used with set of adjective and given value for it
57 @type INF: L{fuzzy.norm.Norm.Norm}
58 @param ACC: norm for accumulation of set of adjectives
59 @type ACC: L{fuzzy.norm.Norm.Norm}
60 """
61 self.ACC = ACC
62 self.INF = INF
63 self.activated_sets = {}
64 self.accumulated_set = None
65
67 """Defuzzification."""
68 raise NotImplementedError("don't use the abstract base class")
69
70
71
72 - def accumulate(self, variable, segment_size=None):
73 """combining adjective values into one set"""
74 self.activated_sets = {}
75 temp = None
76 for name, adjective in variable.adjectives.items():
77
78 temp2 = norm((self.INF or self._INF), adjective.set, adjective.getMembership(), segment_size)
79 self.activated_sets[name] = temp2
80
81 if temp is None:
82 temp = temp2
83 else:
84 temp = merge((self.ACC or self._ACC), temp, temp2, segment_size)
85 self.accumulated_set = temp
86 return temp
87
89 """get a value table of the polygon representation"""
90
91 return set.getValuesXY()
92
94 """Return representation of instance.
95
96 @return: representation of instance
97 @rtype: string
98 """
99 params = []
100 self._repr_params(params)
101 return "%s.%s(%s)" % (self.__class__.__module__, self.__class__.__name__, ", ".join(params))
102
104 """Helper for representation of instance.
105
106 Add all own params to given list in params.
107 """
108 if self.INF: params.append("INF=%s" % repr(self.INF))
109 if self.ACC: params.append("ACC=%s" % repr(self.ACC))
110