Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import skfuzzy as fuzz
- from skfuzzy import control as ctrl
- import matplotlib.pyplot as plt
- timeOfDay = ctrl.Antecedent(np.arange(0, 24, 1), 'time')
- sunIntensity = ctrl.Antecedent(np.arange(0, 11, 1), 'intensity')
- roomSize = ctrl.Antecedent(np.arange(0, 51, 1), 'size')
- bulbIntensity = ctrl.Consequent(np.arange(0, 11, 1), 'bulb')
- # timeOfDay.automf(3)
- # sunIntensity.automf(3)
- # roomSize.automf(3)
- timeOfDay['night'] = fuzz.trimf(timeOfDay.universe, [0, 0, 6])
- timeOfDay['morning'] = fuzz.trimf(timeOfDay.universe, [0, 6, 12])
- timeOfDay['midday'] = fuzz.trimf(timeOfDay.universe, [6, 12, 17])
- timeOfDay['evening'] = fuzz.trimf(timeOfDay.universe, [12, 17, 23])
- sunIntensity.automf(3)
- roomSize['small'] = fuzz.trimf(roomSize.universe, [0, 0, 6])
- roomSize['average'] = fuzz.trimf(roomSize.universe, [0, 6, 25])
- roomSize['big'] = fuzz.trimf(roomSize.universe, [6, 25, 51])
- bulbIntensity.automf(3)
- # bulbIntensity['low'] = fuzz.trimf(bulbIntensity.universe, [0, 0, 3])
- # bulbIntensity['medium'] = fuzz.trimf(bulbIntensity.universe, [0, 3, 7])
- # bulbIntensity['high'] = fuzz.trimf(bulbIntensity.universe, [3, 7, 10])
- # Available options: 'poor'; 'average', or 'good' for sunIntensity and bulbIntensity
- rule1 = ctrl.Rule(timeOfDay['morning'] | sunIntensity['poor'] | roomSize['small'], bulbIntensity['poor'])
- rule2 = ctrl.Rule(timeOfDay['midday'] | sunIntensity['good'] | roomSize['small'], bulbIntensity['average'])
- rule3 = ctrl.Rule(timeOfDay['evening'] | sunIntensity['poor'] | roomSize['small'], bulbIntensity['average'])
- rule4 = ctrl.Rule(timeOfDay['morning'] | sunIntensity['average'] | roomSize['average'], bulbIntensity['poor'])
- rule5 = ctrl.Rule(timeOfDay['midday'] | sunIntensity['good'] | roomSize['small'], bulbIntensity['poor'])
- light_control = ctrl.ControlSystem([rule1, rule2, rule3, rule4, rule5])
- control = ctrl.ControlSystemSimulation(light_control)
- control.input['time'] = 12
- control.input['intensity'] = 7
- control.input['size'] = 45
- control.compute()
- print(control.output['bulb'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement