-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment6.py
More file actions
26 lines (20 loc) · 743 Bytes
/
Assignment6.py
File metadata and controls
26 lines (20 loc) · 743 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import numpy as np
import skfuzzy as fuzz
from skfuzzy import control as ctrl
# Input & Output variables
temp = ctrl.Antecedent(np.arange(0, 11, 1), 'temp')
speed = ctrl.Consequent(np.arange(0, 26, 1), 'speed')
# Membership functions
temp['low'] = fuzz.trimf(temp.universe, [0, 0, 5])
temp['high'] = fuzz.trimf(temp.universe, [5, 10, 10])
speed['slow'] = fuzz.trimf(speed.universe, [0, 0, 13])
speed['fast'] = fuzz.trimf(speed.universe, [13, 25, 25])
# Rule base
rule1 = ctrl.Rule(temp['low'], speed['slow'])
rule2 = ctrl.Rule(temp['high'], speed['fast'])
# Control system
sys = ctrl.ControlSystem([rule1, rule2])
sim = ctrl.ControlSystemSimulation(sys)
sim.input['temp'] = 7
sim.compute()
print("Predicted speed:", sim.output['speed'])