当前位置:   article > 正文

人工智能洗衣机模糊推理系统实验(课本实验)

洗衣机模糊推理系统实验

一、实验目的

理解模糊逻辑推理的原理及特点,熟练应用模糊推理

二、实验内容

用python设计洗衣机洗涤时间的模糊控制

三、实验要求

已知人的操作经验是

污泥越多,油脂越多,洗涤时间越长

污泥适中,油脂适中,洗涤时间适中

污泥越少,油脂越少,洗涤时间越短

洗衣机的模糊控制规则表
xyz
SDNGVS
SDMGM
SDLGL
MDNGS
MDMGM
MDLGL
LDNGM
LDMGL
LDLGVL

其中SD(污泥少)、MD(污泥中)、LD(污泥多)、NG油脂少、MG油脂中、LG油脂多、VS洗涤时间很短、S洗涤时间短、M洗涤时间中等、L洗涤时间长、VL洗涤时间很长

(1)假设污泥、油脂、洗涤时间的论域分别为[0,100] [0,100] [0,120],设计相应的模糊推理系统,给出输入、输出语言变量的隶属函数图,模糊控制规则表和推论结果立体图。

(2)假定当前传感器测得的信息为x0(污泥)=60,y0(油脂)=70,采用模糊决策,给出模糊推理结果,并观察模糊推理的动态仿真环境,给出其动态仿真环境图。

第一小题,代码如下

  1. #需要先安装pip install scikit-fuzzy
  2. #released in 2021.2
  3. """
  4. ==========================================
  5. Fuzzy Control Systems: The washtimeping Problem
  6. ==========================================
  7. The 'washtimeping problem' is commonly used to illustrate the power of fuzzy logic
  8. principles to generate complex behavior from a compact, intuitive set of
  9. expert rules.
  10. If you're new to the world of fuzzy control systems, you might want
  11. to check out the `Fuzzy Control Primer
  12. <../userguide/fuzzy_control_primer.html>`_
  13. before reading through this worked example.
  14. The washtimeping Problem
  15. -------------------
  16. Let's create a fuzzy control system which models how you might choose to washtime
  17. at a restaurant. When washtimeping, you consider the oil and stain,
  18. rated between 0 and 10. You use this to leave a washtime of between 0 and 25%.
  19. We would formulate this problem as:
  20. * Antecedents (Inputs)
  21. - `oil`
  22. * How was the oil on a scale of 0 to 100?
  23. * Fuzzy set (ie, fuzzy value range): poor (SD), acceptable(MD), amazing (LD)
  24. - `stain`
  25. * Universe: stain on a scale of 0 to 100?
  26. * Fuzzy set: bad, decent, great
  27. * Consequents (Outputs)
  28. - `washtime`
  29. * Universe: How much should we washtime, on a scale of 0 to 120
  30. * Fuzzy set: low, medium, high
  31. * Rules
  32. - refer to P302
  33. * Usage
  34. - If I tell this controller that I rated:
  35. * the oil as 10, and
  36. * the stain as 10,
  37. - it would recommend :
  38. * a 29 washtime.
  39. Creating the washtimeping Controller Using the skfuzzy control API
  40. -------------------------------------------------------------
  41. We can use the `skfuzzy` control system API to model this. First, let's
  42. define fuzzy variables
  43. """
  44. import numpy as np
  45. import skfuzzy as fuzz
  46. from skfuzzy import control as ctrl
  47. import matplotlib.pyplot as plt
  48. # New Antecedent/Consequent objects hold universe variables and membership
  49. # functions
  50. stain = ctrl.Antecedent(np.arange(0, 101, 1), 'stain')
  51. oil = ctrl.Antecedent(np.arange(0, 101, 1), 'oil')
  52. washtime = ctrl.Consequent(np.arange(0, 120, 1), 'washtime')
  53. # Auto-membership function population is possible with .automf(3, 5, or 7)
  54. stain.automf(3, variable_type='quant')
  55. oil.automf(3, variable_type='quant')
  56. # Custom membership functions can be built interactively with a familiar,
  57. # Pythonic API
  58. washtime['VS'] = fuzz.trimf(washtime.universe, [0, 0, 20])
  59. washtime['S'] = fuzz.trimf(washtime.universe, [0, 20, 50])
  60. washtime['M'] = fuzz.trimf(washtime.universe, [20, 50, 70])
  61. washtime['L'] = fuzz.trimf(washtime.universe, [50, 70, 100])
  62. washtime['VL'] = fuzz.trimf(washtime.universe, [70, 100, 120])
  63. """
  64. To help understand what the membership looks like, use the ``view`` methods.
  65. These return the matplotlib `Figure` and `Axis` objects. They are persistent
  66. as written in Jupyter notebooks; other environments may require a `plt.show()`
  67. command after each `.view()`.
  68. """
  69. # You can see how these look with .view()
  70. stain['average'].view()
  71. plt.show()
  72. oil.view()
  73. plt.show()
  74. washtime.view()
  75. plt.show()
  76. """
  77. .. image:: PLOT2RST.current_figure
  78. Fuzzy rules
  79. -----------
  80. Now, to make these triangles useful, we define the *fuzzy relationship*
  81. between input and output variables.
  82. """
  83. # low = SD or NG;average = MD or MG;high=LD or LG
  84. rule1 = ctrl.Rule(stain['low'] & oil['low'], washtime['VS'])
  85. rule2 = ctrl.Rule(stain['low'] & oil['average'], washtime['M'])
  86. rule3 = ctrl.Rule(stain['low'] & oil['high'], washtime['L'])
  87. rule4 = ctrl.Rule(stain['average'] & oil['low'], washtime['S'])
  88. rule5 = ctrl.Rule(stain['average'] & oil['average'], washtime['M'])
  89. rule6 = ctrl.Rule(stain['average'] & oil['high'], washtime['L'])
  90. rule7 = ctrl.Rule(stain['high'] & oil['low'], washtime['M'])
  91. rule8 = ctrl.Rule(stain['high'] & oil['average'], washtime['L'])
  92. rule9 = ctrl.Rule(stain['high'] & oil['high'], washtime['VL'])
  93. """
  94. .. image:: PLOT2RST.current_figure
  95. Control System Creation and Simulation
  96. ---------------------------------------
  97. Now that we have our rules defined, we can simply create a control system
  98. via:
  99. """
  100. washtimeping_ctrl = ctrl.ControlSystem([rule1, rule2, rule3, rule4, rule5, rule6, rule7, rule8, rule9])
  101. """
  102. In order to simulate this control system, we will create a
  103. ``ControlSystemSimulation``. Think of this object representing our controller
  104. applied to a specific set of circumstances. For washtimeping, this might be washtimeping
  105. Sharon at the local brew-pub. We would create another
  106. ``ControlSystemSimulation`` when we're trying to apply our ``washtimeping_ctrl``
  107. for Travis at the cafe because the inputs would be different.
  108. """
  109. washtimeping = ctrl.ControlSystemSimulation(washtimeping_ctrl)
  110. """
  111. We can now simulate our control system by simply specifying the inputs
  112. and calling the ``compute`` method.
  113. """
  114. # Pass inputs to the ControlSystem using Antecedent labels with Pythonic API
  115. # Note: if you like passing many inputs all at once, use .inputs(dict_of_data)
  116. washtimeping.input['stain'] = 2
  117. washtimeping.input['oil'] = 2
  118. # Crunch the numbers
  119. washtimeping.compute()
  120. """
  121. Once computed, we can view the result as well as visualize it.
  122. """
  123. print(washtimeping.output['washtime'])
  124. washtime.view(sim=washtimeping)
  125. plt.show()

第二小题代码在第一小题基础上进行稍微改变

 

改为       washtimeping.input['stain'] = 60      就可以了

              washtimeping.input['oil'] = 70

运行结果如下:

 

好了,就这些,大家如果觉得有帮助的话就太好了,我做实验的时候就没有 找到这些。

   

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/522432
推荐阅读
相关标签
  

闽ICP备14008679号