www.gusucode.com > 《模式识别与智能计算》matlab源代码 > 《模式识别与智能计算》matlab源代码/《模式识别与智能计算》部分函数的源程序/书程序/第8章/reduction.m
function varargout=reduction(varargin) if length(varargin)>2 x1=varargin{1};x2=varargin{2};sample=varargin{3}; else x1=varargin{1};x2=varargin{2}; end temp=delrepeat([x1 x2]); x1=temp(:,1:end-2); x2=temp(:,end-1); [r,c]=size(x1); [pos1,num1,gama1]=calimport(x1,x2); y=zeros(1,c); for i=1:c temp=x1;temp(:,i)=[]; [pos,num,gama]=calimport(temp,x2); y(i)=gama1-gama; end temp=x1;m_1=[]; for i=1:c if y(i)==0 temp(:,i)=[]; y1=consistent(temp,x2); if y1==1 m_1=[m_1 i]; temp=x1; else temp=x1; end end end l=length(m_1); for i=l:-1:1 y_1=redu(x1,m_1(1:i)); y_2=consistent(y_1,x2); if y_2==1 m=m_1(1:i); break; end end temp1=0; for i=1:length(m) x1(:,m(i)-temp1)=[]; temp1=temp1+1; end temp=delrepeat([x1 x2]); y1=temp(:,1:end-2); y2=temp(:,end-1); y3=equvalue(y1); r1=length(y3); y4=equvalue(y2); r2=length(y4); rule1=cell(1,r2); for i=1:r2 for j=1:r1 temp=intersect(y3{j}(:,end),y4{i}(:,end)); if isequal(temp,y3{j}(:,end)); rule1{i}=[rule1{i};y3{j}(1,1:end-1) y4{i}(1,1) 1]; else rule1{i}=[rule1{i};y3{j}(1,1:end-1) y4{i}(1,1) 0]; end end end rule=[]; for i=1:r2 rule=[rule;rule1{i}]; end r=size(rule,1); m1=[]; for i=1:r if rule(i,end)==0 m1=[m1 i]; end end temp1=0; for i=1:length(m1) rule(m1(i)-temp1,:)=[]; temp1=temp1+1; end rule=rule(:,1:end-1); rule_old=rule; rule_old=delrepeat(rule_old); rule_old=rule_old(:,1:end-1); [r,c]=size(rule); for i=1:c-1 y_deg{i}=f(rule(:,i)); end for i=1:c-1 temp=rule; temp(:,i)=inf; temp=delrow(temp,inf,'c'); y_temp=equvalue(temp); for j=1:length(y_temp) if size(y_temp{j},1)<length(y_deg{i}) continue else b=y_temp{j}(:,end); b_temp=[]; for k=1:length(b) b_temp=[b_temp rule(b(k),i)]; end if isequal(sort(b_temp),y_deg{i}) for k=1:length(b) rule(b(k),i)=-inf; end end end end end rule=delrepeat(rule); rule=rule(:,1:end-1); [r,c]=size(rule); rule_new=cell(1,r);rule_new1=cell(1,r); for i=1:r temp=[];temp1=[]; for j=1:c if rule(i,j)~=-inf if j<=c-1 temp1=[temp1 j]; end temp=[temp rule(i,j)]; end end rule_new{i}=temp; rule_new1{i}=temp1; end if exist('sample','var') sample=delrow(sample,m,'nc'); [r,c]=size(sample); for i=1:r for j=1:length(rule_new1) temp=[]; for k=1:length(rule_new1{j}) temp=[temp sample(i,rule_new1{j}(k))]; end if isequal(temp,rule_new{j}(1:end-1)) s_out(i)=rule_new{j}(end); end end end m={m m_1}; varargout={rule,[m m_1],rule_new,rule_old,s_out}; else m={m m_1}; varargout={rule,[m m_1],rule_new,rule_old}; end function y=f(x) [r,c]=size(x); if r>1 a=max(x);b=min(x); else a=max(x,[],2);b=min(x,[],2); end y=(b:a); function y=redu(x,m) temp1=0;y=x; for i=1:length(m) y(:,m(i)-temp1)=[]; temp1=temp1+1; end