Package fuzzy :: Package set :: Module Set
[hide private]
[frames] | no frames]

Source Code for Module fuzzy.set.Set

 1  # -*- coding: utf-8 -*- 
 2  # 
 3  # Copyright (C) 2009  Rene Liebscher 
 4  # 
 5  # This program is free software; you can redistribute it and/or modify it under 
 6  # the terms of the GNU Lesser General Public License as published by the Free  
 7  # Software Foundation; either version 3 of the License, or (at your option) any 
 8  # later version. 
 9  # 
10  # This program is distributed in the hope that it will be useful, but WITHOUT  
11  # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
12  # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 
13  # details. 
14  #  
15  # You should have received a copy of the GNU Lesser General Public License 
16  # along with this program; if not, see <http://www.gnu.org/licenses/>.  
17  # 
18   
19  """ 
20  Base class for all fuzzy sets. 
21  """ 
22   
23  __revision__ = "$Id: Set.py,v 1.24 2010-10-29 19:24:41 rliebscher Exp $" 
24   
25 -class Set(object):
26 """Base class for all types of fuzzy sets.""" 27
28 - def __call__(self, x):
29 """Return membership of x in this fuzzy set. 30 This method makes the set work like a function. 31 32 @param x: value x 33 @type x: float 34 @return: membership for value x 35 @rtype: float 36 """ 37 return 0.
38
39 - def getValuesXY(self, flat = True):
40 """Internal helper function to help convert arbitrary fuzzy sets in 41 fuzzy sets represented by a polygon.""" 42 return ((x,self(x)) for x in self.getValuesX())
43
44 - def getValuesX(self):
45 """Internal helper function to help convert arbitrary fuzzy sets in 46 fuzzy sets represented by a polygon.""" 47 raise NotImplementedError("Set has no values defined")
48
49 - def getCOG(self):
50 """Returns center of gravity. 51 52 @return: x-value of center of gravity 53 @rtype: float 54 """ 55 raise NotImplementedError("abstract class %s has no center of gravity." % self.__class__.__name__)
56
57 - def __repr__(self):
58 """Return representation of instance. 59 60 @return: representation of instance 61 @rtype: string 62 """ 63 return "%s.%s()" % (self.__class__.__module__, self.__class__.__name__)
64 65 # pylint: disable=W0611 66 # too make old code happy 67 from fuzzy.set.operations import norm,merge #@UnusedImport 68