Fuzzy logic controller - RuntimeError: Unable to resolve rule execution order

Fuzzy logic controller - RuntimeError: Unable to resolve rule execution order

我是这个概念的新手,我一直在尝试实现淋浴的模糊逻辑控制器。输入是旋钮从最左到最右的位置,输出是从极冷到极热的温度。我在规则中遇到了这个运行时错误。下面是我的愚蠢代码

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

pos = ctrl.Consequent(np.arange(0, 180, 1), 'pos')
temp = ctrl.Consequent(np.arange(0, 100, 1), 'temp')

pos['EL'] = fuzz.trimf(pos.universe, [0, 0, 45])
pos['L'] = fuzz.trimf(pos.universe, [0, 45, 90])
pos['C'] = fuzz.trimf(pos.universe, [45, 90, 135])
pos['R'] = fuzz.trimf(pos.universe, [90, 135, 180])
pos['ER'] = fuzz.trimf(pos.universe, [135, 180, 180])

temp['VC'] = fuzz.trimf(temp.universe, [0, 0, 10])
temp['C'] = fuzz.trimf(temp.universe, [0, 10, 40])
temp['W'] = fuzz.trimf(temp.universe, [10, 40, 80])
temp['H'] = fuzz.trimf(temp.universe, [40, 80, 100])
temp['VH'] = fuzz.trimf(temp.universe, [80, 100, 100])

rule1 = ctrl.Rule(pos['EL'], temp['VC'])
rule2 = ctrl.Rule(pos['L'], temp['C'])
rule3 = ctrl.Rule(pos['C'], temp['W'])
rule4 = ctrl.Rule(pos['R'], temp['H'])
rule5 = ctrl.Rule(pos['ER'], temp['VH'])

temp_ctrl = ctrl.ControlSystem([rule1, rule2, rule3, rule4, rule5])
temprature = ctrl.ControlSystemSimulation(temp_ctrl)

RuntimeError: Unable to resolve rule execution order. The most likely reason is two or more rules that depend on each other. Please check the rule graph for loops.

我想你可能想要这个

pos = ctrl.Consequent(np.arange(0, 180, 1), 'pos')

成为这个

pos = ctrl.Antecedent(np.arange(0, 180, 1), 'pos')

因此您的规则将类似于

if antecedent then consequent