Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

!

pip install -U scikit-fuzzy


!pip install git+git://github.com/scikit-fuzzy/scikit-fuzzy.git
import numpy as np
import skfuzzy as fuzz
from skfuzzy import control as ctrl

temp = ctrl.Antecedent(np.arange(0, 40, 1), 'temp')


pressure = ctrl.Antecedent(np.arange(0,100,1), 'pressure')
chance = ctrl.Consequent(np.arange(0,90,1), "chance")

temp.automf(3)
pressure.automf(3)

temp['cool'] = fuzz.trimf(temp.universe, [0, 0, 45])


temp['nominal'] = fuzz.trimf(temp.universe, [0, 45, 90])
temp['warm'] = fuzz.trimf(temp.universe, [45, 90, 90])

pressure['low'] = fuzz.trimf(pressure.universe, [0, 0, 45])


pressure['ok'] = fuzz.trimf(pressure.universe, [0, 45, 90])
pressure['strong'] = fuzz.trimf(pressure.universe, [45, 90, 90])

chance['negative'] = fuzz.trimf(chance.universe, [0, 0, 45])


chance['zero'] = fuzz.trimf(chance.universe, [0, 45, 90])
chance['positive'] = fuzz.trimf(chance.universe, [45, 90, 90])

temp['average'].view()
pressure['average'].view()
rule1 = ctrl.Rule(temp['cool'] | pressure['low'], chance['negative'])
rule2 = ctrl.Rule(temp['nominal'], pressure['ok'])
rule3 = ctrl.Rule(temp['warm'] | pressure['strong'], chance['positive'])
rule1.view()

chance_ctrl = ctrl.ControlSystem([rule1, rule2, rule3])

chances = ctrl.ControlSystemSimulation(chance_ctrl)

chances.input["temp"] = 30
chances.input["pressure"] = 40

chances.compute()

print(chances.output['chance'])
chance.view(sim=chances)

You might also like