您好,欢迎访问三七文档
当前位置:首页 > 建筑/环境 > 工程监理 > 属性约简(MATLAB算法)有实例有讲解
..粗糙集属性约简题目:SARS诊断注:这是我学粗糙集时老师给的作业U干咳呼吸困难血液检测高烧38度X射线浓痰血细胞多寒战肌肉酸痛乏力胸膜痛头痛非典111110000110112000000000000031010000001000400011110101105100111110110060101111110010710001110011108111100001101191011100011011101111000011011111011100011011121011100011011属性约简的顺序如下:求正域、生成未经处理的区分矩阵、对区分矩阵进行化简、求核、对已经处理过的区分矩阵进行属性约简。约简后的决策表有26行,所有12个属性都是正域中的属性,核为空程序:%main.mtic;a=[1,1,1,1,0,0,0,0,1,1,0,1;0,0,0,0,0,0,0,0,0,0,0,0;1,0,1,0,0,0,0,0,0,1,0,0;0,0,0,1,1,1,1,0,1,0,1,1;1,0,0,1,1,1,1,1,0,1,1,0;0,1,0,1,1,1,1,1,1,0,0,1;1,0,0,0,1,1,1,0,0,1,1,1;1,1,1,1,0,0,0,0,1,1,0,1;1,0,1,1,1,0,0,0,1,1,0,1;1,1,1,1,0,0,0,0,1,1,0,1;1,0,1,1,1,0,0,0,1,1,0,1;1,0,1,1,1,0,0,0,1,1,0,1];d=[1;0;0;0;0;0;0;1;1;1;1;1];pos=posCD(a,d);dismat=dismatrix(a,d,pos);dism=disbe(dismat);..core=cor(dism);[red,row]=redu(dism);time=toc%dismatrix.m%生成未经处理的区分矩阵dismatfunctiondismat=dismatrix(a,d,pos)[m,n]=size(a);p=1;index1=0;index2=0;index=0;dis=-1*ones(m*(m-1)/2,n);fori=1:mforj=i+1:mif(isxbelongtopos(i,pos)&~isxbelongtopos(j,pos))...|(~isxbelongtopos(i,pos)&isxbelongtopos(j,pos))...|(isxbelongtopos(i,pos)&isxbelongtopos(j,pos)&~isxybelongtoindD(i,j,d))index2=1;endifindex2==0continue;endfork=1:nifa(i,k)~=a(j,k)dis(p,k)=1;index1=1;elsedis(p,k)=0;endendifindex1==1p=p+1;index=1;endindex1=0;index2=0;endendifp=m*(m-1)/2ifindex==0dismat=[];return;endifdis(p,1)==-1p=p-1;endelsep=m*(m-1)/2;end..dismat=dis(1:p,:);%redu.m%对已经处理过的区分矩阵进行知识约简function[red,row]=redu(dism)[m,n]=size(dism);red=[];row=0;ifm=0return;endfori=1:nifdism(1,i)~=0row=row+1;endendred(1:row,:)=zeros(row,n);j=1;fori=1:rowwhiledism(1,j)==0j=j+1;endred(i,j)=1;j=j+1;endtemp=[];tempdis=[];rowd=0;rowd1=0;fori=2:mj=1;whilej=rowtemp=uni(dism(i,:),red(j,:));[s,n]=size(temp);rowd1=rowd+s;tempdis(rowd+1:rowd1,:)=temp;rowd=rowd1;j=j+1;temp=[];endred=[];red=disbe(tempdis);tempdis=[];[row,n]=size(red);rowd=0;rowd1=0;end..%disbe.m%对区分矩阵或者约简矩阵进行化简即去掉包含关系functiondism=disbe(dis)[m,n]=size(dis);p=m;fori=1:mifdis(i,1)~=-1forj=1:mifi~=j&dis(j,1)~=-1ifdis(i,:)=dis(j,:)dis(j,1)=-1;p=p-1;elseifdis(i,:)=dis(j,:)dis(i,:)=dis(j,:);dis(j,1)=-1;p=p-1;endendendendenddism=ones(p,n);j=1;fori=1:pwhilej=m&dis(j,1)==-1j=j+1;enddism(i,:)=dis(j,:);j=j+1;end%posCD.m%a为条件属性矩阵,d为决策属性向量%pos为正域,保存条件属性矩阵的索引值functionpos=posCD(a,d)[m,n]=size(a);p=m;index=0;fori=1:mifa(i,1)~=-1forj=i+1:mifa(j,1)~=-1&(a(i,:)==a(j,:)&d(i)~=d(j))a(j,1)=-1;p=p-1;index=1;end..endifindex==1a(i,1)=-1;p=p-1;index=0;endendendpos=zeros(p,1);i=1;forr=1:pwhilea(i,1)==-1&i=mi=i+1;endpos(r)=i;r=r+1;i=i+1;end%cor.m%对已经处理过的区分矩阵求核functioncore=cor(dism)[m,n]=size(dism);core1=zeros(1,n);number=0;fori=1:mnum=0;p=0;forj=1:nifdism(i,j)~=0num=num+1;p=j;endendifnum==1core1(p)=1;number=number+1;endendifnumber==0core=0;elsecore=zeros(1,number);j=1;fori=1:numberwhilecore1(j)==0j=j+1;..endcore(i)=core1(j);j=j+1;endend%uni.m%对区分矩阵的第i行和red(j,:)运算,即将a中%所有的1分别插入到red(j,:)中,待去掉包含关系functiontempred=uni(disa,red)[m,n]=size(red);num=0;fori=1:nifdisa(i)~=0num=num+1;endendtempred=ones(m*num,n);temp=[];j=1;fori=1:numwhiledisa(j)==0j=j+1;endtemp=red;temp(:,j)=ones(m,1);tempred((i-1)*m+1:i*m,:)=temp;j=j+1;end%isxbelongtopos.m%判断x是否在正域pos中%x为索引值%返回值p,如果x在pos中p=1否则p=0functionp=isxbelongtopos(x,pos)[m,n]=size(pos);p=0;ifx=0p=-1;return;endfori=1:mifx==pos(i)p=1;..break;endend%isxybelongtoindD.m%判断x,y是否在indD中%x,y为索引值%返回值p,如果x,y在indD中p=1否则p=0functionp=isxybelongtoindD(x,y,d)ifx=0|xsize(d)|y=0|ysize(d)p=-1;return;endifd(x)==d(y)p=1;elsep=0;end约简后的决策表
本文标题:属性约简(MATLAB算法)有实例有讲解
链接地址:https://www.777doc.com/doc-2133638 .html