您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 经营企划 > 基于粗糙集信息系统约简的算法matlab实现
data2.txt的内容decision2的内容delete_AT函数的源代码functiony=delete_AT(X,ATi)%删除X中第i列的属性值%%%测试%X{1}={'yes''yes''nomal'''}%X{2}={'yes''yes''high'''}%X{3}={'yes''yes''very_high'''}%X{4}={'no''yes''nomal'''}%X=X';%ATi=1;%%%%%%%%[m,n]=size(X);[l,k]=size(X{1});fori=1:mX{i}{ATi}='';endy=X;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;endif(~isequal(X{m},''))ind_AT{k-1}=m;%假如最后一行不为空endyy=ind_AT;%返回不可等价关系my_reduct函数实现function[C,reduct_attr]=my_reduct(X)%%%%%y为约简后的cell数组,reduct_attr为可约去的属性%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%测试数据集%X{1}={'2''1''3'};%X{2}={'3''2''1'};%X{3}={'2''1''3'};%X{4}={'2''2''3'};%X{5}={'1''1''4'};%X{6}={'1''1''2'};%X{7}={'3''2''1'};%X{8}={'1''1''4'};%X{9}={'2''1''3'};%X{10}={'3''2''1'};%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%X{1}={'yes''yes''nomal'''}%X{2}={'yes''yes''high'''}%X{3}={'yes''yes''very_high'''}%X{4}={'no''yes''nomal'''}%X=X';%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%约简[m,n]=size(X);[p,k]=size(X{1});ind_AT=ind(X);%寻找不可等价关系reduct_attr=[];%可约去的的属性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);C{k,1}=X{C_i};%返回约简后的信息系统k=k+1;endendpos函数实现functionpos_d=pos(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;my_test函数实现functiony=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,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(i,pos_d))B{i}='';%若约简后的信息系统B{i}不在正域中则删除该行endend%将在正域规则下约简过的信息系统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});endmatlab输出的结果
本文标题:基于粗糙集信息系统约简的算法matlab实现
链接地址:https://www.777doc.com/doc-4652032 .html