clear all
close all
load wine
data=standdata;
if_fuzzy=0;
neighbor=0.25;
inclusion=0.25;
%%%%%%%%%%%%
select_feature_neighbor=fs_neighbor(data,if_fuzzy,neighbor,inclusion)
%%%%%%%%%%%%%%%%
select_feature_entropy=fs_entropy(data,if_fuzzy,neighbor)
select_feature_con_N=fs_con_N(data,neighbor)
if_fuzzy=1;
%%%%%%%%%%%%
select_feature_neighbor_fuzzy=fs_neighbor(data,if_fuzzy,neighbor,inclusion)
%%%%%%%%%%%%%%%%
select_feature_entropy_fuzzy=fs_entropy(data,if_fuzzy,neighbor)
fs_neighbor模块
%% compute reduct from numerical data, categorical data and their mixtures with neighborhood rough sets.
%% two kinds of neighborhood are used: crisp and fuzzy.
%% Variable precision neighborhood lower approximations are used to compute dependency between conditions and decision.
%% dependency is employed as the heuristic rule.
function select_feature=fs_neighbor(data,if_fuzzy,neighbor,inclusion)
%%input
%%%input:
% data is data matrix, where rows for samples and columns for attributes.
% Numerical attributes should be normalized into [0,1] and decision attribute is put in the last column
% f is the label of "fuzzy" or "crisp". f=0 menas crisp neighborhoods; while f=1 means triangle fuzzy neighborhoods.
% neighborhood means the radius of neighborhood, usually takes value in [0.05 0.5]
% inclusion is the threshold to compute variable precision lower approximation, usually in [0.8, 1]
%%%output
% a reduct--- the set of selected attributes.
[row column]=size(data);
%%%%%%%%%%%%%compute relation matrices with a single attribute%%%%%%%%%
if (if_fuzzy==0)
for i=1:column
col=i;
r=[];
eval(['ssr' num2str(col) '=[];']);
for j=1:row
a=data(j,col);
x=data(:,col);
for m=1:length(x)
r(j,m)=kersim_crisp(a,x(m),neighbor);
end
end
eval(['ssr' num2str(col) '=r;']);
end
else
for i=1:column
col=i;
r=[];
eval(['ssr' num2str(col) '=[];']);
for j=1:row
a=data(j,col);
x=data(:,col);
for m=1:length(x)
r(j,m)=kersim(a,x(m),neighbor);
end
end
eval(['ssr' num2str(col) '=r;']);
end
end
%%%%%%%%%%%%search reduct with a forward greedy strategy%%%%%%%%%%%%%%%%%%%%%%%
n=[];
x=0;
base=ones(row);
r=eval(['ssr' num2str(column)]);
attrinu=column-1;
for j=attrinu:-1:1
sig=[];
for l=1:attrinu
r2=eval(['ssr' num2str(l)]);
r1=min(r2,base);
importance=0;
temp=[];
incluse=[];
for i=1:row
temp=min([r1(i,:);r(i,:)]);
incluse=sum(temp)/sum(r1(i,:));
if incluse>=inclusion
importance=importance+sum(temp)/length(find(temp~=0));
end
end
sig(l)=importance/row;
end
[x1,n1]=max(sig);
x=[x;x1];
len=length(x);
if abs(x(len)-x(len-1))>0.001
base1=eval(['ssr' num2str(n1)]);
base=min(base,base1);
n=[n;n1];
else
break
end
end
select_feature=n;
fs_entropy模块
%% compute reduct from numerical data, categorical data and their mixtures with fuzzy information entropy.
%% Please refer to the following papers:
%% Qinghua Hu, Daren Yu, Zongxia Xie. Information-preserving hybrid data reduction based on fuzzy-rough techniques. Pattern recognition letters. 2006, 27 (5): 414-423
%% Qinghua Hu, Yu Daren, Zongxia Xie,Jinfu Liu. Fuzzy probabilistic approximation spaces and their information measures. IEEE transactions on fuzzy systems. 2006, 14 (2): 191-201
%% Qinghua Hu, Daren Yu. Entropies of fuzzy indiscernibility relation and its operations. International Journal of uncertainty, fuzziness and knowledge-based systems. 12 (5):575-589. 2004
%% We compute a reduct with fuzzy information enttropy if their are numerical attributes; otherwise, we search a reduct with Shannon's entropy/
%% In fact, Shannon's entropy and fuzzy entropy are unified in the same form in this model.
function select_feature=fs_entropy(data,if_fuzzy,neighbor)
%%input
%%%input:
% data is data matrix, where rows for samples and columns for attributes.
% Numerical attributes should be normalized into [0,1] and decision attribute is put in the last column
% f is the label of "fuzzy" or "crisp". f=0 menas crisp neighborhoods; while f=1 means triangle fuzzy neighborhoods.
% neighbor means the radius of neighborhood, usually takes value in [0.05 0.5]
%%%output
% a reduct--- the set of selected attributes.
[row column]=size(data);
%%%%%%%%%%%%%compute the relation matrix %%%%%%%%%
if (if_fuzzy==0)
for i=1:column
col=i;
r=[];
eval(['ssr' num2str(col) '=[];']);
for j=1:row
a=data(j,col);
x=data(:,col);
for m=1:length(x)
r(j,m)=kersim_crisp(a,x(m),neighbor);
end
end
eval(['ssr' num2str(col) '=r;']);
end
else
for i=1:column
col=i;
r=[];
eval(['ssr' num2str(col) '=[];']);
for j=1:row
a=data(j,col);
x=data(:,col);
for m=1:length(x)
r(j,m)=kersim(a,x(m),neighbor);
end
end
eval(['ssr' num2str(col) '=r;']);
end
end
%%%%%%%%%%%data reduct based on entropy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
n=[];
sig=[];
x=0;
base=ones(row);
r=eval(['ssr' num2str(column)]);
entropyd=entropy(r);
attrinu=column-1;
for j=attrinu:-1:1
for i=1:attrinu
r1=eval(['ssr' num2str(i)]);
sig(i)=entropyd+entropy(min(r1,base))-entropy(min(min(r1,r),base));
end
[x1,n1]=max(sig);
x=[x;x1];
len=length(x);
if abs(x(len)-x(len-1))>0.001
base1=eval(['ssr' num2str(n1)]);
base=min(base,base1);
n=[n;n1];
else
break
end
end
select_feature=n;
fs_con_N模块
%% compute reduct from numerical data, categorical data and their mixtures with neighborhood rough sets.
%% two kinds of neighborhood are used: crisp and fuzzy.
%% Variable precision neighborhood lower approximations are used to compute dependency between conditions and decision.
%% dependency is employed as the heuristic rule.
function [select_feature,attr_sig]=fs_con_N(data,neighbor)
%%input
%%%input:
% data is data matrix, where rows for samples and columns for attributes.
% Numerical attributes should be normalized into [0,1] and decision attribute is put in the last column
% neighborhood means the radius of neighborhood, usually takes value in [0.05 0.5]
%%%output
% a reduct--- the set of selected attributes.
[row column]=size(data);
classnum=max(data(:,column));
%%%%%%%%%%%%%compute relation matrices with a single attribute%%%%%%%%%
for i=1:column
col=i;
r=[];
eval(['ssr' num2str(col) '=[];']);
for j=1:row
a=data(j,col);
x=data(:,col);
for m=1:length(x)
r(j,m)=kersim_crisp(a,x(m),neighbor);
end
end
eval(['ssr' num2str(col) '=r;']);
end
%%%%%%%%%%%%search reduct with a forward greedy strategy%%%%%%%%%%%%%%%%%%%%%%%
n=[];
x=0;
base=ones(row);
r=eval(['ssr' num2str(column)]);
attrinu=column-1;
for j=attrinu:-1:1
sig=[];
for l=1:attrinu
r2=eval(['ssr' num2str(l)]);
r1=min(r2,base);
importance=0;
temp=[];
for i=1:row
temp=r1(i,:);
neighbor_loc=find(temp==1);
label_value_N=data(neighbor_loc,column);
for class_i=1:classnum
class_i_num_N(class_i)=length(find(label_value_N==class_i));
end
[value,real_class]=max(class_i_num_N);
if (data(i,column)==real_class)
importance=importance+1;
end
end
sig(l)=importance/row;
end
[x1,n1]=max(sig);
x=[x;x1];
len=length(x);
if abs(x(len)-x(len-1))>0.001
base1=eval(['ssr' num2str(n1)]);
base=min(base,base1);
n=[n;n1];
else
break
end
end
attr_sig=x(2:(length(x)-1));
select_feature=n;
新的改变算法会在此基础上进行更新,希望自己能更早的搞定。也好分享出来新的源代码。