Advertisement
Guest User

Untitled

a guest
Nov 2nd, 2022
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.03 KB | None | 0 0
  1. import numpy as np
  2. import skfuzzy as fuzz
  3. from skfuzzy import control as ctrl
  4. import matplotlib.pyplot as plt
  5.  
  6. timeOfDay = ctrl.Antecedent(np.arange(0, 24, 1), 'time')
  7. sunIntensity = ctrl.Antecedent(np.arange(0, 11, 1), 'intensity')
  8. roomSize = ctrl.Antecedent(np.arange(0, 51, 1), 'size')
  9. bulbIntensity = ctrl.Consequent(np.arange(0, 11, 1), 'bulb')
  10.  
  11. # timeOfDay.automf(3)
  12. # sunIntensity.automf(3)
  13. # roomSize.automf(3)
  14.  
  15. timeOfDay['night'] = fuzz.trimf(timeOfDay.universe, [0, 0, 6])
  16. timeOfDay['morning'] = fuzz.trimf(timeOfDay.universe, [0, 6, 12])
  17. timeOfDay['midday'] = fuzz.trimf(timeOfDay.universe, [6, 12, 17])
  18. timeOfDay['evening'] = fuzz.trimf(timeOfDay.universe, [12, 17, 23])
  19.  
  20. sunIntensity.automf(3)
  21.  
  22. roomSize['small'] = fuzz.trimf(roomSize.universe, [0, 0, 6])
  23. roomSize['average'] = fuzz.trimf(roomSize.universe, [0, 6, 25])
  24. roomSize['big'] = fuzz.trimf(roomSize.universe, [6, 25, 51])
  25.  
  26. bulbIntensity.automf(3)
  27.  
  28. # bulbIntensity['low'] = fuzz.trimf(bulbIntensity.universe, [0, 0, 3])
  29. # bulbIntensity['medium'] = fuzz.trimf(bulbIntensity.universe, [0, 3, 7])
  30. # bulbIntensity['high'] = fuzz.trimf(bulbIntensity.universe, [3, 7, 10])
  31.  
  32. # Available options: 'poor'; 'average', or 'good' for sunIntensity and bulbIntensity
  33. rule1 = ctrl.Rule(timeOfDay['morning'] | sunIntensity['poor'] | roomSize['small'], bulbIntensity['poor'])
  34. rule2 = ctrl.Rule(timeOfDay['midday'] | sunIntensity['good'] | roomSize['small'], bulbIntensity['average'])
  35. rule3 = ctrl.Rule(timeOfDay['evening'] | sunIntensity['poor'] | roomSize['small'], bulbIntensity['average'])
  36. rule4 = ctrl.Rule(timeOfDay['morning'] | sunIntensity['average'] | roomSize['average'], bulbIntensity['poor'])
  37. rule5 = ctrl.Rule(timeOfDay['midday'] | sunIntensity['good'] | roomSize['small'], bulbIntensity['poor'])
  38.  
  39. light_control = ctrl.ControlSystem([rule1, rule2, rule3, rule4, rule5])
  40.  
  41. control = ctrl.ControlSystemSimulation(light_control)
  42.  
  43. control.input['time'] = 12
  44. control.input['intensity'] = 7
  45. control.input['size'] = 45
  46.  
  47. control.compute()
  48.  
  49. print(control.output['bulb'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement