📄 rsattributereduction.m
字号:
%Rough Set Attribute's Reduction algorithm
%Version 1.0 16-July-2008
%Department of Business Management
%NorthChina Electric Power University,Beijing,China
%MicroArmy
%Inputs:
% AttriValues -Attributes' Value matrix
% DecisionTypeValue -DecisionTypeValue matrix
%Outputs:
%The Core of the attribute
%0 express can be deleted
%1 express not
%function RSAttributeReduction(AttributeValues,DecisionValues)
function RSAR=RSAttributeReduction(AttributeValues,DecisionValues)
%The Idea of algorithm
%for every attributes,
%deleted one by one, and check the attributevalues
%if(AttributeValues are all different)
% the deleted attributes can be deleted
%else
% if(the same AttributeValues' DecisionValues is also same)
% the deleted attributes can be deleted
% else
% the deleted attribute can't be deleted
[m,n]=size(AttributeValues);
record=zeros(n,1); %Record the attributes weather can be reduced, 0 express can reduced, otherwise is 1;
reducerecord=ones(n,1); %Record the reduce attribute traces
for j=1:n
tempAttriV=AttributeValues;
tempAttriV(:,j)=[];
if (min(reducerecord)~=1)
g=0;
for k=1:j-1
if (reducerecord(k)==0)
tempAttriV(:,k-g)=[];
g=g+1; %Record the reduce cols
end
end
end
for i=1:m
%tempDValues=DecisionValues;
%tempDValues(i)=[];
compareResult=Compare(tempAttriV(i,:),tempAttriV,DecisionValues(i),DecisionValues);
if (compareResult==0)
record(j)=0;
reducerecord(j)=0;
else
record(j)=1;
reducerecord(j)=1;
break
end
end
end
%display the result
if(min(reducerecord==0))
disp('the last column left!')
else
RSAR=record;
end
function [compareResult]=Compare(RowArray,Matrix,DValue,DArray)
%Input:
% RowArray:compared array
% Matrix:the Matrix
% DValue: the respectivly decision value of the RowArray
% DArray: the Decision Array
[m1,n1]=size(Matrix);
record1=zeros(m1,n1); %Record every rows' result of comparing the rowarray with the matrix
samerow=ones(1,n1); %if attribute row is same ,then produce a onesrow;
compareResult=0;
tempcompareResult=0;
for i1=1:m1
record1(i1,:)=(RowArray==Matrix(i1,:));
end
for i3=1:m1
if ((record1(i3,:)==samerow) & (DArray(i3)==DValue))
compareResult=compareResult | 0;
elseif ((record1(i3,:)==samerow) & (DArray(i3)~=DValue))
compareResult=1;
break
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -