Package fuzzy :: Package defuzzify :: Module Dict
[hide private]
[frames] | no frames]

Source Code for Module fuzzy.defuzzify.Dict

 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  """Not a real defuzzification. 
20  Just stores the adjective memberships in a dictionary for output.""" 
21   
22  __revision__ = "$Id: Dict.py,v 1.9 2010-03-28 18:40:33 rliebscher Exp $" 
23   
24  from fuzzy.defuzzify.Base import Base 
25   
26 -class Dict(Base):
27 """Not a real defuzzification. 28 Just stores the adjective memberships 29 in a dictionary for output. 30 You should use in the adjectives instances of Set itself. 31 32 What can be done with this? 33 34 For example: 35 36 You want help with buying a car. 37 38 Input are your preferences:: 39 speed, payload (1-10), ... 40 (map to "very important, important, doesn't matter, not wanted, never" ;-) 41 42 Output are choices: 43 cars with adjectives: ferrari, truck, ... 44 45 rules are as follows:: 46 if speed->very_important && payload->never then car->ferrari 47 if payload->very_important then car->truck 48 ... and so on 49 50 Then you use this as follows:: 51 input variables 52 { speed:3, payload:1, ...} 53 ==> 54 output_variables 55 { car: { 56 ferrari:0.1, 57 truck: 1.0, 58 ... 59 } 60 } 61 """
62 - def __init__(self, *args, **keywords):
63 super(Dict, self).__init__(*args, **keywords)
64
65 - def getValue(self, variable):
66 """no defuzzification just return membership values""" 67 temp = {} 68 for name, adjective in variable.adjectives.items(): 69 # get precomputed adjective set membership 70 temp[name] = adjective.getMembership() 71 return temp
72