粗糙集-属性约简-matlab程序Data2为条件属性,decision2为决策属性%%%my_test函数实现clc;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%读取信息系统文件file=textread('data2.txt','%s','delimiter','\n','whitespace','');%读取文件信息,每一行为一个胞元[m,n]=size(file);%胞元的大小fori=1:mwords=strread(file{i},'%s','delimiter','');%读取每个胞元中字符,即分解胞元为新的胞元words=words';%转置X{i}=words;endX=X';%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%[B,num,AT]=my_reduct(X);%信息系统的约简ind_AT=ind(X);%信息系统的不可等价关系%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%显示约简信息系统disp('约简后的条件系统为:');[m,n]=size(B);fori=1:mdisp(B{i});end%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%读取决策系统文件file=textread('decision2.txt','%s','delimiter','\n','whitespace','');[m,n]=size(file);fori=1:mwords=strread(file{i},'%s','delimiter','');words=words';D{i}=words;endD=D';%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%决策系统的正域约简X_D=X;[l,k]=size(X_D{1});pos_d=pos(X_D,D);%正域fori=1:m%%%%%%%%%%%%%%正域有问题%%%%%%%%%%%%%%%%%%%%%%%%%%%if(~ismember(num(i),pos_d))B{i}='';%若约简后的信息系统B{i}不在正域中则删除该行end%因为相同的条件得到的决策不一样,end%将在正域规则下约简过的信息系统B连接决策系统D[m,n]=size(B);fori=1:mif(~isequal(B{i},''))B{i}{1,k+1}=D{i}{1};endend%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%显示约简决策系统disp('约简后的决策系统为:');[m,n]=size(B);fori=1:mdisp(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);%约简后的信息对应的个体fori=1:kB=delete_AT(X,i);if(isequal(ind_AT,ind(B)))%若IND(AT-{a}=IND(AT)reduct_attr=union(reduct_attr,i);%则寻找到可约去的属性X=B;endend%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%剔除重复的行k=1;fori=1:mif(~isequal(ind_AT{i},[]))C_i=ind_AT{i,1}(1);num(k)=i;C{k,1}=X{C_i};%返回约简后的信息系统k=k+1;endend--------------------------------------------------------------------------------%%%%%ind函数实现functionyy=ind(X)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%寻找不可分辨关系[m,n]=size(X);k=1;ind_AT=cell(m,1);fori=1:mforj=(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);%寻找不可等价关系endendendk=k+1;end--------------------------------------------------------------------------------%%%delete_AT函数的源代码functiony=delete_AT(X,ATi)%删除X中第i列的属性值[m,n]=size(X);[l,k]=size(X{1});fori=1:mX{i}{ATi}='';endy=X;--------------------------------------------------------------------------------%%%%%pos函数实现functionpos_d=pos(X,D)%求决策系统的正域函数%X为条件属性,D为决策属性ind_D=ind(D);%求决策属性D的不可等价关系[m,n]=size(ind_D);ind_X=ind(X);%求信息系统属性X的不可等价关系low=[];%存储正域个体的编号fori=1:mforj=1:mif(~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...endendendendpos_d=low;