+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

解决断言错误和值错误的解决方案?

发布于2021-01-17 16:25     阅读(633)     评论(0)     点赞(5)     收藏(5)


0

1

2

3

4

5

6

7

8

9

这是我的代码有问题。

AssertionError:解模糊时总面积为零!

ValueError:无法计算清晰的输出,可能是因为系统太稀疏。检查以确保这组输入值将通过当前的一组规则激活每个前项中的至少一个连接的术语。运行我的代码后,显示这两个错误的顶部。

代码下面是我运行后的完整错误消息。我能知道问题在哪里吗?

import numpy as np
import skfuzzy as fuzz
from skfuzzy import control as ctrl

Temp = ctrl.Antecedent(np.arange(0,101,1),'temperature')
Temp['Low'] = fuzz.trapmf(Temp.universe, [0,0,20,30])
Temp['Medium'] = fuzz.trimf(Temp.universe, [25,50,70])
Temp['High'] = fuzz.trapmf(Temp.universe, [60,80,100,100])

Humidity = ctrl.Antecedent(np.arange(0,101,1),'Humidity')
Humidity['Poor']=fuzz.trapmf(Humidity.universe, [0,0,10,20])
Humidity['Fair']=fuzz.trimf(Humidity.universe, [15,30,50])
Humidity['Good'] = fuzz.trapmf(Humidity.universe, [45,60,100,100])

CO = ctrl.Antecedent(np.arange(0,101,1),'CO')
CO['Low'] = fuzz.trapmf(CO.universe, [0,0,25,35])
CO['Medium'] = fuzz.trimf(CO.universe, [30,50,70])
CO['High'] = fuzz.trapmf(CO.universe, [65,80,100,100])

CO2 = ctrl.Antecedent(np.arange(0,101,1),'CO2')
CO2['Low'] = fuzz.trapmf(CO2.universe, [0,0,10,20])
CO2['Medium'] = fuzz.trimf(CO2.universe, [15,30,50])
CO2['High'] = fuzz.trapmf(CO2.universe, [45,60,100,100])

Condition = ctrl.Consequent(np.arange(0,101,1),'Health Condition')
Condition['Very Good']=fuzz.trapmf(Condition.universe, [0,0,10,30])
Condition['Good']=fuzz.trimf(Condition.universe, [20,30,40])
Condition['Medium']=fuzz.trimf(Condition.universe, [35,50,65])
Condition['Bad']=fuzz.trimf(Condition.universe, [60,70,80])
Condition['Dangerous']=fuzz.trapmf(Condition.universe, [75,90,100,100])

Temp.view()
Humidity.view()
CO.view()
CO2.view()
Condition.view()

rule1 = ctrl.Rule(Temp['Medium'] & Humidity['Fair'] & CO['Low'] & CO2['Low'], Condition['Good'])
rule2 = ctrl.Rule(Temp['Medium'] & Humidity['Good'] & CO['Medium'] & CO2['Low'], Condition['Very Good'])
rule3 = ctrl.Rule(Temp['Low'] & Humidity['Poor'] & CO['High'] & CO2['High'], Condition['Dangerous'])
rule4 = ctrl.Rule(Temp['High'] & Humidity['Poor'] & CO['Medium'] & CO2['Low'], Condition['Bad'])
rule5 = ctrl.Rule(Temp['Low'] & Humidity['Fair'] & CO['Medium'] & CO2['Medium'], Condition['Medium'])

rule1.view()
rule2.view()
rule3.view()
rule4.view()
rule5.view()

Health_ctrl = ctrl.ControlSystem([rule1, rule2, rule3, rule4, rule5])
HealthResult = ctrl.ControlSystemSimulation(Health_ctrl)

HealthResult.input['temperature'] =45
HealthResult.input['Humidity'] =40
HealthResult.input['CO'] =50
HealthResult.input['CO2'] =75

HealthResult.compute()

print(HealthResult.output['Health Condition'])
Condition.view(sim=HealthResult)



---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/skfuzzy/control/controlsystem.py in defuzz(self)
    586                 return defuzz(ups_universe, output_mf,
--> 587                               self.var.defuzzify_method)
    588             except AssertionError:

3 frames
/usr/local/lib/python3.6/dist-packages/skfuzzy/defuzzify/defuzz.py in defuzz(x, mfx, mode)
    247         zero_truth_degree = mfx.sum() == 0  # Approximation of total area
--> 248         assert not zero_truth_degree, 'Total area is zero in defuzzification!'
    249 

AssertionError: Total area is zero in defuzzification!

During handling of the above exception, another exception occurred:
ValueError                                Traceback (most recent call last)
<ipython-input-4-f358e5f1a15d> in <module>()
     56 HealthResult.input['CarbonDioxide'] =75
     57 
---> 58 HealthResult.compute()
     59 
     60 print(HealthResult.output['Health Condition'])

/usr/local/lib/python3.6/dist-packages/skfuzzy/control/controlsystem.py in compute(self)
    371         for consequent in self.ctrl.consequents:
    372             consequent.output[self] = \
--> 373                 CrispValueCalculator(consequent, self).defuzz()
    374             self.output[consequent.label] = consequent.output[self]
    375 

/usr/local/lib/python3.6/dist-packages/skfuzzy/control/controlsystem.py in defuzz(self)
    587                               self.var.defuzzify_method)
    588             except AssertionError:
--> 589                 raise ValueError("Crisp output cannot be calculated, likely "
    590                                  "because the system is too sparse. Check to "
    591                                  "make sure this set of input values will "

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.

解决方案


当它说“太稀疏”时,表示没有激活任何规则的区域,因此无法计算面积(hiper-area),因此无法计算重心(基本上除以零)。在您的情况下:

规则1:C0和C02的成员资格为0

规则2:湿度和C02的成员资格为0

规则3:温度,湿度和CO的成员资格为0

规则4:温度和二氧化碳的成员资格为0。

因此,不会产生任何区域

0

1

2

3

4

5

6

7

8

9



所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接: https://www.pythonheidong.com/blog/article/777231/851e34eae085123be78c/

来源: python黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

5 0
收藏该文
已收藏

评论内容:(最多支持255个字符)