粗糙集属性约简matlab程序

更新时间:2023-03-11 18:31:01 阅读量: 教育文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

粗糙集-属性约简-matlab程序

Data2为条件属性, decision2为决策属性 %%%my_test函数实现 clc;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%读取信息系统文件

file = textread('data2.txt','%s','delimiter','\\n','whitespace',''); %读取文件信息,每一行为一个胞元 [m,n]=size(file); %胞元的大小 for i=1:m

words=strread(file{i},'%s','delimiter',' ');%读取每个胞元中字符,即分解胞元为新的胞元 words=words';%转置 X{i}=words; end X=X';

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% [B,num,AT]=my_reduct(X); %信息系统的约简 ind_AT=ind(X); %信息系统的不可等价关系

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%显示约简信息系统 disp('约简后的条件系统为:'); [m,n]=size(B); for i=1:m disp(B{i}); end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%读取决策系统文件 file = textread('decision2.txt','%s','delimiter','\\n','whitespace',''); [m,n]=size(file); for i=1:m

words=strread(file{i},'%s','delimiter',' '); words=words'; D{i}=words; end D=D';

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%决策系统的正域约简 X_D=X;

[l,k]=size(X_D{1}); pos_d=pos(X_D,D);%正域 for

i=1:m

%%%%%%%%%%%%%%

题%%%%%%%%%%%%%%%%%%%%%%%%%%% if(~ismember(num(i),pos_d))

B{i}=''; %若约简后的信息系统B{i}不在正域中则删除该行 end %因为相同的条件得到的决策不一样, end

%将在正域规则下约简过的信息系统B连接决策系统D [m,n]=size(B); for i=1:m

if(~isequal(B{i},'')) B{i}{1,k+1}=D{i}{1}; end end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%显示约简决策系统

disp('约简后的决策系统为:'); [m,n]=size(B); for i=1:m disp(B{i}); end

-------------------------------------------------------------------------------- %%%%%my_reduct函数实现

function [C,num,reduct_attr]=my_reduct(X)

%%%%%y为约简后的cell数组,reduct_attr为可约去的属性 %X为行向量(元素为胞元) clc;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%约简 [m,n]=size(X); [p,k]=size(X{1});

ind_AT=ind(X);%寻找不可等价关系 reduct_attr=[]; %可约去的的属性

num=zeros(m,1);%约简后的信息对应的个体 for i=1:k

B=delete_AT(X,i);

if(isequal(ind_AT,ind(B))) %若IND(AT-{a}=IND(AT) reduct_attr=union(reduct_attr,i); %则寻找到可约去的属性 X=B; end end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%剔除重复的行

k=1; for i=1:m

if(~isequal(ind_AT{i},[])) C_i=ind_AT{i,1}(1); num(k)=i;

C{k,1}=X{C_i}; %返回约简后的信息系统 k=k+1; end end

-------------------------------------------------------------------------------- %%%%%ind函数实现

function yy=ind(X) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%寻找不可分辨关系 [m,n]=size(X); k=1;

ind_AT=cell(m,1); for i=1:m

for j=(i+1):m %潜在问题,如i=m是终止循环,此时若最后一行不为空的话,将漏扫 if(~isequal(X{i},'')) %若X{i}不为空

ind_AT{k}=union(ind_AT{k},i); %不可等价关系赋初值 if(isequal(X{i},X{j}))

X{j}=''; %若X{i}==X{j},则删除X{j} ind_AT{k}=union(ind_AT{k},j); %寻找不可等价关系 end end end k=k+1; end

-------------------------------------------------------------------------------- %%Tlete_AT函数的源代码

function y=delete_AT(X,ATi) % 删除X中第i列的属性值 [m,n]=size(X); [l,k]=size(X{1}); for i=1:m X{i}{ATi}=''; end y=X;

-------------------------------------------------------------------------------- %%%%%pos函数实现

function pos_d=pos(X,D)%求决策系统的正域函数 %X为条件属性,D为决策属性

ind_D=ind(D); %求决策属性D的不可等价关系

[m,n]=size(ind_D);

ind_X=ind(X); %求信息系统属性X的不可等价关系 low=[]; %存储正域个体的编号 for i=1:m for j=1:m

if(~isequal(ind_X{i},[])&&~isequal(ind_D{j},[])) if(ismember(ind_X{i},ind_D{j}))

low=union(low,ind_X{i});%由性质Pos_AT(d)=low_AT(X1)Ulow_AT(X2)U... end end end end pos_d=low;

本文来源:https://www.bwwdw.com/article/hnbw.html

Top