模糊系统 python 输入时断言错误
fuzzy system python assertion error during input
我建立了一个模糊控制系统,它接受三个输入 (x,y,z) 接受(差、平均或好)值,returns 一个输出 (w) 接受(低、平均) , 或高) 值。不幸的是,当我测试系统时,我得到一个没有任何附加信息的断言错误。用于构建系统的代码如下所示。
import numpy as np
import skfuzzy as fuzz
from skfuzzy import control as ctrl
import matplotlib.pyplot as plt
from matplotlib import rc
x=ctrl.Antecedent(np.arange(0,1,0.001), 'x')
y=ctrl.Antecedent(np.arange(0,1,0.001), 'y')
z=ctrl.Antecedent(np.arange(0,1,0.001), 'y')
w=ctrl.Consequent(np.arange(0,1,0.1),'w')
x.automf(3)
y.automf(5)
z.automf(7)
w['low'] = fuzz.trimf(w.universe, [0, 0, 0.3])
w['average'] = fuzz.trimf(w.universe, [0.25, 0.5, 0.75])
w['high'] = fuzz.trimf(w.universe, [0.7, 1, 1])
rule1 = ctrl.Rule(x['poor'] & y['poor'] & z['poor'], w['low'])
rule2 = ctrl.Rule(x['poor'] & y['poor'] & z['good'], w['low'])
rule3 = ctrl.Rule(x['poor'] & y['good'] & z['poor'], w['high'])
rule4 = ctrl.Rule(x['poor'] & y['good'] & z['good'], w['average'])
rule5 = ctrl.Rule(x['good'] & y['poor'] & z['poor'], w['low'])
rule6 = ctrl.Rule(x['good'] & y['poor'] & z['good'], w['low'])
rule7 = ctrl.Rule(x['good'] & y['good'] & z['poor'], w['average'])
rule8 = ctrl.Rule(x['good'] & y['good'] & z['good'], w['low'])
w_ctrl = ctrl.ControlSystem([rule1, rule2, rule3, rule4, rule5, rule6, rule7, rule8])
wResults= ctrl.ControlSystemSimulation(w_ctrl)
wResults.input['x'] = 0.03
wResults.input['y'] = 0.7
wResults.input['z'] = 0.01
wResults.compute()
我得到的错误是:
AssertionError Traceback (most recent call last)
<ipython-input-162-4519156d7582> in <module>()
25 wResults= ctrl.ControlSystemSimulation(w_ctrl)
26 wResults.input['x'] = 0.03
---> 27 wResults.input['y'] = 0.7
28 wResults.input['z'] = 0.01
29 wResults.compute()
C:\Users\user01\Anaconda3\lib\site-packages\skfuzzy\control\controlsystem.py in __setitem__(self, key, value)
129 if len(matches) == 0:
130 raise ValueError("Unexpected input: " + key)
--> 131 assert len(matches) == 1
132 var = matches[0]
133
AssertionError:
我想知道是否有人知道这段代码哪里出错了。
第一个问题是打字错误,
z = ctrl.Antecedent(np.arange(0,1,0.001), 'y') # should be 'z'!
现在的代码,当运行,returns
ValueError: Crisp output cannot be calculated, likely because the system is too sparse.
Check to make sure this set of input values will activate at least one connected Term
in each Antecedent via the current set of Rules.
...因为
wResults.input['y'] = 0.7 # classifies as "decent",
# and you haven't given any relevant rules
我建立了一个模糊控制系统,它接受三个输入 (x,y,z) 接受(差、平均或好)值,returns 一个输出 (w) 接受(低、平均) , 或高) 值。不幸的是,当我测试系统时,我得到一个没有任何附加信息的断言错误。用于构建系统的代码如下所示。
import numpy as np
import skfuzzy as fuzz
from skfuzzy import control as ctrl
import matplotlib.pyplot as plt
from matplotlib import rc
x=ctrl.Antecedent(np.arange(0,1,0.001), 'x')
y=ctrl.Antecedent(np.arange(0,1,0.001), 'y')
z=ctrl.Antecedent(np.arange(0,1,0.001), 'y')
w=ctrl.Consequent(np.arange(0,1,0.1),'w')
x.automf(3)
y.automf(5)
z.automf(7)
w['low'] = fuzz.trimf(w.universe, [0, 0, 0.3])
w['average'] = fuzz.trimf(w.universe, [0.25, 0.5, 0.75])
w['high'] = fuzz.trimf(w.universe, [0.7, 1, 1])
rule1 = ctrl.Rule(x['poor'] & y['poor'] & z['poor'], w['low'])
rule2 = ctrl.Rule(x['poor'] & y['poor'] & z['good'], w['low'])
rule3 = ctrl.Rule(x['poor'] & y['good'] & z['poor'], w['high'])
rule4 = ctrl.Rule(x['poor'] & y['good'] & z['good'], w['average'])
rule5 = ctrl.Rule(x['good'] & y['poor'] & z['poor'], w['low'])
rule6 = ctrl.Rule(x['good'] & y['poor'] & z['good'], w['low'])
rule7 = ctrl.Rule(x['good'] & y['good'] & z['poor'], w['average'])
rule8 = ctrl.Rule(x['good'] & y['good'] & z['good'], w['low'])
w_ctrl = ctrl.ControlSystem([rule1, rule2, rule3, rule4, rule5, rule6, rule7, rule8])
wResults= ctrl.ControlSystemSimulation(w_ctrl)
wResults.input['x'] = 0.03
wResults.input['y'] = 0.7
wResults.input['z'] = 0.01
wResults.compute()
我得到的错误是:
AssertionError Traceback (most recent call last)
<ipython-input-162-4519156d7582> in <module>()
25 wResults= ctrl.ControlSystemSimulation(w_ctrl)
26 wResults.input['x'] = 0.03
---> 27 wResults.input['y'] = 0.7
28 wResults.input['z'] = 0.01
29 wResults.compute()
C:\Users\user01\Anaconda3\lib\site-packages\skfuzzy\control\controlsystem.py in __setitem__(self, key, value)
129 if len(matches) == 0:
130 raise ValueError("Unexpected input: " + key)
--> 131 assert len(matches) == 1
132 var = matches[0]
133
AssertionError:
我想知道是否有人知道这段代码哪里出错了。
第一个问题是打字错误,
z = ctrl.Antecedent(np.arange(0,1,0.001), 'y') # should be 'z'!
现在的代码,当运行,returns
ValueError: Crisp output cannot be calculated, likely because the system is too sparse.
Check to make sure this set of input values will activate at least one connected Term
in each Antecedent via the current set of Rules.
...因为
wResults.input['y'] = 0.7 # classifies as "decent",
# and you haven't given any relevant rules