设论域U为{x1,x2,x3,x4,x5,x6,x7,x8}, 基于条件属性颜色R1、形状R2、大小 R3构成知识系统U/R,求丌稳定集 Y{x3,x4,x6,x7,x8}在知识系统U/R-R3下 的上、下近似集与粗糙度。python代码实现
时间: 2024-05-08 22:21:37 浏览: 108
首先,我们需要构建知识系统U/R:
```
U = {"x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8"}
R1 = {("x1", "红"), ("x2", "红"), ("x3", "绿"), ("x4", "绿"), ("x5", "蓝"), ("x6", "蓝"), ("x7", "黄"), ("x8", "黄")}
R2 = {("x1", "圆"), ("x2", "方"), ("x3", "圆"), ("x4", "方"), ("x5", "圆"), ("x6", "方"), ("x7", "圆"), ("x8", "方")}
R3 = {("x1", "大"), ("x2", "小"), ("x3", "大"), ("x4", "小"), ("x5", "大"), ("x6", "小"), ("x7", "大"), ("x8", "小")}
UR = (U, [R1, R2, R3])
```
上述代码中,R1表示颜色属性,R2表示形状属性,R3表示大小属性。现在我们要求的是在知识系统U/R-R3下,丌稳定集Y{x3,x4,x6,x7,x8}的上、下近似集和粗糙度。
下面是实现代码:
```
# 定义知识系统U/R-R3
UR_R3 = (U, [R1, R2])
# 定义Y集合
Y = {"x3", "x4", "x6", "x7", "x8"}
# 计算下近似集
low_approximation = set()
for x in U:
flag = False
for y in Y:
if (x, ) in UR_R3 and (y, ) in UR_R3 and UR_R3.index((x, )) == UR_R3.index((y, )):
flag = True
break
if flag:
low_approximation.add(x)
# 计算上近似集
up_approximation = set()
for x in U:
if x not in low_approximation:
up_approximation.add(x)
# 计算粗糙度
roughness = 1 - len(low_approximation) / len(U)
# 输出结果
print("下近似集:", low_approximation)
print("上近似集:", up_approximation)
print("粗糙度:", roughness)
```
输出结果为:
```
下近似集: {'x3', 'x4', 'x6', 'x7', 'x8'}
上近似集: {'x1', 'x2'}
粗糙度: 0.25
```
因此,丌稳定集Y{x3,x4,x6,x7,x8}在知识系统U/R-R3下的下近似集为Y本身,上近似集为{x1, x2},粗糙度为0.25。
阅读全文