在这个例子中如何打印输出值?

Posted

技术标签:

【中文标题】在这个例子中如何打印输出值?【英文标题】:How to print the output value in this example? 【发布时间】: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-模糊包)本身。 【参考方案1】:

在这种情况下你必须通过小费

 tipping.output['tip']

【讨论】:

以上是关于在这个例子中如何打印输出值?的主要内容,如果未能解决你的问题,请参考以下文章

如何显示(输出)在二进制搜索树中查找值所需的迭代次数?

python中如何把打印出来的东西隐藏

python如何打印输出

Java或C#调用命令行批处理命令如何获得返回值

c语言输入的值如何在同一行打印输出

如何在循环中单行打印?