-1

The following is the code to solve fuzzy logic, I tried to make from fuzzy control system (scikit fuzzy liberary) but I am facing error ValueError: Unexpected input: temprature

import numpy as np
import skfuzzy as fuzz
from skfuzzy import control as ctrl
temprature = ctrl.Antecedent(np.arange(0, 15, 1), 'temperature')
moisture = ctrl.Antecedent(np.arange(0, 11, 1), 'moisture')
humidity = ctrl.Antecedent(np.arange(0, 11, 1), 'humidity')
minutes = ctrl.Consequent(np.arange(0,26, 1), 'minutes')
temprature.automf(3)
moisture.automf(3)
humidity.automf(3)
minutes['low'] = fuzz.trimf(minutes.universe, [0, 0, 13])
minutes['medium'] = fuzz.trimf(minutes.universe, [0, 13, 25])
minutes['high'] = fuzz.trimf(minutes.universe, [13, 25, 25])
rule1 = ctrl.Rule(temprature['poor'] | moisture['poor'] | humidity['poor'], minutes['low'])
rule2 = ctrl.Rule(temprature['average'] | moisture['average'] | humidity['average'], minutes['medium'])
rule3 = ctrl.Rule(temprature['good'] | moisture['good'] | humidity['good'], minutes['high'])
tap_ctrl = ctrl.ControlSystem([rule1, rule2, rule3])
tap_control_system = ctrl.ControlSystemSimulation(tap_ctrl)
tap_control_system.input['temprature'] = 1
tap_control_system.input['moisture'] = 1
tap_control_system.input['humidity'] = 1
tap_control_system.compute()
print(tap_control_system.output['minutes'])

Error:

Traceback (most recent call last):
  File "engine.py", line 30, in <module>
    tap_control_system.input['temprature'] = 1
  File "C:\Users\Toshiba\anaconda3\envs\Fuzzy-System-Project\lib\site-packages\skfuzzy\control\controlsystem.py", line 168, in __setitem__
    raise ValueError("Unexpected input: " + key)
ValueError: Unexpected input: temprature
halfer
  • 19,824
  • 17
  • 99
  • 186
Mrr Ahmer
  • 13
  • 3
  • Just a code styling nitpick, please import only necessary stuff (`from numpy import arange;from skfuzzy.control import Antecedent;etc`) and wrap the logic in simple functions (that you can re-use later). That way the code will have less characters and will be more readable to you when some time passes (+ it's easier to write tests for). – Peter Badida Jan 17 '21 at 14:44
  • how i can remove error ValueError: Unexpected input: temprature, can you help please? – Mrr Ahmer Jan 17 '21 at 15:09

1 Answers1

0

It's a typo. You have a typo here:

tap_control_system.input['temprature'] = 1

it should be:

tap_control_system.input['temperature'] = 1

Notebook tried on Jupyter website:

# In [1]:
!pip install scikit-fuzzy

Collecting scikit-fuzzy
  Downloading scikit-fuzzy-0.4.2.tar.gz (993 kB)
     |████████████████████████████████| 993 kB 4.2 MB/s eta 0:00:01
Requirement already satisfied: numpy>=1.6.0 in /srv/conda/envs/notebook/lib/python3.6/site-packages (from scikit-fuzzy) (1.19.5)
Requirement already satisfied: scipy>=0.9.0 in /srv/conda/envs/notebook/lib/python3.6/site-packages (from scikit-fuzzy) (1.5.3)
Requirement already satisfied: networkx>=1.9.0 in /srv/conda/envs/notebook/lib/python3.6/site-packages (from scikit-fuzzy) (2.5)
Requirement already satisfied: decorator>=4.3.0 in /srv/conda/envs/notebook/lib/python3.6/site-packages (from networkx>=1.9.0->scikit-fuzzy) (4.4.2)
Building wheels for collected packages: scikit-fuzzy
  Building wheel for scikit-fuzzy (setup.py) ... done
  Created wheel for scikit-fuzzy: filename=scikit_fuzzy-0.4.2-py3-none-any.whl size=894068 sha256=ac90a92c7d392cfe40f066083f856561db6152a2a6bab3bfa86bf7293fb0568a
  Stored in directory: /home/jovyan/.cache/pip/wheels/31/1e/58/db8cfe08f81c72d8c31bc58690ce63d9e3d93a6e97dca5ddb4
Successfully built scikit-fuzzy
Installing collected packages: scikit-fuzzy
Successfully installed scikit-fuzzy-0.4.2

# In [2]: 
import numpy as np
import skfuzzy as fuzz
from skfuzzy import control as ctrl
temprature = ctrl.Antecedent(np.arange(0, 15, 1), 'temperature')
moisture = ctrl.Antecedent(np.arange(0, 11, 1), 'moisture')
humidity = ctrl.Antecedent(np.arange(0, 11, 1), 'humidity')
minutes = ctrl.Consequent(np.arange(0,26, 1), 'minutes')
temprature.automf(3)
moisture.automf(3)
humidity.automf(3)
minutes['low'] = fuzz.trimf(minutes.universe, [0, 0, 13])
minutes['medium'] = fuzz.trimf(minutes.universe, [0, 13, 25])
minutes['high'] = fuzz.trimf(minutes.universe, [13, 25, 25])
rule1 = ctrl.Rule(temprature['poor'] | moisture['poor'] | humidity['poor'], minutes['low'])
rule2 = ctrl.Rule(temprature['average'] | moisture['average'] | humidity['average'], minutes['medium'])
rule3 = ctrl.Rule(temprature['good'] | moisture['good'] | humidity['good'], minutes['high'])
tap_ctrl = ctrl.ControlSystem([rule1, rule2, rule3])
tap_control_system = ctrl.ControlSystemSimulation(tap_ctrl)
tap_control_system.input['temperature'] = 1
tap_control_system.input['moisture'] = 1
tap_control_system.input['humidity'] = 1
tap_control_system.compute()
print(tap_control_system.output['minutes'])

8.085852534617038
Peter Badida
  • 11,310
  • 10
  • 44
  • 90