资源描述:
《粗糙集属性约简matlab程序.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、粗糙集-属性约简-matlab程序Data2为条件属性,decision2为决策属性%%%my_test函数实现clc;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%读取信息系统文件file=textread('data2.txt','%s','delimiter','','whitespace','');%读取文件信息,每一行为一个胞元[m,n]=size(file);%胞元的大小fori=1:mwords=strread(file{i},'%s','delimiter','');%读取每个胞元中字符,即分解胞元为新的胞元words=words
2、';%转置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=tex
3、tread('decision2.txt','%s','delimiter','','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%%%%%%%%%%%%%%正域有
4、问题%%%%%%%%%%%%%%%%%%%%%%%%%%%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]=siz
5、e(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}
6、);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
7、}(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是终止