Package fuzzy :: Package norm :: Module ParametricNorm
[hide private]
[frames] | no frames]

Source Code for Module fuzzy.norm.ParametricNorm

 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      Base class for any kind of parametric fuzzy norm. 
20  """ 
21   
22  __revision__ = "$Id: ParametricNorm.py,v 1.16 2010-10-29 19:24:41 rliebscher Exp $" 
23   
24  from fuzzy.norm.Norm import Norm 
25  from fuzzy.utils import prop 
26 27 -class ParametricNorm(Norm):
28 """Abstract base class for any parametric fuzzy norm 29 30 @ivar p: parameter for norm 31 @type p: float 32 """ 33 _range = None 34
35 - def __init__(self, type, param):
36 """Initialize type and parameter 37 38 @param param: parameter for norm 39 @type param: float 40 """ 41 super(ParametricNorm, self).__init__(type) 42 self.p = param
43 44 # pylint: disable=E0202,E0211 45 #ID:E0202 ParametricNorm.p: An attribute inherited from ParametricNorm hide this method 46 #ID:E0211 TParametricNorm.p: Method has no argument 47 @prop
48 - def p(): #@NoSelf
49 """x 50 @type: float""" 51 def fget(self): # pylint: disable=W0612,C0111 52 return self._p
53 def fset(self, value): # pylint: disable=W0612,C0111 54 self._checkParam(value) 55 self._p = value 56 return locals() 57 58 # pylint: disable=E0211 59 #ID:E0211 TParametricNorm.p_range: Method has no argument 60 @prop
61 - def p_range(): #@NoSelf
62 """range(s) of valid values for p""" 63 def fget(self): # pylint: disable=W0612,C0111 64 return self._range 65 return locals() 66
67 - def _checkParam(self, value):
68 """check parameter if allowed for paramter p 69 @param value: the value to be checked 70 @type value: float""" 71 from fuzzy.utils import checkRange 72 if not checkRange(value, self._range): 73 from fuzzy.Exception import FuzzyException 74 raise FuzzyException("Parameter value %s is not allowed" % str(value))
75
76 - def __repr__(self):
77 """Return representation of instance. 78 79 @return: representation of instance 80 @rtype: string 81 """ 82 return "%s.%s(param=%s)" % (self.__class__.__module__, self.__class__.__name__, self._p)
83