1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 """Describes a ... of a variable."""
19 __revision__ = "$Id: Adjective.py,v 1.16 2010-02-17 19:57:13 rliebscher Exp $"
20
21
22 from fuzzy.norm.Max import Max
23 from fuzzy.set.Set import Set
24
26 """Describes a ... of a variable.
27
28 @ivar set: fuzzy set
29 @type set: L{fuzzy.set.Set.Set}
30 @ivar COM: norm (if None the class default _COM is used.)
31 @type COM: L{fuzzy.norm.Norm.Norm}
32 @ivar membership: set or calculated membership
33 @type membership: float
34 @cvar _COM: class default is instance variable is None
35 @type _COM: L{fuzzy.norm.Norm.Norm}
36 """
37
38
39 _COM = Max()
40 _set = Set()
41
43 """Initialize adjective.
44
45 @param set: fuzzy set
46 @type set: L{fuzzy.set.Set.Set}
47 @param COM: norm (if None the class default _COM is used.)
48 @type COM: L{fuzzy.norm.Norm.Norm}
49 """
50 self.set = set or Adjective._set
51 self.membership = None
52 self.COM = COM
53
55 """Get membership for an input value from the fuzzy set."""
56 self.membership = self.set(value)
57
59 """Return membership set in this adjective."""
60 if self.membership is None:
61 return 0.0
62 else:
63 return self.membership
64
66 """Set membership of this adjective as result
67 of a rule calculation,
68 if already set use COM norm to merge
69 old and new value."""
70
71 if self.membership is None:
72 self.membership = value
73 else:
74 self.membership = (self.COM or self._COM)(
75 self.membership,
76 value
77 )
78
80 """Reset membership to unknown value (None)."""
81 self.membership = None
82
84 """Find own name in given system.
85 Returns a tuple (var_name,adj_name) of None."""
86 return system.findAdjectiveName(self)
87
89 """Return representation of instance.
90
91 @return: representation of instance
92 @rtype: string
93 """
94 params = []
95 if self.set is not Adjective._set: params.append("set=%s" % repr(self.set))
96 if self.COM: params.append("COM=%s" % repr(self.COM))
97 return "%s.%s(%s)" % (self.__class__.__module__, self.__class__.__name__, ", ".join(params))
98