Package fuzzy :: Package operator :: Module Compound
[hide private]
[frames] | no frames]

Source Code for Module fuzzy.operator.Compound

 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  """The Compound class takes values of several input operators  and  
19  processes them through a given norm.""" 
20  __revision__ = "$Id: Compound.py,v 1.16 2010-10-29 19:24:41 rliebscher Exp $" 
21   
22  from fuzzy.operator.Operator import Operator 
23   
24 -class Compound(Operator): # pylint: disable=R0903
25 """Take values of input operators and process them 26 through the given norm. 27 28 @ivar norm: how to combine inputs. (eg. Min,Max,...) 29 @type norm: L{fuzzy.norm.Norm.Norm} 30 @ivar inputs: list of inputs (subclassed from L{fuzzy.operator.Operator.Operator}). 31 """ 32
33 - def __init__(self, norm, *inputs):
34 """Constructor. 35 36 @param norm: how to combine inputs. (eg. Min,Max,...) 37 @type norm: L{fuzzy.norm.Norm.Norm} 38 @param inputs: list of inputs (subclassed from L{fuzzy.operator.Operator.Operator}). 39 """ 40 super(Compound, self).__init__() 41 self.norm = norm 42 self.inputs = inputs
43
44 - def __call__(self):
45 """Get current value of input and combine them with help of norm.""" 46 return self.norm(*[x() for x in self.inputs])
47
48 - def __repr__(self):
49 """Return representation of instance. 50 51 @return: representation of instance 52 @rtype: string 53 """ 54 return "%s.%s(norm=%s, inputs=%s)" % ( 55 self.__class__.__module__, 56 self.__class__.__name__, 57 repr(self.norm), 58 repr(self.inputs), 59 )
60