本文概述
- Python3
- Python3
- Python3
- Python3
模糊是指不清楚或模糊的事物。因此, 模糊集是一个集合, 其中每个键都与值相关联, 该值基于确定性介于0到1之间。此值通常称为隶属度。模糊集在常规集符号的顶部用波浪号表示。
用代码对模糊集进行运算:
1.并集或合集:
考虑由A和B表示的2个模糊集, 然后让Y成为它们的并集, 那么对于A和B的每个成员, Y将是:
degree_of_membership(Y)= max(degree_of_membership(A), degree_of_membership(B))
范例:
Python3
# Example to Demonstrate the
# Union of Two Fuzzy Sets
A = dict ()
B = dict ()
Y = dict ()A = { "a" : 0.2 , "b" : 0.3 , "c" : 0.6 , "d" : 0.6 }
B = { "a" : 0.9 , "b" : 0.9 , "c" : 0.4 , "d" : 0.5 }print ( 'The First Fuzzy Set is :' , A)
print ( 'The Second Fuzzy Set is :' , B)for A_key, B_key in zip (A, B):
A_value = https://www.lsbin.com/A[A_key]
B_value = B[B_key]if A_value >
B_value:
Y[A_key] = A_value
else :
Y[B_key] = B_valueprint ('Fuzzy Set Union is :' , Y)
输出如下
The First Fuzzy Set is : {'a': 0.2, 'b': 0.3, 'c': 0.6, 'd': 0.6}
The Second Fuzzy Set is : {'a': 0.9, 'b': 0.9, 'c': 0.4, 'd': 0.5}
Fuzzy Set Union is : {'a': 0.9, 'b': 0.9, 'c': 0.6, 'd': 0.6}
2.交集:
考虑2个用A和B表示的模糊集, 然后让Y视为它们的交集, 那么对于A和B的每个成员, Y将是:
degree_of_membership(Y)= min(degree_of_membership(A), degree_of_membership(B))
范例:
Python3
# Example to Demonstrate
# Intersection of Two Fuzzy Sets
A = dict ()
B = dict ()
Y = dict ()A = { "a" : 0.2 , "b" : 0.3 , "c" : 0.6 , "d" : 0.6 }
B = { "a" : 0.9 , "b" : 0.9 , "c" : 0.4 , "d" : 0.5 }print ( 'The First Fuzzy Set is :' , A)
print ( 'The Second Fuzzy Set is :' , B)for A_key, B_key in zip (A, B):
A_value = https://www.lsbin.com/A[A_key]
B_value = B[B_key]if A_value <
B_value:
Y[A_key] = A_value
else :
Y[B_key] = B_value
print ('Fuzzy Set Intersection is :' , Y)
输出如下
The First Fuzzy Set is : {'a': 0.2, 'b': 0.3, 'c': 0.6, 'd': 0.6}
The Second Fuzzy Set is : {'a': 0.9, 'b': 0.9, 'c': 0.4, 'd': 0.5}
Fuzzy Set Intersection is : {'a': 0.2, 'b': 0.3, 'c': 0.4, 'd': 0.5}
3.补集:
考虑用A表示的模糊集, 然后将Y视为它的补集, 那么对于A的每个成员, Y将是:
degree_of_membership(Y)= 1 - degree_of_membership(A)
范例:
Python3
# Example to Demonstrate the
# Difference Between Two Fuzzy Sets
A = dict ()
Y = dict ()A = { "a" : 0.2 , "b" : 0.3 , "c" : 0.6 , "d" : 0.6 }print ( 'The Fuzzy Set is :' , A)for A_key in A:
Y[A_key] = 1 - A[A_key]print ( 'Fuzzy Set Complement is :' , Y)
输出如下
The Fuzzy Set is : {'a': 0.2, 'b': 0.3, 'c': 0.6, 'd': 0.6}
Fuzzy Set Complement is : {'a': 0.8, 'b': 0.7, 'c': 0.4, 'd': 0.4}
4.差集:
考虑2个用A和B表示的模糊集, 然后让Y视为它们的交集, 那么对于A和B的每个成员, Y将是:
degree_of_membership(Y)= min(degree_of_membership(A), 1- degree_of_membership(B))
范例:
Python3
# Example to Demonstrate the
# Difference Between Two Fuzzy Sets
A = dict ()
B = dict ()
Y = dict ()A = { "a" : 0.2 , "b" : 0.3 , "c" : 0.6 , "d" : 0.6 }
B = { "a" : 0.9 , "b" : 0.9 , "c" : 0.4 , "d" : 0.5 }print ( 'The First Fuzzy Set is :' , A)
print ( 'The Second Fuzzy Set is :' , B)for A_key, B_key in zip (A, B):
A_value = https://www.lsbin.com/A[A_key]
B_value = B[B_key]
B_value = 1 - B_valueif A_value <
B_value:
Y[A_key] = A_value
else :
Y[B_key] = B_valueprint ('Fuzzy Set Difference is :' , Y)
输出如下
The First Fuzzy Set is : {"a": 0.2, "b": 0.3, "c": 0.6, "d": 0.6}
The Second Fuzzy Set is : {"a": 0.9, "b": 0.9, "c": 0.4, "d": 0.5}
Fuzzy Set Difference is : {"a": 0.1, "b": 0.1, "c": 0.6, "d": 0.5}
【模糊集的常见操作及示例和代码】首先, 你的面试准备可通过以下方式增强你的数据结构概念:Python DS课程。
推荐阅读
- Arcesium面试经验(全日制FTE校园)
- jQuery如何使用GMaps插件(代码示例指南)
- Python中进程的同步和池化(代码实现和图解)
- CSS星号*选择器介绍和用法示例
- 局域网windows7系统32位网络共享图文详细教程图解
- Ghost windows7系统32位桌面壁纸大全制作详细说明
- 本文教你windows7系统32位激活办法
- windows7升级windows10系统图文详细教程制作详细说明
- 本文教你Ghost win7系统32位怎样设置开机密码