2017-05-29 42 views
0

我已經建立了一個模糊控制系統,它接受三個輸入(x,y,z),它們接受(差,平均或好的)值並返回一個輸出(w)平均值或高值)。不幸的是,當我測試系統時,我得到一個斷言錯誤,沒有任何額外的信息。下面顯示了用於構建系統的代碼。模糊系統在輸入期間python斷言錯誤

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: 

我不知道是否有人有一個想法,其中該代碼出了問題。

回答

1

第一個問題是一個錯字,

z = ctrl.Antecedent(np.arange(0,1,0.001), 'y') # should be 'z'! 

現在的代碼在運行時,返回

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 
+0

感謝名單@Hugh。我修正了錯字錯誤,並將所有成員函數調整爲值3,現在它正常工作。 – Bander