《属性约简(MATLAB算法)有实例有讲解(共7页).doc》由会员分享,可在线阅读,更多相关《属性约简(MATLAB算法)有实例有讲解(共7页).doc(7页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、精选优质文档-倾情为你奉上粗糙集属性约简题目: SARS 诊断注:这是我学粗糙集时老师给的作业U干咳呼吸困难血液检测高烧38度X射线浓痰血细胞多寒战肌肉酸痛乏力胸膜痛头痛非典111110000110112000000000000031010000001000400011110101105100111110110060101111110010710001110011108111100001101191011100011011101111000011011111011100011011121011100011011属性约简的顺序如下:求正域、生成未经处理的区分矩阵、对区分矩阵进行化简、求核、对已经
2、处理过的区分矩阵进行属性约简。约简后的决策表有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
3、,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% 生成未经处理的区分矩阵dismatfunction dismat=dismatrix(a,d,pos)m,n=size(a);p=1;index1=0;index2=0;index=0;
4、dis=-1*ones(m*(m-1)/2,n);for i=1:m for j=i+1:m if (isxbelongtopos(i,pos)&isxbelongtopos(j,pos). |(isxbelongtopos(i,pos)&isxbelongtopos(j,pos). |(isxbelongtopos(i,pos)&isxbelongtopos(j,pos)&isxybelongtoindD(i,j,d) index2=1; end if index2=0 continue; end for k=1:n if a(i,k)=a(j,k) dis(p,k)=1; index1=1
5、; else dis(p,k)=0; end end if index1=1 p=p+1;index=1; end index1=0; index2=0; endendif p=m*(m-1)/2 if index=0 dismat=; return; end if dis(p,1)=-1 p=p-1; endelse p=m*(m-1)/2;enddismat=dis(1:p,:);% redu.m% 对已经处理过的区分矩阵进行知识约简function red,row=redu(dism)m,n=size(dism);red=;row=0;if m=0 return;endfor i=1:n
6、 if dism(1,i)=0 row=row+1; endendred(1:row,:)=zeros(row,n);j=1;for i=1:row while dism(1,j)=0 j=j+1; end red(i,j)=1; j=j+1;endtemp=;tempdis=;rowd=0;rowd1=0;for i=2:m j=1; while j=row temp=uni(dism(i,:),red(j,:); s,n=size(temp); rowd1=rowd+s; tempdis(rowd+1:rowd1,:)=temp; rowd=rowd1; j=j+1; temp=; end
7、 red=; red=disbe(tempdis); tempdis=; row,n=size(red); rowd=0;rowd1=0;end% disbe.m% 对区分矩阵或者约简矩阵进行化简即去掉包含关系function dism=disbe(dis)m,n=size(dis);p=m;for i=1:m if dis(i,1)=-1 for j=1:m if i=j & dis(j,1)=-1 if dis(i,:)=dis(j,:) dis(i,:)=dis(j,:); dis(j,1)=-1; p=p-1; end end end endenddism=ones(p,n);j=1;
8、for i=1:p while j=m & dis(j,1)=-1 j=j+1; end dism(i,:)=dis(j,:); j=j+1;end% posCD.m% a为条件属性矩阵,d为决策属性向量% pos为正域,保存条件属性矩阵的索引值function pos=posCD(a,d)m,n=size(a);p=m;index=0;for i=1:m if a(i,1)=-1 for j=i+1:m if a(j,1)=-1 &(a(i,:)=a(j,:)&d(i)=d(j) a(j,1)=-1;p=p-1;index=1; end end if index=1 a(i,1)=-1;p=
9、p-1;index=0; end endendpos=zeros(p,1);i=1;for r=1:p while a(i,1)=-1&i=m i=i+1; end pos(r)=i; r=r+1; i=i+1;end% cor.m% 对已经处理过的区分矩阵求核function core=cor(dism)m,n=size(dism);core1=zeros(1,n);number=0;for i=1:m num=0;p=0; for j=1:n if dism(i,j)=0 num=num+1; p=j; end end if num=1 core1(p)=1; number=number+
10、1; endendif number=0 core=0;else core=zeros(1,number); j=1; for i=1:number while core1(j)=0 j=j+1; end core(i)=core1(j); j=j+1; endend% uni.m%对区分矩阵的第i行和red(j,:)运算,即将a中%所有的1分别插入到red(j,:)中,待去掉包含关系function tempred=uni(disa,red)m,n=size(red);num=0;for i=1:n if disa(i)=0 num=num+1; endendtempred=ones(m*n
11、um,n);temp=;j=1;for i=1:num while disa(j)=0 j=j+1; end temp=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=0function p=isxbelongtopos(x,pos)m,n=size(pos);p=0;if x=0 p=-1; return;endfor i=1:m if x=pos(i) p=1; break; endend% isxybelongtoindD.m% 判断x,y是否在indD中% x,y为索引值% 返回值p,如果x,y在indD中p=1否则p=0function p=isxybelongtoindD(x,y,d)if xsize(d) | ysize(d) p=-1; return;endif d(x)=d(y) p=1;else p=0;end约简后的决策表专心-专注-专业
限制150内