1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 """Represents a fuzzy rule."""
19 __revision__ = "$Id: Rule.py,v 1.17 2010-02-17 19:57:13 rliebscher Exp $"
20
21 from fuzzy.norm.Min import Min
22
24 """This is realizes an important part of the inference engine.
25 It represents and calculates the value of a fuzzy rule
26 and sets the given adjective to the appropriate value.
27
28 @cvar _CER: the default value (=Min()) for the norm used to calculate the certainty of a rule.
29 @type _CER: L{fuzzy.norm.Norm.Norm}
30 @ivar adjective: fuzzy adjective to set
31 @type adjective: L{fuzzy.Adjective.Adjective}
32 @ivar operator: Operator which provides the value to set
33 @type operator: L{fuzzy.operator.Operator.Operator}
34 @ivar certainty: how sure are we about this rule
35 @type certainty: float
36 @ivar CER: fuzzy norm to use with certainty (normally a t-norm)
37 @type CER: L{fuzzy.norm.Norm.Norm}
38 """
39
40
41 _CER = Min()
42
43 - def __init__(self, adjective, operator, certainty=1.0, CER=None):
44 """Initialize instance.
45 @param adjective: fuzzy adjective to set
46 @type adjective: L{fuzzy.Adjective.Adjective}
47 @param operator: Operator which provides the value to set
48 @type operator: L{fuzzy.operator.Operator.Operator}
49 @param certainty: how sure are we about this rule
50 @type certainty: float
51 @param CER: fuzzy norm to use with certainty (normally a t-norm)
52 @type CER: L{fuzzy.norm.Norm.Norm}
53 """
54
55 self.adjective = adjective
56 self.operator = operator
57 self.certainty = certainty
58 self.CER = CER
59
82
84 """Lookup the name given this rule in the given system"""
85 return system.findRuleName(self)
86
88 """Return representation of instance.
89
90 @return: representation of instance
91 @rtype: string
92 """
93 params = []
94 params.append("adjective=%s" % object.__repr__(self.adjective))
95 params.append("operator=%s" % repr(self.operator))
96 if self.certainty != 1.0: params.append("certainty=%s" % self.certainty)
97 if self.CER: params.append("CER=%s" % repr(self.CER))
98 return "%s.%s(%s)" % (self.__class__.__module__, self.__class__.__name__, ", ".join(params))
99