【发布时间】:2017-11-12 10:32:01
【问题描述】:
我正在尝试测试以下链接中存在的模糊逻辑提示示例:click here
我的问题是如何让这个控制系统以['low', 'medium', 'high'] 的形式打印输出值(小费),而不是打印实际的计算值。
以下是示例代码
import matplotlib.pyplot as plt
import numpy as np
import skfuzzy as fuzzy
from skfuzzy import control
# Universe variables
quality = control.Antecedent(np.arange(0, 11, 1), 'quality')
service = control.Antecedent(np.arange(0, 11, 1), 'service')
tip = control.Consequent(np.arange(0, 26, 1), 'tip')
# Auto-membership function population (3,5,7)
quality.automf(3)
service.automf(3)
# Custom triangle membership functions
tip['low'] = fuzzy.trimf(tip.universe, [0, 0, 13])
tip['medium'] = fuzzy.trimf(tip.universe, [0, 13, 25])
tip['high'] = fuzzy.trimf(tip.universe, [13, 25, 25])
#view memberships
#quality.view()
#service.view()
#tip.view()
#Fuzzy rules
rule1 = control.Rule(quality['poor'] | service['poor'], tip['low'])
rule2 = control.Rule(service['average'], tip['medium'])
rule3 = control.Rule(service['good'] | quality['good'], tip['high'])
#Control System Creation and Simulation
tipping_ctrl = control.ControlSystem([rule1, rule2, rule3])
tipping = control.ControlSystemSimulation(tipping_ctrl)
# Pass inputs to the ControlSystem & compute
tipping.input['quality'] = 10
tipping.input['service'] = 3
tipping.compute()
#visualize & view
print (tipping.output)
tip.view(sim=tipping)
plt.show()
【问题讨论】:
-
不是有
if range1 <= val < range2: print "low" elif range2 <= val < range3: print "medium" else: print "high"那么简单 -
@NikhilRajawat 感谢您的评论,如果无法使用模糊控制系统(scikit-模糊包)本身。
标签: python matplotlib scipy scikit-learn fuzzy-logic