粗糙集约简 程序 matlab,粗糙集属性约简matlab程序
时间: 2023-09-16 14:14:56 浏览: 66
以下是粗糙集属性约简的matlab程序:
```matlab
function [reduct, core] = roughSetReduction(data, decision)
% data: 数据集,每行为一个样本,每列为一个属性
% decision: 决策属性所在的列数
% reduct: 约简后的属性集合
% core: 核属性集合
% 计算正域
P = [];
for i = 1:size(data, 1)
if data(i, decision) == 1
P = [P; data(i, :)];
end
end
% 计算关系矩阵
R = zeros(size(P, 1));
for i = 1:size(P, 1)
for j = 1:size(P, 1)
isR = true;
for k = 1:size(data, 2)
if k ~= decision && data(i, k) ~= data(j, k)
isR = false;
break;
end
end
if isR
R(i, j) = 1;
end
end
end
% 计算核属性
core = [];
for i = 1:size(P, 2)
isCore = true;
for j = 1:size(P, 1)
if P(j, i) == 0
continue;
end
isAllZero = true;
for k = 1:size(P, 1)
if R(j, k) == 1 && P(k, i) == 0
isAllZero = false;
break;
end
end
if isAllZero
isCore = false;
break;
end
end
if isCore
core = [core i];
end
end
% 计算约简属性
reduct = core;
for i = 1:size(P, 2)
if ismember(i, core)
continue;
end
isReduct = true;
for j = 1:length(reduct)
isAllZero = true;
for k = 1:size(P, 1)
if R(k, k) == 1 && P(k, reduct(j)) == 1 && P(k, i) == 0
isAllZero = false;
break;
end
end
if isAllZero
isReduct = false;
break;
end
end
if isReduct
reduct = [reduct i];
end
end
```
该程序实现了粗糙集属性约简的算法,输入为数据集和决策属性所在的列数,输出为约简后的属性集合和核属性集合。其中,正域用P表示,关系矩阵用R表示,核属性集合用core表示,约简属性集合用reduct表示。
阅读全文