1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 """Realize a S-shaped fuzzy set."""
20
21 __revision__ = "$Id: SFunction.py,v 1.19 2010-03-28 18:44:46 rliebscher Exp $"
22
23
24 from fuzzy.set.Function import Function
25
27 r"""
28 Realize a S-shaped fuzzy set::
29 __
30 /|
31 / |
32 /| |
33 _/ | |
34 | a |
35 | |
36 2*delta
37
38 See also U{http://pyfuzzy.sourceforge.net/demo/set/SFunction.png}
39
40 @ivar a: center of set.
41 @type a: float
42 @ivar delta: absolute distance between x-values for minimum and maximum.
43 @type delta: float
44 """
45
47 """Initialize a S-shaped fuzzy set.
48
49 @param a: center of set
50 @type a: float
51 @param delta: absolute distance between x-values for minimum and maximum
52 @type delta: float
53 """
54 super(SFunction, self).__init__()
55 self.a = a
56 self.delta = delta
57
59 """Return membership of x in this fuzzy set.
60 This method makes the set work like a function.
61
62 @param x: value for which the membership is to calculate
63 @type x: float
64 @return: membership
65 @rtype: float
66 """
67 a = self.a
68 d = self.delta
69 if x <= a-d:
70 return 0.0
71 if x <= a:
72 t = (x-a+d)/(2.0*d)
73 return 2.0*t*t
74 if x <= a+d:
75 t = (a-x+d)/(2.0*d)
76 return 1.0-2.0*t*t
77 return 1.0
78
83
85 """Return sequence of x-values so we get a smooth function."""
86 a = self.a
87 d = self.delta
88 stepsize = 2. * d / Function._resolution
89 x = a - d
90 for _ in range(Function._resolution):
91 yield x
92 x += stepsize
93 yield a + d
94
96 """Return representation of instance.
97
98 @return: representation of instance
99 @rtype: string
100 """
101 return "%s.%s(a=%s, delta=%s)" % (self.__class__.__module__, self.__class__.__name__, self.a, self.delta)
102