理解模糊逻辑推理的原理及特点,熟练应用模糊推理。
采用Matlad 7.0 的Fuzzy Logic Tool 设计洗衣机洗涤时间的模糊控制。
已知人的操作经验为:
“污泥越多,油脂越多,洗涤时间越长”;
“污泥适中,油脂适中,洗涤时间适中”;
“污泥越少,油脂越少,洗涤时间越短”。
模糊控制规则:
1、if(x is SD)and(y is NG)then(z is VS)(1)
2、if(x is SD)and(y is MG)then(z is M)(1)
3、if(x is SD)and(y is LG)then(z is L)(1)
4、if(x is MD)and(y is NG)then(z is S)(1)
5、if(x is MD)and(y is MG)then(z is M)(1)
6、if(x is MD)and(y is LG)then(z is L)(1)
7、if(x is LD)and(y is MG)then(z is M)(1)
8、if(x is LD)and(y is MG)then(z is L)(1)
9、if(x is LD)and(y is LG)then(z is VL)(1)
其中SD(污泥少)、MD(污泥中)、LD(污泥多)、NG(油脂少)、MG(油脂中)、LG(油脂多)、VS(洗涤时间很短)、S(洗涤时间短)、M(洗涤时间中等)、L(洗涤时间长)、VL(洗涤时间很长)。
(1) 假设污泥、油脂、洗涤时间的论域分别为 [0,100]、[0,100] 和 [0,120],设计相应的模糊推理系统,给出输入、输出语言变量的隶属函数图,模糊控制规则表和推理结果立体图。
4.模糊控制规则表
注:SD(污泥少)、MD(污泥中)、LD(污泥多)、NG(油脂少)、MG(油脂中)、LG(油脂多)、VS(洗涤时间很短)、S(洗涤时间短)、M(洗涤时间中等)、L(洗涤时间长)、VL(洗涤时间很长)。
(2)假定当前传感器测得的信息为x (污泥) = 60,y(油脂) = 70,采用模糊决策,给出模糊推理结果,并观察模糊推理得到动态仿真环境,给出其动态仿真环境图。
这里使用python来实现
(2)规则触发。被触发的规则有4条:
Rule1:IF x is MD AND y is MG THEN z is M;
Rule2:IF x is MD AND y is LG THEN z is L;
Rule3:IF x is LD AND y is MG THEN z is L;
Rule4:IF x is LD AND y is LG THEN z is VL。
(3)规则前提推理。在同一条规则内,前提之间通过交运算得到规则结论。
(5)去模糊化。采用加权平均判决发的方法。根据洗涤时间隶属函数的反函数用相应的隶属度求出时间论域中对应的值。
1. # 1. 污泥隶属度计算
2. def Sludge(a):
3. sludge = [0, 0, 0] # 默认隶属度为0,依次对应SD,MD,LD
4. if a < 0 or a > 100:
5. return (print("输入值有误"))
6. elif 0 <= a <= 50:
7. sludge[0] = (50 - a) / 50
8. sludge[1] = a / 50
9. elif 50 < a <= 100:
10. sludge[1] = (100 - a) / 50 # 40/50
11. sludge[2] = (a - 50) / 50 # 10/50
12. return sludge
13.
14. # 2. 油脂隶属度计算
15. def Grease(a):
16. grease = [0, 0, 0] # 默认隶属度为0,依次对应NG,MG,LG
17. if a < 0 or a > 100:
18. return (print("输入值有误"))
19. elif 0 <= a <= 50:
20. grease[0] = (50 - a) / 50
21. grease[1] = a / 50
22. elif 50 < a <= 100:
23. grease[1] = (100 - a) / 50 # 30/50
24. grease[2] = (a - 50) / 50 # 10/50
25. return grease
26.
27. # 3. 规则前提推理,并运算取最小值
28. def Rules(a, b): # a为污泥隶属度,b为油脂隶属度
29. rules_value = [0, 0, 0, 0, 0, 0, 0, 0, 0] # 依次对应9条规则结果VS,M,L,S,M,L,M,L,VL
30. if a[0] != 0 and b[0] != 0:
31. rules_value[0] = min(a[0], b[0]) # 返回规则下最小值
32. if a[0] != 0 and b[1] != 0:
33. rules_value[1] = min(a[0], b[1])
34. if a[0] != 0 and b[2] != 0:
35. rules_value[2] = min(a[0], b[2])
36. if a[1] != 0 and b[0] != 0:
37. rules_value[3] = min(a[1], b[0])
38. if a[1] != 0 and b[1] != 0:
39. rules_value[4] = min(a[1], b[1])
40. if a[1] != 0 and b[2] != 0:
41. rules_value[5] = min(a[1], b[2])
42. if a[2] != 0 and b[0] != 0:
43. rules_value[6] = min(a[2], b[0])
44. if a[2] != 0 and b[1] != 0:
45. rules_value[7] = min(a[2], b[1])
46. if a[2] != 0 and b[2] != 0:
47. rules_value[8] = min(a[2], b[2])
48. return rules_value
详细代码下载:https://download.csdn.net/download/hgxiaojiujiu/40088631
略…
注:这篇文章的部分内容是参考这篇文章的matlab方法和步骤
https://blog.csdn.net/qq_44057443/article/details/92668331?spm=1001.2101.3001.6650.9&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-9.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-9.no_search_link