首页 > 解决方案 > 模糊逻辑:小费问题 - 输出永远不会超过阈值?

问题描述

我是 python 模糊逻辑的新手,并且一直在实现 skfuzzy 库。我看到的第一个例子是小费问题,这里 -> https://pythonhosted.org/scikit-fuzzy/auto_examples/plot_tipping_problem_newapi.html

我实现了自己的版本,但我发现输出(提示)永远不会超过某个阈值。例如,即使餐费是 10/10,服务是 10/10,也不会给 25% 的小费,反之亦然。最低的是4.33%和21%。这是为什么?

这是一个问题,因为我正在使用它来实现洗衣机。输出永远不会超过“平均值”的最后四分之一,并且没有输入永远能够达到输出的边界,这似乎很荒谬。有人可以引导我了解为什么会这样吗?

这是我的 jupyter 笔记本,因为有人要求 - 它与小费问题没有太大不同,但就是这样。

import numpy as np
import skfuzzy as fuzz
from skfuzzy import control as ctrl
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D


# New Antecedent/Consequent objects hold universe variables and membership
# functions
numdish = ctrl.Antecedent(np.arange(0, 51, 1), 'number of dishes')
dirtiness = ctrl.Antecedent(np.arange(0, 101, 1), 'level of dirtiness')
washtime = ctrl.Consequent(np.arange(0, 61, 1), 'wash time')

##numdish.automf(3)
numdish['low'] = fuzz.trimf(numdish.universe, [0,0,25])
numdish['average'] = fuzz.trimf(numdish.universe, [0, 25, 50])
numdish['high'] = fuzz.trimf(numdish.universe, [25, 50, 50])

##dirtiness.automf(3)
dirtiness['light'] = fuzz.trimf(dirtiness.universe, [0, 0, 40])
dirtiness['medium'] = fuzz.trimf(dirtiness.universe, [15, 50, 85])
dirtiness['heavy'] = fuzz.trimf(dirtiness.universe, [60, 100, 100])

washtime['short'] = fuzz.trimf(washtime.universe, [0, 0,25])
washtime['average'] = fuzz.trapmf(washtime.universe, [0, 25,35, 60])
washtime['long'] = fuzz.trimf(washtime.universe, [35,60,60])

##If numdish is low OR dirtiness is light, washtime will be short
rule1 = ctrl.Rule(numdish['low'] | dirtiness['light'], washtime['short'])

##If numdish is high AND dirtiness is heavy, washtime will be long
rule2 = ctrl.Rule(numdish['high'] & dirtiness['heavy'], washtime['long'])

##If numdish is high OR dirtiness is heavy, washtime will be long
rule3 = ctrl.Rule(numdish['high'] | dirtiness['heavy'], washtime['long'])

##If numdish is low AND dirtiness is light, washtime will be short
rule4 = ctrl.Rule(numdish['low'] & dirtiness['light'], washtime['short'])

##If numdish is average AND dirtiness is medium, washtime will be average
rule5 = ctrl.Rule(numdish['average'] & dirtiness['medium'], washtime['average'])

washtime_ctrl = ctrl.ControlSystem([rule1, rule2, rule3, rule4, rule5])

washtiming = ctrl.ControlSystemSimulation(washtime_ctrl)

# Here, you can pass in inputs to test the system. 
washtiming.input['number of dishes'] = 5
washtiming.input['level of dirtiness'] = 15

# Crunch the numbers
washtiming.compute()
print(washtiming.output['wash time'])
washtime.view(sim=washtiming)

即使将值设置为 0,0,最低洗涤时间仍为 8 分钟。即使将值设置为 50,100,最高洗涤时间仍为 51 分钟。

为什么它会停在这些边界上?不应该输入 0 盘子数量和 0 脏度等级给 0,反之亦然?

我希望这个问题现在很清楚。

标签: pythonfuzzy-logicfuzzyskfuzzy

解决方案


推荐阅读